LCOV - code coverage report
Current view: top level - ccode - valaccodestruct.vala (source / functions) Coverage Total Hit
Test: vala 0.57.0.298-a8cae1 Lines: 96.0 % 25 24
Test Date: 2024-04-25 11:34:36 Functions: - 0 0

            Line data    Source code
       1              : /* valaccodestruct.vala
       2              :  *
       3              :  * Copyright (C) 2006-2010  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 struct declaration in the C code.
      27              :  */
      28        12729 : public class Vala.CCodeStruct : CCodeNode {
      29              :         /**
      30              :          * The struct name.
      31              :          */
      32        20571 :         public string name { get; set; }
      33              : 
      34            0 :         public bool is_empty { get { return declarations.size == 0; } }
      35              : 
      36        12176 :         private List<CCodeDeclaration> declarations = new ArrayList<CCodeDeclaration> ();
      37              : 
      38        18264 :         public CCodeStruct (string name) {
      39         6088 :                 this.name = name;
      40              :         }
      41              : 
      42              :         /**
      43              :          * Adds the specified declaration as member to this struct.
      44              :          *
      45              :          * @param decl a variable declaration
      46              :          */
      47        10795 :         public void add_declaration (CCodeDeclaration decl) {
      48        10795 :                 declarations.add (decl);
      49              :         }
      50              : 
      51              :         /**
      52              :          * Adds a variable with the specified type and name to this struct.
      53              :          *
      54              :          * @param type_name field type
      55              :          * @param name      member name
      56              :          */
      57        19794 :         public void add_field (string type_name, string name, CCodeModifiers modifiers = 0, CCodeDeclaratorSuffix? declarator_suffix = null) {
      58         9897 :                 var decl = new CCodeDeclaration (type_name);
      59         9897 :                 decl.add_declarator (new CCodeVariableDeclarator (name, null, declarator_suffix));
      60         9897 :                 decl.modifiers = modifiers;
      61         9897 :                 add_declaration (decl);
      62              :         }
      63              : 
      64         2481 :         public override void write (CCodeWriter writer) {
      65         2481 :                 writer.write_string ("struct ");
      66         2481 :                 writer.write_string (name);
      67         2481 :                 writer.write_begin_block ();
      68        15539 :                 foreach (CCodeDeclaration decl in declarations) {
      69         6529 :                         decl.write_declaration (writer);
      70              :                 }
      71              : 
      72         2481 :                 writer.write_end_block ();
      73         2481 :                 if (CCodeModifiers.DEPRECATED in modifiers) {
      74            2 :                         writer.write_string (GNUC_DEPRECATED);
      75              :                 }
      76         2481 :                 writer.write_string (";");
      77         2481 :                 writer.write_newline ();
      78         2481 :                 writer.write_newline ();
      79              :         }
      80              : }
        

Generated by: LCOV version 2.0-1