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

            Line data    Source code
       1              : /* valaenumvaluetype.vala
       2              :  *
       3              :  * Copyright (C) 2009-2011  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              :  * An enum value type.
      27              :  */
      28       986496 : public class Vala.EnumValueType : ValueType {
      29       984959 :         private Method? to_string_method;
      30              : 
      31      2954877 :         public EnumValueType (Enum type_symbol, SourceReference? source_reference = null) {
      32       984959 :                 base (type_symbol, source_reference);
      33              :         }
      34              : 
      35        78538 :         public override DataType copy () {
      36        78538 :                 var result = new EnumValueType ((Enum) type_symbol, source_reference);
      37        78538 :                 result.value_owned = value_owned;
      38        78538 :                 result.nullable = nullable;
      39              : 
      40        78538 :                 return result;
      41              :         }
      42              : 
      43           93 :         public unowned Method get_to_string_method () {
      44          140 :                 if (to_string_method == null) {
      45           47 :                         var string_type = CodeContext.get ().analyzer.string_type.copy ();
      46           47 :                         string_type.value_owned = false;
      47           47 :                         to_string_method = new Method ("to_string", string_type, source_reference);
      48           47 :                         to_string_method.access = SymbolAccessibility.PUBLIC;
      49           47 :                         to_string_method.is_extern = true;
      50           47 :                         if (CodeContext.get ().profile == Profile.POSIX) {
      51            1 :                                 to_string_method.set_attribute_string ("CCode", "cheader_filename", "stdlib.h");
      52              :                         } else {
      53           46 :                                 to_string_method.set_attribute_string ("CCode", "cheader_filename", "glib-object.h");
      54              :                         }
      55           47 :                         to_string_method.owner = type_symbol.scope;
      56           47 :                         to_string_method.this_parameter = new Parameter ("this", copy (), source_reference);
      57           47 :                         to_string_method.scope.add (to_string_method.this_parameter.name, to_string_method.this_parameter);
      58              :                 }
      59           93 :                 return to_string_method;
      60              :         }
      61              : 
      62           98 :         public override Symbol? get_member (string member_name) {
      63           98 :                 var result = base.get_member (member_name);
      64           98 :                 if (result == null && member_name == "to_string") {
      65           14 :                         return get_to_string_method ();
      66              :                 }
      67           98 :                 return result;
      68              :         }
      69              : }
        

Generated by: LCOV version 2.0-1