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

            Line data    Source code
       1              : /* valaccodeunaryexpression.vala
       2              :  *
       3              :  * Copyright (C) 2006-2009  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 expression with one operand in the C code.
      27              :  */
      28        17489 : public class Vala.CCodeUnaryExpression : CCodeExpression {
      29              :         /**
      30              :          * The unary operator.
      31              :          */
      32        16829 :         public CCodeUnaryOperator operator { get; set; }
      33              : 
      34              :         /**
      35              :          * The operand.
      36              :          */
      37        33688 :         public CCodeExpression inner { get; set; }
      38              : 
      39        50487 :         public CCodeUnaryExpression (CCodeUnaryOperator op, CCodeExpression expr) {
      40        16829 :                 operator = op;
      41        16829 :                 inner = expr;
      42              :         }
      43              : 
      44        12866 :         public override void write (CCodeWriter writer) {
      45        12866 :                 switch (operator) {
      46            0 :                 case CCodeUnaryOperator.PLUS: writer.write_string ("+"); inner.write_inner (writer); break;
      47          214 :                 case CCodeUnaryOperator.MINUS: writer.write_string ("-"); inner.write_inner (writer); break;
      48         1994 :                 case CCodeUnaryOperator.LOGICAL_NEGATION: writer.write_string ("!"); inner.write_inner (writer); break;
      49            2 :                 case CCodeUnaryOperator.BITWISE_COMPLEMENT: writer.write_string ("~"); inner.write_inner (writer); break;
      50              :                 case CCodeUnaryOperator.POINTER_INDIRECTION:
      51         1758 :                         var inner_unary = inner as CCodeUnaryExpression;
      52            1 :                         if (inner_unary != null && inner_unary.operator == CCodeUnaryOperator.ADDRESS_OF) {
      53              :                                 // simplify expression
      54            1 :                                 inner_unary.inner.write (writer);
      55            1 :                                 return;
      56              :                         }
      57         1757 :                         writer.write_string ("*");
      58         1757 :                         inner.write_inner (writer);
      59         1757 :                         break;
      60              :                 case CCodeUnaryOperator.ADDRESS_OF:
      61         8538 :                         var inner_unary = inner as CCodeUnaryExpression;
      62           29 :                         if (inner_unary != null && inner_unary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
      63              :                                 // simplify expression
      64           29 :                                 inner_unary.inner.write (writer);
      65           29 :                                 return;
      66              :                         }
      67         8509 :                         writer.write_string ("&");
      68         8509 :                         inner.write_inner (writer);
      69         8509 :                         break;
      70            0 :                 case CCodeUnaryOperator.PREFIX_INCREMENT: writer.write_string ("++"); inner.write_inner (writer); break;
      71            3 :                 case CCodeUnaryOperator.PREFIX_DECREMENT: writer.write_string ("--"); inner.write_inner (writer); break;
      72          357 :                 case CCodeUnaryOperator.POSTFIX_INCREMENT: inner.write_inner (writer); writer.write_string ("++"); break;
      73            0 :                 case CCodeUnaryOperator.POSTFIX_DECREMENT: inner.write_inner (writer); writer.write_string ("--"); break;
      74            0 :                 default: assert_not_reached ();
      75              :                 }
      76              :         }
      77              : 
      78         1547 :         public override void write_inner (CCodeWriter writer) {
      79         1547 :                 writer.write_string ("(");
      80         1547 :                 this.write (writer);
      81         1547 :                 writer.write_string (")");
      82              :         }
      83              : }
      84              : 
      85              : public enum Vala.CCodeUnaryOperator {
      86              :         PLUS,
      87              :         MINUS,
      88              :         LOGICAL_NEGATION,
      89              :         BITWISE_COMPLEMENT,
      90              :         POINTER_INDIRECTION,
      91              :         ADDRESS_OF,
      92              :         PREFIX_INCREMENT,
      93              :         PREFIX_DECREMENT,
      94              :         POSTFIX_INCREMENT,
      95              :         POSTFIX_DECREMENT
      96              : }
        

Generated by: LCOV version 2.0-1