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

            Line data    Source code
       1              : /* valadeclarationstatement.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              : 
      24              : /**
      25              :  * Represents a local variable or constant declaration statement in the source code.
      26              :  */
      27       170146 : public class Vala.DeclarationStatement : CodeNode, Statement {
      28              :         /**
      29              :          * The local variable or constant declaration.
      30              :          */
      31              :         public Symbol declaration {
      32      1147881 :                 get {
      33      1147881 :                         return _declaration;
      34              :                 }
      35       167072 :                 private set {
      36       167072 :                         _declaration = value;
      37       167072 :                         if (_declaration != null) {
      38       167072 :                                 _declaration.parent_node = this;
      39              :                         }
      40              :                 }
      41              :         }
      42              : 
      43       167072 :         Symbol _declaration;
      44              : 
      45              :         /**
      46              :          * Creates a new declaration statement.
      47              :          *
      48              :          * @param declaration       local variable declaration
      49              :          * @param source_reference  reference to source code
      50              :          * @return                  newly created declaration statement
      51              :          */
      52       501216 :         public DeclarationStatement (Symbol declaration, SourceReference? source_reference = null) {
      53       167072 :                 this.declaration = declaration;
      54       167072 :                 this.source_reference = source_reference;
      55              :         }
      56              : 
      57       199479 :         public override void accept (CodeVisitor visitor) {
      58       199479 :                 visitor.visit_declaration_statement (this);
      59              :         }
      60              : 
      61       199479 :         public override void accept_children (CodeVisitor visitor) {
      62       199479 :                 declaration.accept (visitor);
      63              :         }
      64              : 
      65       147060 :         public override void get_error_types (Collection<DataType> collection, SourceReference? source_reference = null) {
      66       147060 :                 if (source_reference == null) {
      67       145333 :                         source_reference = this.source_reference;
      68              :                 }
      69       147060 :                 unowned LocalVariable? local = declaration as LocalVariable;
      70       147041 :                 if (local != null && local.initializer != null) {
      71        80180 :                         local.initializer.get_error_types (collection, source_reference);
      72              :                 }
      73              :         }
      74              : 
      75       160080 :         public override bool check (CodeContext context) {
      76       160080 :                 if (checked) {
      77            0 :                         return !error;
      78              :                 }
      79              : 
      80       160080 :                 checked = true;
      81              : 
      82       160080 :                 if (!declaration.check (context)) {
      83              :                         // ignore inner error
      84          104 :                         error = true;
      85          104 :                         return false;
      86              :                 }
      87              : 
      88       159976 :                 return !error;
      89              :         }
      90              : 
      91        12703 :         public override void emit (CodeGenerator codegen) {
      92        12703 :                 codegen.visit_declaration_statement (this);
      93              :         }
      94              : 
      95       314082 :         public override void get_defined_variables (Collection<Variable> collection) {
      96       314082 :                 unowned LocalVariable? local = declaration as LocalVariable;
      97       314031 :                 if (local != null) {
      98       314031 :                         unowned ArrayType? array_type = local.variable_type as ArrayType;
      99       314031 :                         if (local.initializer != null) {
     100       174708 :                                 local.initializer.get_defined_variables (collection);
     101       174708 :                                 collection.add (local);
     102       139323 :                         } else if (array_type != null && array_type.fixed_length) {
     103           63 :                                 collection.add (local);
     104              :                         }
     105              :                 }
     106              :         }
     107              : 
     108       104694 :         public override void get_used_variables (Collection<Variable> collection) {
     109       104694 :                 unowned LocalVariable? local = declaration as LocalVariable;
     110       104677 :                 if (local != null && local.initializer != null) {
     111        58236 :                         local.initializer.get_used_variables (collection);
     112              :                 }
     113              :         }
     114              : }
        

Generated by: LCOV version 2.0-1