1 /* 2 This file is part of GNU APL, a free implementation of the 3 ISO/IEC Standard 13751, "Programming Language APL, Extended" 4 5 Copyright (C) 2008-2015 Dr. Jürgen Sauermann 6 7 This program is free software: you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation, either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef __INDEXEXPR_HH_DEFINED__ 22 #define __INDEXEXPR_HH_DEFINED__ 23 24 #include "Cell.hh" 25 #include "DynamicObject.hh" 26 #include "Value.hh" 27 28 //----------------------------------------------------------------------------- 29 /** 30 An array of index values. 31 */ 32 /// The interal representation of some APL index [A1;A2;...;An] 33 class IndexExpr : public DynamicObject 34 { 35 public: 36 /// constructor: empty (0-dimensional) IndexExpr 37 IndexExpr(Assign_state ass_state, const char * loc); 38 39 /// destructor 40 ~IndexExpr(); 41 42 /// The quad-io for this index. 43 uint32_t quad_io; 44 45 /// The values (0 = elided index as in [] or [;]. 46 Value_P values[MAX_RANK]; 47 48 /// append a value. add(Value_P val)49 void add(Value_P val) 50 { Assert(rank < MAX_RANK); 51 values[rank++] = val; } 52 53 /// return the number of values (= number of semicolons + 1) value_count() const54 uRank value_count() const { return rank; } 55 56 /// return true iff the number of dimensions is 1 (i.e. no ; and non-empty) is_axis() const57 bool is_axis() const { return rank == 1; } 58 59 /// Return an axis (from an IndexExpr of rank 1. 60 Rank get_axis(Rank max_axis) const; 61 62 /// set axis \b axis to \b val 63 void set_value(uAxis axis, Value_P val); 64 65 /// return true iff this index is part of indexed assignment ( A[]← ) get_assign_state() const66 Assign_state get_assign_state() const 67 { return assign_state; } 68 69 /// Return a set of axes as shape. This is used to convert a number of 70 /// axes (like in [2 3]) into a shape (like 2 3). 71 Shape to_shape() const; 72 73 /// return one axis value and clear it in \b this IndexExpr 74 Value_P extract_value(uAxis rk); 75 76 /// clear all axis values 77 void extract_all(); 78 79 /// check that all indices are valid, return true if not. 80 bool check_range(const Shape & shape) const; 81 82 /// print stale IndexExprs, and return the number of stale IndexExprs. 83 static int print_stale(ostream & out); 84 85 /// erase stale IndexExprs 86 static void erase_stale(const char * loc); 87 88 protected: 89 /// the number of dimensions 90 uRank rank; 91 92 /// true iff this index is part of indexed assignment ( A[]← ) 93 const Assign_state assign_state; 94 }; 95 //----------------------------------------------------------------------------- 96 97 #endif // __INDEXEXPR_HH_DEFINED__ 98