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

            Line data    Source code
       1              : /* valasignaltype.vala
       2              :  *
       3              :  * Copyright (C) 2007-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              :  * The type of a signal referencea.
      27              :  */
      28          674 : public class Vala.SignalType : CallableType {
      29              :         public weak Signal signal_symbol {
      30          845 :                 get {
      31          845 :                         return (Signal) symbol;
      32              :                 }
      33              :         }
      34              : 
      35          618 :         Method? connect_method;
      36          618 :         Method? connect_after_method;
      37          618 :         Method? disconnect_method;
      38          618 :         Method? emit_method;
      39              : 
      40         1854 :         public SignalType (Signal signal_symbol, SourceReference? source_reference = null) {
      41          618 :                 base (signal_symbol, source_reference);
      42              :         }
      43              : 
      44          409 :         public override DataType copy () {
      45          409 :                 return new SignalType (signal_symbol, source_reference);
      46              :         }
      47              : 
      48            0 :         public override bool compatible (DataType target_type) {
      49              :                 return false;
      50              :         }
      51              : 
      52            0 :         public override string to_qualified_string (Scope? scope) {
      53            0 :                 return signal_symbol.get_full_name ();
      54              :         }
      55              : 
      56          108 :         public DelegateType get_handler_type () {
      57          211 :                 var type_sym = (ObjectTypeSymbol) signal_symbol.parent_symbol;
      58          108 :                 var sender_type = SemanticAnalyzer.get_data_type_for_symbol (type_sym);
      59          108 :                 var result = new DelegateType (signal_symbol.get_delegate (sender_type, this), source_reference);
      60          108 :                 result.value_owned = true;
      61              : 
      62          108 :                 if (result.delegate_symbol.has_type_parameters ()) {
      63           26 :                         foreach (var type_param in type_sym.get_type_parameters ()) {
      64           10 :                                 var type_arg = new GenericType (type_param, source_reference);
      65           10 :                                 type_arg.value_owned = true;
      66           10 :                                 result.add_type_argument (type_arg);
      67              :                         }
      68              :                 }
      69              : 
      70          108 :                 return result;
      71              :         }
      72              : 
      73           88 :         unowned Method get_connect_method () {
      74          176 :                 if (connect_method == null) {
      75           88 :                         var ulong_type = CodeContext.get ().analyzer.ulong_type.copy ();
      76           88 :                         connect_method = new Method ("connect", ulong_type, source_reference);
      77           88 :                         connect_method.access = SymbolAccessibility.PUBLIC;
      78           88 :                         connect_method.external = true;
      79           88 :                         connect_method.owner = signal_symbol.scope;
      80           88 :                         connect_method.add_parameter (new Parameter ("handler", get_handler_type (), source_reference));
      81              :                 }
      82           88 :                 return connect_method;
      83              :         }
      84              : 
      85            2 :         unowned Method get_connect_after_method () {
      86            4 :                 if (connect_after_method == null) {
      87            2 :                         var ulong_type = CodeContext.get ().analyzer.ulong_type.copy ();
      88            2 :                         connect_after_method = new Method ("connect_after", ulong_type, source_reference);
      89            2 :                         connect_after_method.access = SymbolAccessibility.PUBLIC;
      90            2 :                         connect_after_method.external = true;
      91            2 :                         connect_after_method.owner = signal_symbol.scope;
      92            2 :                         connect_after_method.add_parameter (new Parameter ("handler", get_handler_type (), source_reference));
      93              :                 }
      94            2 :                 return connect_after_method;
      95              :         }
      96              : 
      97           13 :         unowned Method get_disconnect_method () {
      98           13 :                 if (disconnect_method == null) {
      99           13 :                         disconnect_method = new Method ("disconnect", new VoidType (), source_reference);
     100           13 :                         disconnect_method.access = SymbolAccessibility.PUBLIC;
     101           13 :                         disconnect_method.external = true;
     102           13 :                         disconnect_method.owner = signal_symbol.scope;
     103           13 :                         disconnect_method.add_parameter (new Parameter ("handler", get_handler_type (), source_reference));
     104              :                 }
     105           13 :                 return disconnect_method;
     106              :         }
     107              : 
     108            0 :         unowned Method get_emit_method () {
     109            0 :                 if (emit_method == null) {
     110            0 :                         emit_method = new Method ("emit", signal_symbol.return_type, source_reference);
     111            0 :                         emit_method.access = SymbolAccessibility.PUBLIC;
     112            0 :                         emit_method.external = true;
     113            0 :                         emit_method.owner = signal_symbol.scope;
     114              :                 }
     115            0 :                 return emit_method;
     116              :         }
     117              : 
     118          103 :         public override Symbol? get_member (string member_name) {
     119          103 :                 if (member_name == "connect") {
     120          176 :                         return get_connect_method ();
     121           15 :                 } else if (member_name == "connect_after") {
     122            4 :                         return get_connect_after_method ();
     123           13 :                 } else if (member_name == "disconnect") {
     124           26 :                         return get_disconnect_method ();
     125            0 :                 } else if (member_name == "emit") {
     126            0 :                         return get_emit_method ();
     127              :                 }
     128          103 :                 return null;
     129              :         }
     130              : 
     131            0 :         public override bool is_accessible (Symbol sym) {
     132            0 :                 return signal_symbol.is_accessible (sym);
     133              :         }
     134              : }
        

Generated by: LCOV version 2.0-1