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

            Line data    Source code
       1              : /* valasizeofexpression.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 sizeof expression in the source code.
      27              :  */
      28         7686 : public class Vala.SizeofExpression : Expression {
      29              :         /**
      30              :          * The type whose size to be retrieved.
      31              :          */
      32              :         public DataType type_reference {
      33        17252 :                 get { return _data_type; }
      34        11862 :                 private set {
      35        11862 :                         _data_type = value;
      36        11862 :                         _data_type.parent_node = this;
      37              :                 }
      38              :         }
      39              : 
      40         6157 :         private DataType _data_type;
      41              : 
      42              :         /**
      43              :          * Creates a new sizeof expression.
      44              :          *
      45              :          * @param type   a data type
      46              :          * @param source reference to source code
      47              :          * @return       newly created sizeof expression
      48              :          */
      49        18471 :         public SizeofExpression (DataType type, SourceReference? source = null) {
      50         6157 :                 type_reference = type;
      51         6157 :                 source_reference = source;
      52              :         }
      53              : 
      54         5760 :         public override void accept (CodeVisitor visitor) {
      55         5760 :                 visitor.visit_sizeof_expression (this);
      56              : 
      57         5760 :                 visitor.visit_expression (this);
      58              :         }
      59              : 
      60         5737 :         public override void accept_children (CodeVisitor visitor) {
      61         5737 :                 type_reference.accept (visitor);
      62              :         }
      63              : 
      64            0 :         public override bool is_pure () {
      65            0 :                 return true;
      66              :         }
      67              : 
      68            3 :         public override bool is_constant () {
      69            3 :                 return true;
      70              :         }
      71              : 
      72         5705 :         public override void replace_type (DataType old_type, DataType new_type) {
      73         5705 :                 if (type_reference == old_type) {
      74         5705 :                         type_reference = new_type;
      75              :                 }
      76              :         }
      77              : 
      78         5689 :         public override bool check (CodeContext context) {
      79         5689 :                 if (checked) {
      80            8 :                         return !error;
      81              :                 }
      82              : 
      83         5681 :                 checked = true;
      84              : 
      85         5681 :                 type_reference.check (context);
      86              : 
      87         5681 :                 value_type = context.analyzer.ulong_type;
      88              : 
      89         5681 :                 return !error;
      90              :         }
      91              : 
      92           41 :         public override void emit (CodeGenerator codegen) {
      93           41 :                 codegen.visit_sizeof_expression (this);
      94              : 
      95           41 :                 codegen.visit_expression (this);
      96              :         }
      97              : }
        

Generated by: LCOV version 2.0-1