LCOV - code coverage report
Current view: top level - ccode - valaccodeifsection.vala (source / functions) Coverage Total Hit
Test: vala 0.57.0.298-a8cae1 Lines: 96.6 % 29 28
Test Date: 2024-04-25 11:34:36 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         9255 : public class Vala.CCodeIfSection : CCodeFragment {
      29              :         /**
      30              :          * The conditional expression, or null if there is no condition.
      31              :          */
      32        25227 :         public string? expression { get; set; }
      33              : 
      34         8409 :         CCodeIfSection? else_section;
      35              :         bool is_else_section;
      36              : 
      37        16818 :         public CCodeIfSection (string? expr) {
      38         8409 :                 expression = expr;
      39         8409 :                 is_else_section = false;
      40              :         }
      41              : 
      42         3711 :         public unowned CCodeIfSection append_else (string? expr = null) {
      43         3711 :                 else_section = new CCodeIfSection (expr);
      44         3711 :                 else_section.is_else_section = true;
      45         3711 :                 return else_section;
      46              :         }
      47              : 
      48         5693 :         public override void write (CCodeWriter writer) {
      49         5693 :                 if (is_else_section) {
      50         2353 :                         if (expression != null) {
      51         1670 :                                 writer.write_string ("#elif ");
      52         1670 :                                 writer.write_string (expression);
      53              :                         } else {
      54          683 :                                 writer.write_string ("#else");
      55              :                         }
      56         3340 :                 } else if (expression != null) {
      57         3340 :                         writer.write_string ("#if ");
      58         3340 :                         writer.write_string (expression);
      59              :                 }
      60         5693 :                 writer.write_newline ();
      61        19053 :                 foreach (CCodeNode node in get_children ()) {
      62         6680 :                         node.write_combined (writer);
      63              :                 }
      64         5693 :                 if (else_section != null) {
      65         2353 :                         else_section.write_combined (writer);
      66              :                 } else {
      67         3340 :                         writer.write_string ("#endif");
      68         3340 :                         writer.write_newline ();
      69              :                 }
      70              :         }
      71              : 
      72            0 :         public override void write_declaration (CCodeWriter writer) {
      73              :         }
      74              : 
      75         4027 :         public override void write_combined (CCodeWriter writer) {
      76         4027 :                 write (writer);
      77              :         }
      78              : }
        

Generated by: LCOV version 2.0-1