Hormiga 1.0

/var/www/hormigaproject.com.ar/files/src/oper/operand.h

Go to the documentation of this file.
00001 
00002 /*
00003 # Hormiga - Software de cálculo programable.
00004 #
00005 # Copyright (C) 2008, 2009 Leonardo Román, Hugo J. Curti, Norma  Ercoli,
00006 # Universidad Nacional del Centro de la Provincia de Buenos Aires
00007 # (UNCPBA)
00008 #
00009 # Este programa es parte de Hormiga.
00010 #
00011 # Hormiga es software libre. Puede redistribuirlo y/o modificarlo
00012 # bajo los términos de la Licencia Pública General de GNU según es
00013 # publicada por la Free Software Foundation, versión 2. Vea el archivo
00014 # COPIA (español, no oficial) o COPYING (inglés, oficial) en directorio
00015 # raíz.
00016 #
00017 # Hormiga se distribuye con la esperanza de que sea útil, pero SIN
00018 # NINGUNA GARANTÍA, incluso sin la garantía MERCANTIL implícita o sin
00019 # garantizar la CONVENIENCIA PARA UN PROPÓSITO PARTICULAR. Véase la
00020 # Licencia Pública General de GNU para más detalles.
00021 #
00022 # Debería haber recibido una copia de la Licencia Pública General junto
00023 # con Hormiga. Si no ha sido así, escriba a la Free Software
00024 # Foundation, Inc., en 675 Mass Ave, Cambridge, MA 02139, EEUU.
00025 # Añada también información sobre cómo contactar con usted mediante
00026 # correo electrónico y postal.
00027 #
00028 # This file is part of Hormiga.
00029 #
00030 # Hormiga is free software; you can redistribute it and/or modify
00031 # it under the terms of the GNU General Public License version 2
00032 # as published by the Free Software Foundation; see the file COPYING
00033 # in the top directory for details.
00034 #
00035 # Hormiga is distributed in the hope that it will be useful,
00036 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00037 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00038 # GNU General Public License for more details.
00039 #
00040 # You should have received a copy of the GNU General Public License
00041 # along with Hormiga; if not, write to the Free Software
00042 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00043 # USA
00044 */
00045 
00046 
00047 #ifndef OPERAND_H
00048 #define OPERAND_H
00049 
00050 #include "oper/operand_interface.h"
00051 
00052 
00053 /* Mmmm... necesito un puntero a Step, pero si hago el include se arma la del
00054  * huevo y la gallina ... Parece que una declaracion implicita de la clase
00055  * soluciona el problema.
00056  */
00057 //#include "step/step.h"
00058 class Step ;
00059 
00060 
00061 
00062 class Boolean : public Operand
00063 {
00064 public:
00065     virtual T_MAGNITUDE getValue () const ;
00066     virtual T_STRING toString () const ;
00067     virtual bool isShareable () { return ( true ) ; }
00068     virtual T_STRING getSymbol() const { return ( symbol ) ; }
00069     virtual bool isConstantExpresion () const ;
00071     Boolean () ;
00072     Boolean ( T_MAGNITUDE v , T_STRING &symbol ) ;
00073     Boolean ( Boolean &v ) ;
00074     virtual ~Boolean () {}
00075 
00076 protected:
00077     bool value ;
00078     T_STRING symbol ;
00079 };
00080 
00081 
00082 class VarBoolean : public Boolean , Seteable
00083 {
00084 public:
00085     virtual T_MAGNITUDE setValue ( T_MAGNITUDE v ) ;
00086     virtual bool isConstantExpresion () const ;
00088     VarBoolean () ;
00089     VarBoolean ( T_MAGNITUDE &v , T_STRING &symbol ) ;
00090     VarBoolean ( Boolean &v ) ;
00091     VarBoolean ( VarBoolean &v ) ;
00092     virtual ~VarBoolean () {} ;
00093 };
00094 
00095 class Value : public Operand , public Typeable
00096 {
00097 public:
00098     virtual T_MAGNITUDE getValue () const ;
00099     virtual T_STRING toString () const ;
00100     virtual bool isShareable () { return ( true ) ; }
00101     virtual T_STRING getSymbol() const { return ( symbol ) ; }
00102     // This method should be abstracted into a super-class over 'Variable'
00103     virtual bool isSeteable () { return ( false ) ; }
00104     virtual bool isConstantExpresion () const ;
00106     Value () ;
00107     Value ( T_MAGNITUDE v , T_STRING &symbol , Type* type = NULL ) ;
00108     Value ( Value &v ) ;
00109     virtual ~Value () {}
00110 protected:
00111     T_MAGNITUDE value ;
00112     T_STRING symbol ;
00113 };
00114 
00115 class VarValue : public Value , Seteable
00116 {
00117 public:
00118     virtual T_MAGNITUDE setValue ( T_MAGNITUDE v ) ;
00119     virtual void setOwnerStep ( Step *step ) { this->owner = step ; }
00120     virtual Step* getOwnerStep () { return ( owner ) ; }
00121     // Overloaded from 'Value'
00122     virtual bool isSeteable () { return ( true ) ; }
00123     virtual bool isConstantExpresion () const ;
00125     VarValue () ;
00126     VarValue ( T_MAGNITUDE v , T_STRING &symbol  , Type* type ) ;
00127     VarValue ( Value &v ) ;
00128     VarValue ( VarValue &v ) ;
00129     virtual ~VarValue () {}
00130 protected:
00131     Step* owner ;
00132 };
00133 
00134 class VarValueProxy : public VarValue
00135 {
00136 public:
00141     virtual void setProxiedOperand ( Operand* proxyedVar ) ;
00142     virtual Operand* getProxiedOperand () { return ( realParam ) ; }
00143     virtual void resetInternalValue () ;
00145     virtual T_MAGNITUDE setValue ( T_MAGNITUDE v ) ;
00146     virtual T_MAGNITUDE getValue () const ;
00147     virtual T_STRING toString () const ;
00148     //virtual bool isShareable () { return ( false ) ; } ???
00150     VarValueProxy () ;
00151     VarValueProxy ( T_STRING symbol  , Type* type , bool isReference ) ;
00152     virtual ~VarValueProxy () ;
00153 protected:
00154     Operand *realParam ;
00155     VarValue *formalParam ; // Not alwais used.
00156     bool isReference ;
00157 };
00158 
00159 
00172 class Sequence : public Operand
00173 {
00174 public:
00175     T_MAGNITUDE getFirst () const ;
00176     T_MAGNITUDE getLast () const ;
00177     T_MAGNITUDE getStep () const ;
00178 
00181     /* This method is needed by FunctionInstance in order to known that the
00182      * Function should be 'Integrated' (not only evaluated)
00183      */
00184     virtual bool isSequence () { return ( true ) ; }
00185 
00186     virtual bool isConstantExpresion () const ;
00187 
00188     virtual T_MAGNITUDE getValue () const ;
00189     virtual T_STRING toString () const ;
00190     virtual T_STRING getSymbol () const { return ("SEQUENCE") ; }
00191 
00193     Sequence ( Operand* first , Operand* last , Operand* step ) ;
00194     virtual ~Sequence () ;
00195 protected:
00196     Operand* first ;
00197     Operand* last ;
00198     Operand* step ;
00199 };
00200 
00201 
00211 class OperatorNot : public UnaryOperator
00212 {
00213 public:
00214     virtual T_STRING getSymbol () const ;
00215     virtual T_MAGNITUDE getValue() const ;
00216     OperatorNot ( Operand *op ) ;
00217 protected:
00218     static T_STRING symbol ;
00219 };
00220 
00221 class OperatorNeg : public UnaryOperator
00222 {
00223 public:
00224     virtual T_STRING getSymbol () const ;
00225     virtual T_MAGNITUDE getValue() const ;
00226     OperatorNeg ( Operand *op ) ;
00227 protected:
00228     static T_STRING symbol ;
00229 };
00230 
00231 class OperatorFactorial : public UnaryOperator
00232 {
00233 public:
00234     virtual T_STRING getSymbol () const ;
00235     virtual T_MAGNITUDE getValue() const ;
00236     OperatorFactorial ( Operand *op ) ;
00237 protected:
00238     static T_STRING symbol ;
00239 };
00240 
00241 
00244 // ------ ARITMETICS
00245 class OperatorAdd : public BinaryOperator
00246 {
00247 public:
00248     virtual T_STRING getSymbol () const ;
00249     virtual T_MAGNITUDE getValue() const ;
00250     OperatorAdd ( Operand *op1 , Operand *op2 ) ;
00251 protected:
00252     static T_STRING symbol ;
00253 };
00254 
00255 
00256 class OperatorSub : public BinaryOperator
00257 {
00258 public:
00259     virtual T_STRING getSymbol () const ;
00260     virtual T_MAGNITUDE getValue() const ;
00261     OperatorSub ( Operand *op1 , Operand *op2 ) ;
00262 protected:
00263     static T_STRING symbol ;
00264 };
00265 
00266 class OperatorMul : public BinaryOperator
00267 {
00268 public:
00269     virtual T_STRING getSymbol () const ;
00270     virtual T_MAGNITUDE getValue() const ;
00271     OperatorMul ( Operand *op1 , Operand *op2 ) ;
00272 protected:
00273     static T_STRING symbol ;
00274 };
00275 
00276 class OperatorDiv : public BinaryOperator
00277 {
00278 public:
00279     virtual T_STRING getSymbol () const ;
00280     virtual T_MAGNITUDE getValue() const ;
00281     OperatorDiv ( Operand *op1 , Operand *op2 ) ;
00282 protected:
00283     static T_STRING symbol ;
00284 };
00285 
00286 class OperatorMod : public BinaryOperator
00287 {
00288 public:
00289     virtual T_STRING getSymbol () const ;
00290     virtual T_MAGNITUDE getValue() const ;
00291     OperatorMod ( Operand *op1 , Operand *op2 ) ;
00292 protected:
00293     static T_STRING symbol ;
00294 };
00295 
00296 // ----- BOLEANS
00297 class OperatorAnd : public BinaryOperator
00298 {
00299 public:
00300     virtual T_STRING getSymbol () const ;
00301     virtual T_MAGNITUDE getValue() const ;
00302     OperatorAnd ( Operand *op1 , Operand *op2 ) ;
00303 protected:
00304     static T_STRING symbol ;
00305 };
00306 
00307 class OperatorOr : public BinaryOperator
00308 {
00309 public:
00310     virtual T_STRING getSymbol () const ;
00311     virtual T_MAGNITUDE getValue() const ;
00312     OperatorOr ( Operand *op1 , Operand *op2 ) ;
00313 protected:
00314     static T_STRING symbol ;
00315 };
00316 
00317 class OperatorEqual : public BinaryOperator
00318 {
00319 public:
00320     virtual T_STRING getSymbol () const ;
00321     virtual T_MAGNITUDE getValue() const ;
00322     OperatorEqual ( Operand *op1 , Operand *op2 ) ;
00323 protected:
00324     static T_STRING symbol ;
00325 };
00326 
00327 class OperatorDistinct : public BinaryOperator
00328 {
00329 public:
00330     virtual T_STRING getSymbol () const ;
00331     virtual T_MAGNITUDE getValue() const ;
00332     OperatorDistinct ( Operand *op1 , Operand *op2 ) ;
00333 protected:
00334     static T_STRING symbol ;
00335 };
00336 
00337 class OperatorGT : public BinaryOperator
00338 {
00339 public:
00340     virtual T_STRING getSymbol () const ;
00341     virtual T_MAGNITUDE getValue() const ;
00342     OperatorGT ( Operand *op1 , Operand *op2 ) ;
00343 protected:
00344     static T_STRING symbol ;
00345 };
00346 
00347 class OperatorLT : public BinaryOperator
00348 {
00349 public:
00350     virtual T_STRING getSymbol () const ;
00351     virtual T_MAGNITUDE getValue() const ;
00352     OperatorLT ( Operand *op1 , Operand *op2 ) ;
00353 protected:
00354     static T_STRING symbol ;
00355 };
00356 
00357 class OperatorGE : public BinaryOperator
00358 {
00359 public:
00360     virtual T_STRING getSymbol () const ;
00361     virtual T_MAGNITUDE getValue() const ;
00362     OperatorGE ( Operand *op1 , Operand *op2 ) ;
00363 protected:
00364     static T_STRING symbol ;
00365 };
00366 
00367 class OperatorLE : public BinaryOperator
00368 {
00369 public:
00370     virtual T_STRING getSymbol () const ;
00371     virtual T_MAGNITUDE getValue() const ;
00372     OperatorLE ( Operand *op1 , Operand *op2 ) ;
00373 protected:
00374     static T_STRING symbol ;
00375 };
00376 
00377 #endif // OPERAND_H