1 /* 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 3 * Copyright (C) 2008-2008 - DIGITEO - Bruno JOFRET 4 * 5 * Copyright (C) 2012 - 2016 - Scilab Enterprises 6 * 7 * This file is hereby licensed under the terms of the GNU GPL v2.0, 8 * pursuant to article 5.3.4 of the CeCILL v.2.1. 9 * This file was originally licensed under the terms of the CeCILL v2.1, 10 * and continues to be available under such terms. 11 * For more information, see the COPYING file which you should have received 12 * along with this program. 13 * 14 */ 15 16 #ifndef AST_LISTEXP_HXX 17 #define AST_LISTEXP_HXX 18 19 #include "exp.hxx" 20 21 namespace ast 22 { 23 24 /** \brief Abstract an Operation Expression node. 25 ** 26 ** \b Example: 1:0.5:10 */ 27 class ListExp : public Exp 28 { 29 public: 30 /** \name Ctor & dtor. 31 ** \{ */ 32 public: 33 /** \brief Construct an Implicit list Expression node. 34 ** \param location scanner position informations 35 ** \param start the start point of the list 36 ** \param step the step between each element 37 ** \param end the end of the list (the max value) 38 ** 39 ** \b Example: start:step:stop 40 ** \li "start" is the start point of the list 41 ** \li "step" is the step between each element 42 ** \li "stop" is the end of the list (the max value) 43 */ ListExp(const Location & location,Exp & start,Exp & step,Exp & end,bool explicitStep=false)44 ListExp (const Location& location, 45 Exp& start, Exp& step, Exp& end, bool explicitStep = false) 46 : Exp (location), 47 _explicitStep(explicitStep) 48 { 49 start.setParent(this); 50 step.setParent(this); 51 end.setParent(this); 52 _exps.push_back(&start); 53 _exps.push_back(&step); 54 _exps.push_back(&end); 55 56 values[0] = std::numeric_limits<double>::quiet_NaN(); 57 values[1] = std::numeric_limits<double>::quiet_NaN(); 58 values[2] = std::numeric_limits<double>::quiet_NaN(); 59 values[3] = std::numeric_limits<double>::quiet_NaN(); 60 61 is_values_int[0] = false; 62 is_values_int[1] = false; 63 is_values_int[2] = false; 64 is_values_int[3] = false; 65 } 66 67 /** \brief Destroy a Operation Expression node. 68 ** 69 ** Delete left and right, see constructor. */ ~ListExp()70 virtual ~ListExp () 71 { 72 } 73 /** \} */ 74 clone()75 virtual ListExp* clone() 76 { 77 ListExp* cloned = new ListExp(getLocation(), *getStart().clone(), *getStep().clone(), *getEnd().clone(), hasExplicitStep()); 78 cloned->setVerbose(isVerbose()); 79 return cloned; 80 } 81 82 /** \name Visitors entry point. 83 ** \{ */ 84 public: 85 /** \brief Accept a const visitor \a v. */ accept(Visitor & v)86 virtual void accept (Visitor& v) 87 { 88 v.visit (*this); 89 } 90 /** \brief Accept a non-const visitor \a v. */ accept(ConstVisitor & v) const91 virtual void accept (ConstVisitor& v) const 92 { 93 v.visit (*this); 94 } 95 /** \} */ 96 97 98 /** \name Accessors. 99 ** \{ */ 100 public: 101 /** \brief Return the expression (read only) */ getStart() const102 const Exp& getStart () const 103 { 104 return *_exps[0]; 105 } 106 /** \brief Return the expression (read and write) */ getStart()107 Exp& getStart () 108 { 109 return *_exps[0]; 110 } 111 112 /** \brief Return the expression (read only) */ getStep() const113 const Exp& getStep () const 114 { 115 return *_exps[1]; 116 } 117 /** \brief Return the expression (read and write) */ getStep()118 Exp& getStep () 119 { 120 return *_exps[1]; 121 } 122 123 /** \brief Return the expression (read only) */ getEnd() const124 const Exp& getEnd () const 125 { 126 return *_exps[2]; 127 } 128 /** \brief Return the expression (read and write) */ getEnd()129 Exp& getEnd () 130 { 131 return *_exps[2]; 132 } 133 setValues(double start,double step,double end,double single)134 inline void setValues(double start, double step, double end, double single) 135 { 136 values[0] = start; 137 values[1] = step; 138 values[2] = end; 139 values[3] = single; 140 } 141 getValues() const142 inline const double * getValues() const 143 { 144 return values; 145 } 146 147 /** \brief Return if expression has explicit step defined */ hasExplicitStep() const148 bool hasExplicitStep () const 149 { 150 return _explicitStep; 151 } 152 153 /** \} */ getType() const154 virtual ExpType getType() const 155 { 156 return LISTEXP; 157 } isListExp() const158 inline bool isListExp() const 159 { 160 return true; 161 } 162 163 protected: 164 double values[4]; 165 bool is_values_int[4]; 166 /** \brief has list explicit step. */ 167 bool _explicitStep; 168 }; 169 170 } // namespace ast 171 172 #endif // !AST_LISTEXP_HXX 173