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

            Line data    Source code
       1              : /* valaccodeifsection.vala
       2              :  *
       3              :  * Copyright (C) 2013  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              :  *      Marc-André Lurau <marcandre.lureau@redhat.com>
      21              :  */
      22              : 
      23              : using GLib;
      24              : 
      25              : /**
      26              :  * Represents a section that should be processed on condition.
      27              :  */
      28         9215 : public class Vala.CCodeIfSection : CCodeFragment {
      29              :         /**
      30              :          * The conditional expression, or null if there is no condition.
      31              :          */
      32        25119 :         public string? expression { get; set; }
      33              : 
      34         8373 :         CCodeIfSection? else_section;
      35              :         bool is_else_section;
      36              : 
      37        16746 :         public CCodeIfSection (string? expr) {
      38         8373 :                 expression = expr;
      39         8373 :                 is_else_section = false;
      40              :         }
      41              : 
      42         3695 :         public unowned CCodeIfSection append_else (string? expr = null) {
      43         3695 :                 else_section = new CCodeIfSection (expr);
      44         3695 :                 else_section.is_else_section = true;
      45         3695 :                 return else_section;
      46              :         }
      47              : 
      48         5669 :         public override void write (CCodeWriter writer) {
      49         5669 :                 if (is_else_section) {
      50         2343 :                         if (expression != null) {
      51         1663 :                                 writer.write_string ("#elif ");
      52         1663 :                                 writer.write_string (expression);
      53              :                         } else {
      54          680 :                                 writer.write_string ("#else");
      55              :                         }
      56         3326 :                 } else if (expression != null) {
      57         3326 :                         writer.write_string ("#if ");
      58         3326 :                         writer.write_string (expression);
      59              :                 }
      60         5669 :                 writer.write_newline ();
      61        18973 :                 foreach (CCodeNode node in get_children ()) {
      62         6652 :                         node.write_combined (writer);
      63              :                 }
      64         5669 :                 if (else_section != null) {
      65         2343 :                         else_section.write_combined (writer);
      66              :                 } else {
      67         3326 :                         writer.write_string ("#endif");
      68         3326 :                         writer.write_newline ();
      69              :                 }
      70              :         }
      71              : 
      72            0 :         public override void write_declaration (CCodeWriter writer) {
      73              :         }
      74              : 
      75         4010 :         public override void write_combined (CCodeWriter writer) {
      76         4010 :                 write (writer);
      77              :         }
      78              : }
        

Generated by: LCOV version 2.0-1