summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-01-02 00:26:29 -0700
committerMike Buland <eichlan@xagasoft.com>2012-01-02 00:26:29 -0700
commit0433eb31936fc72486e9a81732d5bcd38cf5808a (patch)
tree01f2a53e300af872350b700dbe8d4a0fa7fac38d /src
parent55e6f570f5760e970c6523458914b5e4c63a6ce4 (diff)
downloadstage-0433eb31936fc72486e9a81732d5bcd38cf5808a.tar.gz
stage-0433eb31936fc72486e9a81732d5bcd38cf5808a.tar.bz2
stage-0433eb31936fc72486e9a81732d5bcd38cf5808a.tar.xz
stage-0433eb31936fc72486e9a81732d5bcd38cf5808a.zip
Variables upconvert on add now.
It's not perfect, but it's decent for now, and early testing.
Diffstat (limited to 'src')
-rw-r--r--src/variable.cpp17
-rw-r--r--src/variable.h5
2 files changed, 20 insertions, 2 deletions
diff --git a/src/variable.cpp b/src/variable.cpp
index a3fb4a2..965e1af 100644
--- a/src/variable.cpp
+++ b/src/variable.cpp
@@ -453,6 +453,16 @@ Variable Variable::operator+( const Variable &rhs ) const
453{ 453{
454 if( eType != rhs.eType ) 454 if( eType != rhs.eType )
455 { 455 {
456 Type eNew = bestType( eType, rhs.eType );
457
458 if( eType != eNew )
459 {
460 return to( eNew ) + rhs;
461 }
462 else
463 {
464 return *this + rhs.to( eNew );
465 }
456 throw VariableException("Adding between dissimilar types is not yet supported."); 466 throw VariableException("Adding between dissimilar types is not yet supported.");
457 } 467 }
458 else 468 else
@@ -868,6 +878,13 @@ void Variable::deinitType()
868 iValue = 0; 878 iValue = 0;
869} 879}
870 880
881Variable::Type Variable::bestType( Variable::Type t1, Variable::Type t2 ) const
882{
883 Type tBest = Bu::max( t1, t2 );
884
885 return tBest;
886}
887
871template<> uint32_t Bu::__calcHashCode<Variable>( const Variable &k ) 888template<> uint32_t Bu::__calcHashCode<Variable>( const Variable &k )
872{ 889{
873 switch( k.getType() ) 890 switch( k.getType() )
diff --git a/src/variable.h b/src/variable.h
index 8741b28..2eedcbb 100644
--- a/src/variable.h
+++ b/src/variable.h
@@ -28,12 +28,12 @@ public:
28 tBool, 28 tBool,
29 tInt, 29 tInt,
30 tFloat, 30 tFloat,
31 tString,
32 tSituation, 31 tSituation,
33 tVariable, 32 tVariable,
34 tVarPtr, 33 tVarPtr,
35 tList, 34 tList,
36 tDictionary 35 tDictionary,
36 tString,
37 }; 37 };
38 38
39public: 39public:
@@ -90,6 +90,7 @@ public:
90private: 90private:
91 void initType(); 91 void initType();
92 void deinitType(); 92 void deinitType();
93 Type bestType( Type t1, Type t2 ) const;
93 94
94private: 95private:
95 Type eType; 96 Type eType;