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

            Line data    Source code
       1              : /* valaccodedeclaration.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 local variable declaration in the C code.
      27              :  */
      28       184916 : public class Vala.CCodeDeclaration : CCodeStatement {
      29              :         /**
      30              :          * The type of the local variable.
      31              :          */
      32       276129 :         public string type_name { get; set; }
      33              : 
      34       184086 :         private List<CCodeDeclarator> declarators = new ArrayList<CCodeDeclarator> ();
      35              : 
      36       276129 :         public CCodeDeclaration (string type_name) {
      37        92043 :                 this.type_name = type_name;
      38              :         }
      39              : 
      40              :         /**
      41              :          * Adds the specified declarator to this declaration.
      42              :          *
      43              :          * @param decl a declarator
      44              :          */
      45        92043 :         public void add_declarator (CCodeDeclarator decl) {
      46        92043 :                 declarators.add (decl);
      47              :         }
      48              : 
      49              :         /**
      50              :          * Returns the list of declarators.
      51              :          *
      52              :          * @return declarators list
      53              :          */
      54            0 :         public unowned List<CCodeDeclarator> get_declarators () {
      55            0 :                 return declarators;
      56              :         }
      57              : 
      58        69727 :         public override void write (CCodeWriter writer) {
      59        69727 :                 if ((modifiers & (CCodeModifiers.STATIC | CCodeModifiers.INTERNAL | CCodeModifiers.EXTERN)) == 0) {
      60       191421 :                         foreach (CCodeDeclarator decl in declarators) {
      61        63807 :                                 decl.write_initialization (writer);
      62              :                         }
      63              :                 }
      64              :         }
      65              : 
      66          548 :         private bool has_initializer () {
      67         1130 :                 foreach (CCodeDeclarator decl in declarators) {
      68          548 :                         var var_decl = decl as CCodeVariableDeclarator;
      69          548 :                         if (var_decl != null && var_decl.initializer == null) {
      70          257 :                                 return false;
      71              :                         }
      72              :                 }
      73          548 :                 return true;
      74              :         }
      75              : 
      76        77567 :         public override void write_declaration (CCodeWriter writer) {
      77        77567 :                 if ((modifiers & (CCodeModifiers.STATIC | CCodeModifiers.INTERNAL | CCodeModifiers.EXTERN)) != 0) {
      78              :                         // combined declaration and initialization for static and extern variables
      79         5920 :                         writer.write_indent (line);
      80         5920 :                         if ((modifiers & CCodeModifiers.INTERNAL) != 0) {
      81            0 :                                 writer.write_string (GNUC_INTERNAL);
      82              :                         }
      83         5920 :                         if ((modifiers & CCodeModifiers.STATIC) != 0) {
      84         5372 :                                 writer.write_string ("static ");
      85              :                         }
      86         5920 :                         if ((modifiers & CCodeModifiers.VOLATILE) != 0) {
      87         1058 :                                 writer.write_string ("volatile ");
      88              :                         }
      89         5920 :                         if ((modifiers & CCodeModifiers.EXTERN) != 0 && !has_initializer ()) {
      90          257 :                                 writer.write_string ("VALA_EXTERN ");
      91              :                         }
      92         5920 :                         if ((modifiers & CCodeModifiers.THREAD_LOCAL) != 0) {
      93            0 :                                 writer.write_string ("thread_local ");
      94              :                         }
      95         5920 :                         writer.write_string (type_name);
      96         5920 :                         writer.write_string (" ");
      97              : 
      98         5920 :                         bool first = true;
      99        17760 :                         foreach (CCodeDeclarator decl in declarators) {
     100         5920 :                                 if (!first) {
     101            0 :                                         writer.write_string (", ");
     102              :                                 } else {
     103              :                                         first = false;
     104              :                                 }
     105         5920 :                                 decl.write (writer);
     106              :                         }
     107              : 
     108         5920 :                         writer.write_string (";");
     109         5920 :                         writer.write_newline ();
     110         5920 :                         return;
     111              :                 }
     112              : 
     113        71647 :                 writer.write_indent ();
     114        71647 :                 if ((modifiers & CCodeModifiers.REGISTER) == CCodeModifiers.REGISTER) {
     115          136 :                         writer.write_string ("register ");
     116              :                 }
     117        71647 :                 if ((modifiers & CCodeModifiers.VOLATILE) != 0) {
     118            0 :                         writer.write_string ("volatile ");
     119              :                 }
     120        71647 :                 writer.write_string (type_name);
     121        71647 :                 writer.write_string (" ");
     122              : 
     123        71647 :                 bool first = true;
     124       214941 :                 foreach (CCodeDeclarator decl in declarators) {
     125        71647 :                         if (!first) {
     126            0 :                                 writer.write_string (", ");
     127              :                         } else {
     128              :                                 first = false;
     129              :                         }
     130        71647 :                         decl.write_declaration (writer);
     131              :                 }
     132              : 
     133        71647 :                 if (CCodeModifiers.DEPRECATED in modifiers) {
     134            2 :                         writer.write_string (GNUC_DEPRECATED);
     135              :                 }
     136              : 
     137        71647 :                 writer.write_string (";");
     138        71647 :                 writer.write_newline ();
     139              :         }
     140              : }
        

Generated by: LCOV version 2.0-1