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

            Line data    Source code
       1              : /* valaccodefunctiondeclarator.vala
       2              :  *
       3              :  * Copyright (C) 2006-2007  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 function pointer declarator in the C code.
      27              :  */
      28         4567 : public class Vala.CCodeFunctionDeclarator : CCodeDeclarator {
      29         4360 :         private List<CCodeParameter> parameters = new ArrayList<CCodeParameter> ();
      30              : 
      31         6540 :         public CCodeFunctionDeclarator (string name) {
      32         2180 :                 this.name = name;
      33              :         }
      34              : 
      35              :         /**
      36              :          * Appends the specified parameter to the list of function parameters.
      37              :          *
      38              :          * @param param a formal parameter
      39              :          */
      40         4519 :         public void add_parameter (CCodeParameter param) {
      41         4519 :                 parameters.add (param);
      42              :         }
      43              : 
      44            0 :         public override void write (CCodeWriter writer) {
      45            0 :                 write_declaration (writer);
      46              :         }
      47              : 
      48          614 :         public override void write_declaration (CCodeWriter writer) {
      49          614 :                 writer.write_string ("(*");
      50          614 :                 writer.write_string (name);
      51          614 :                 writer.write_string (") (");
      52              : 
      53          614 :                 bool has_args = (CCodeModifiers.PRINTF in modifiers || CCodeModifiers.SCANF in modifiers);
      54          614 :                 int i = 0;
      55          614 :                 int format_arg_index = -1;
      56          614 :                 int args_index = -1;
      57         3198 :                 foreach (CCodeParameter param in parameters) {
      58         1292 :                         if (i > 0) {
      59          691 :                                 writer.write_string (", ");
      60              :                         }
      61         1292 :                         param.write (writer);
      62         1292 :                         if (CCodeModifiers.FORMAT_ARG in param.modifiers) {
      63            2 :                                 format_arg_index = i;
      64              :                         }
      65         1292 :                         if (has_args && param.ellipsis) {
      66              :                                 args_index = i;
      67         1292 :                         } else if (has_args && param.type_name == "va_list" && format_arg_index < 0) {
      68            2 :                                 format_arg_index = i - 1;
      69              :                         }
      70         1292 :                         i++;
      71              :                 }
      72          614 :                 if (i == 0) {
      73           13 :                         writer.write_string ("void");
      74              :                 }
      75              : 
      76          614 :                 writer.write_string (")");
      77              : 
      78          614 :                 if (CCodeModifiers.DEPRECATED in modifiers) {
      79            3 :                         writer.write_string (GNUC_DEPRECATED);
      80              :                 }
      81              : 
      82          614 :                 if (CCodeModifiers.PRINTF in modifiers) {
      83            2 :                         format_arg_index = (format_arg_index >= 0 ? format_arg_index + 1 : args_index);
      84            2 :                         writer.write_string (GNUC_PRINTF.printf (format_arg_index, args_index + 1));
      85          612 :                 } else if (CCodeModifiers.SCANF in modifiers) {
      86            1 :                         format_arg_index = (format_arg_index >= 0 ? format_arg_index + 1 : args_index);
      87            1 :                         writer.write_string (GNUC_SCANF.printf (format_arg_index, args_index + 1));
      88          611 :                 } else if (format_arg_index >= 0) {
      89            1 :                         writer.write_string (GNUC_FORMAT.printf (format_arg_index + 1));
      90              :                 }
      91              :         }
      92              : }
        

Generated by: LCOV version 2.0-1