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

            Line data    Source code
       1              : /* valaccodeifstatement.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 an if selection statement in the C code.
      27              :  */
      28        15779 : public class Vala.CCodeIfStatement : CCodeStatement {
      29              :         /**
      30              :          * The boolean condition to evaluate.
      31              :          */
      32        70516 :         public CCodeExpression condition { get; set; }
      33              : 
      34              :         /**
      35              :          * The statement to be evaluated if the condition holds.
      36              :          */
      37        45285 :         public CCodeStatement true_statement { get; set; }
      38              : 
      39              :         /**
      40              :          * The optional statement to be evaluated if the condition doesn't hold.
      41              :          */
      42        44545 :         public CCodeStatement? false_statement { get; set; }
      43              : 
      44        45285 :         public CCodeIfStatement (CCodeExpression cond, CCodeStatement true_stmt, CCodeStatement? false_stmt = null) {
      45        15095 :                 condition = cond;
      46        15095 :                 true_statement = true_stmt;
      47        15095 :                 false_statement = false_stmt;
      48              :         }
      49              : 
      50              :         /**
      51              :          * Specifies whether this if statement is part of an else if statement.
      52              :          * This only affects the output formatting.
      53              :          */
      54          643 :         public bool else_if { get; set; }
      55              : 
      56        12843 :         public override void write (CCodeWriter writer) {
      57        12843 :                 if (!else_if) {
      58        12200 :                         writer.write_indent (line);
      59              :                 } else {
      60          643 :                         writer.write_string (" ");
      61              :                 }
      62        12843 :                 writer.write_string ("if (");
      63        12843 :                 if (condition != null) {
      64        12843 :                         condition.write (writer);
      65              :                 }
      66        12843 :                 writer.write_string (")");
      67              : 
      68              :                 /* else shouldn't be on a separate line */
      69        17551 :                 if (false_statement != null && true_statement is CCodeBlock) {
      70         4708 :                         var cblock = (CCodeBlock) true_statement;
      71         4708 :                         cblock.suppress_newline = true;
      72              :                 }
      73              : 
      74        12843 :                 true_statement.write (writer);
      75        12843 :                 if (false_statement != null) {
      76         4708 :                         if (writer.bol) {
      77            0 :                                 writer.write_indent ();
      78            0 :                                 writer.write_string ("else");
      79              :                         } else {
      80         4708 :                                 writer.write_string (" else");
      81              :                         }
      82              : 
      83              :                         /* else if should be on one line */
      84         5351 :                         if (false_statement is CCodeIfStatement) {
      85          643 :                                 var cif = (CCodeIfStatement) false_statement;
      86          643 :                                 cif.else_if = true;
      87              :                         }
      88              : 
      89         4708 :                         false_statement.write (writer);
      90              :                 }
      91              :         }
      92              : }
        

Generated by: LCOV version 2.0-1