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

            Line data    Source code
       1              : /* valaccodevariabledeclarator.vala
       2              :  *
       3              :  * Copyright (C) 2006-2009  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 variable declarator in the C code.
      27              :  */
      28        98937 : public class Vala.CCodeVariableDeclarator : CCodeDeclarator {
      29              :         /**
      30              :          * The optional initializer expression.
      31              :          */
      32       206602 :         public CCodeExpression? initializer { get; set; }
      33              : 
      34              :         /**
      35              :          * The optional declarator suffix.
      36              :          */
      37       196180 :         public CCodeDeclaratorSuffix? declarator_suffix { get; set; }
      38              : 
      39              :         /**
      40              :          * Initializer only used to zero memory, safe to initialize as part
      41              :          * of declaration at beginning of block instead of separate assignment.
      42              :          */
      43        10136 :         public bool init0 { get; set; }
      44              : 
      45       289638 :         public CCodeVariableDeclarator (string name, CCodeExpression? initializer = null, CCodeDeclaratorSuffix? declarator_suffix = null) {
      46        96546 :                 this.name = name;
      47        96546 :                 this.initializer = initializer;
      48        96546 :                 this.declarator_suffix = declarator_suffix;
      49              :         }
      50              : 
      51         4632 :         public CCodeVariableDeclarator.zero (string name, CCodeExpression? initializer, CCodeDeclaratorSuffix? declarator_suffix = null) {
      52         1544 :                 this.name = name;
      53         1544 :                 this.initializer = initializer;
      54         1544 :                 this.declarator_suffix = declarator_suffix;
      55         1544 :                 this.init0 = true;
      56              :         }
      57              : 
      58         6450 :         public override void write (CCodeWriter writer) {
      59         6450 :                 writer.write_string (name);
      60              : 
      61         6450 :                 if (declarator_suffix != null) {
      62          530 :                         declarator_suffix.write (writer);
      63              :                 }
      64              : 
      65         6450 :                 if (initializer != null) {
      66         4822 :                         writer.write_string (" = ");
      67         4822 :                         initializer.write (writer);
      68              :                 }
      69              :         }
      70              : 
      71        74376 :         public override void write_declaration (CCodeWriter writer) {
      72        74376 :                 writer.write_string (name);
      73              : 
      74        74376 :                 if (declarator_suffix != null) {
      75           84 :                         declarator_suffix.write (writer);
      76              :                 }
      77              : 
      78        74376 :                 if (initializer != null && init0) {
      79        10087 :                         writer.write_string (" = ");
      80        10087 :                         initializer.write (writer);
      81              :                 }
      82              :         }
      83              : 
      84        63807 :         public override void write_initialization (CCodeWriter writer) {
      85        63807 :                 if (initializer != null && !init0) {
      86         4367 :                         writer.write_indent (line);
      87              : 
      88         4367 :                         writer.write_string (name);
      89         4367 :                         writer.write_string (" = ");
      90         4367 :                         initializer.write (writer);
      91              : 
      92         4367 :                         writer.write_string (";");
      93         4367 :                         writer.write_newline ();
      94              :                 }
      95              :         }
      96              : }
      97              : 
      98         2346 : public class Vala.CCodeDeclaratorSuffix {
      99              :         bool array;
     100          690 :         List<CCodeExpression>? array_length;
     101              : 
     102         1270 :         public CCodeDeclaratorSuffix.with_array (CCodeExpression? array_length = null) {
     103          635 :                 if (array_length != null) {
     104          634 :                         this.array_length = new ArrayList<CCodeExpression> ();
     105          634 :                         this.array_length.add (array_length);
     106              :                 }
     107          635 :                 array = true;
     108              :         }
     109              : 
     110          110 :         public CCodeDeclaratorSuffix.with_multi_array (List<CCodeExpression>? array_length = null) {
     111           55 :                 this.array_length = array_length;
     112           55 :                 array = true;
     113              :         }
     114              : 
     115          614 :         public void write (CCodeWriter writer) {
     116          614 :                 if (array_length != null && array_length.size > 0) {
     117         1847 :                         foreach (var length in array_length) {
     118          617 :                                 writer.write_string ("[");
     119          617 :                                 if (length != null) {
     120          617 :                                         length.write (writer);
     121              :                                 }
     122          617 :                                 writer.write_string ("]");
     123              :                         }
     124            1 :                 } else if (array) {
     125            1 :                         writer.write_string ("[]");
     126              :                 }
     127              :         }
     128              : }
        

Generated by: LCOV version 2.0-1