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

            Line data    Source code
       1              : /* valaerrorcode.vala
       2              :  *
       3              :  * Copyright (C) 2008  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 an error value member in the source code.
      27              :  */
      28         1530 : public class Vala.ErrorCode : TypeSymbol {
      29              :         /**
      30              :          * Specifies the numerical representation of this enum value.
      31              :          */
      32              :         public Expression? value {
      33       412429 :                 get { return _value; }
      34           15 :                 set {
      35       412267 :                         _value = value;
      36           15 :                         if (_value != null) {
      37           15 :                                 _value.parent_node = this;
      38              :                         }
      39              :                 }
      40              :         }
      41              : 
      42              :         /**
      43              :          * Refers to the enum value of this error code for direct access.
      44              :          */
      45              :         public Constant code {
      46       824516 :                 get {
      47       824516 :                         return _code;
      48              :                 }
      49       412252 :                 private set {
      50       824504 :                         _code = value;
      51       412252 :                         if (_code != null) {
      52       412252 :                                 _code.owner = owner;
      53              :                         }
      54              :                 }
      55              :         }
      56              : 
      57              :         /**
      58              :          * The nick of this error code
      59              :          */
      60              :         public string nick {
      61           52 :                 get {
      62           52 :                         if (_nick == null) {
      63           52 :                                 _nick = get_attribute_string ("Description", "nick");
      64           52 :                                 if (_nick == null) {
      65           52 :                                         _nick = name.down ().replace ("_", "-");
      66              :                                 }
      67              :                         }
      68           52 :                         return _nick;
      69              :                 }
      70              :         }
      71              : 
      72       445542 :         private Expression _value;
      73       445542 :         private Constant _code;
      74       445542 :         private string? _nick = null;
      75              : 
      76              :         /**
      77              :          * Creates a new enum value.
      78              :          *
      79              :          * @param name enum value name
      80              :          * @return     newly created enum value
      81              :          */
      82      1336615 :         public ErrorCode (string name, SourceReference? source_reference = null, Comment? comment = null) {
      83       445542 :                 base (name, source_reference, comment);
      84              :         }
      85              : 
      86              :         /**
      87              :          * Creates a new enum value with the specified numerical representation.
      88              :          *
      89              :          * @param name  enum value name
      90              :          * @param value numerical representation
      91              :          * @return      newly created enum value
      92              :          */
      93           33 :         public ErrorCode.with_value (string name, Expression value, SourceReference? source_reference = null) {
      94           11 :                 this (name, source_reference);
      95           11 :                 this.value = value;
      96              :         }
      97              : 
      98       970372 :         public override void accept (CodeVisitor visitor) {
      99       970372 :                 visitor.visit_error_code (this);
     100              :         }
     101              : 
     102            0 :         public override void accept_children (CodeVisitor visitor) {
     103            0 :                 if (value != null) {
     104            0 :                         value.accept (visitor);
     105              :                 }
     106              :         }
     107              : 
     108       413757 :         public override bool check (CodeContext context) {
     109       413757 :                 if (checked) {
     110         1505 :                         return !error;
     111              :                 }
     112              : 
     113       412252 :                 checked = true;
     114              : 
     115       412252 :                 if (value != null) {
     116           15 :                         value.check (context);
     117              :                 }
     118              : 
     119       412252 :                 code = new Constant (name, context.analyzer.int_type.copy (), null, source_reference, comment);
     120       412252 :                 code.external = true;
     121       412252 :                 code.check (context);
     122              : 
     123       412252 :                 return !error;
     124              :         }
     125              : }
        

Generated by: LCOV version 2.0-1