summaryrefslogtreecommitdiff
path: root/src/variable.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-12-29 23:30:49 -0700
committerMike Buland <eichlan@xagasoft.com>2011-12-29 23:30:49 -0700
commit35f71b12dc48a928d98743f607f62b2f6dbe7307 (patch)
treef4297f57e570f52f3776392fc8ed4075db1ab4ac /src/variable.cpp
parentf66458278ce3663397fc985a1253c85b74f011e6 (diff)
downloadstage-35f71b12dc48a928d98743f607f62b2f6dbe7307.tar.gz
stage-35f71b12dc48a928d98743f607f62b2f6dbe7307.tar.bz2
stage-35f71b12dc48a928d98743f607f62b2f6dbe7307.tar.xz
stage-35f71b12dc48a928d98743f607f62b2f6dbe7307.zip
Goto works, scopes work.
Diffstat (limited to 'src/variable.cpp')
-rw-r--r--src/variable.cpp42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/variable.cpp b/src/variable.cpp
index 5e2462c..4c5ca4c 100644
--- a/src/variable.cpp
+++ b/src/variable.cpp
@@ -4,6 +4,11 @@
4#include <stdlib.h> 4#include <stdlib.h>
5 5
6typedef Bu::ExceptionBase VariableException; 6typedef Bu::ExceptionBase VariableException;
7
8bool VariableRef::operator==( const VariableRef &rhs ) const
9{
10 return sid == rhs.sid && sName == rhs.sName;
11}
7 12
8Variable::Variable() : 13Variable::Variable() :
9 eType( tNull ), 14 eType( tNull ),
@@ -62,10 +67,11 @@ Variable Variable::newSituationName( const Bu::String &s )
62 return v; 67 return v;
63} 68}
64 69
65Variable Variable::newVariableName( const Bu::String &s ) 70Variable Variable::newVariableName( const Bu::String &s, ScopeId sid )
66{ 71{
67 Variable v( tVariable ); 72 Variable v( tVariable );
68 (*v.sValue) = s; 73 v.rValue->sName = s;
74 v.rValue->sid = sid;
69 return v; 75 return v;
70} 76}
71 77
@@ -86,9 +92,16 @@ double Variable::getFloat() const
86 92
87Bu::String Variable::getString() const 93Bu::String Variable::getString() const
88{ 94{
95 if( eType != tString && eType != tSituation )
96 throw Bu::ExceptionBase("That's not a string.");
89 return *sValue; 97 return *sValue;
90} 98}
91 99
100VariableRef Variable::getVariableRef() const
101{
102 return *rValue;
103}
104
92Variable Variable::to( Type e ) const 105Variable Variable::to( Type e ) const
93{ 106{
94 if( e == eType ) 107 if( e == eType )
@@ -222,10 +235,13 @@ Variable &Variable::operator=( const Variable &rhs )
222 235
223 case tString: 236 case tString:
224 case tSituation: 237 case tSituation:
225 case tVariable:
226 (*sValue) = *rhs.sValue; 238 (*sValue) = *rhs.sValue;
227 break; 239 break;
228 240
241 case tVariable:
242 (*rValue) = *rhs.rValue;
243 break;
244
229 case tList: 245 case tList:
230 (*lValue) = *rhs.lValue; 246 (*lValue) = *rhs.lValue;
231 break; 247 break;
@@ -527,8 +543,10 @@ bool Variable::operator==( const Variable &rhs ) const
527 543
528 case tString: 544 case tString:
529 case tSituation: 545 case tSituation:
530 case tVariable:
531 return (*sValue) == (*rhs.sValue); 546 return (*sValue) == (*rhs.sValue);
547
548 case tVariable:
549 return (*rValue) == (*rhs.rValue);
532 550
533 case tList: 551 case tList:
534 return (*lValue) == (*rhs.lValue); 552 return (*lValue) == (*rhs.lValue);
@@ -678,9 +696,12 @@ void Variable::initType()
678 { 696 {
679 case tString: 697 case tString:
680 case tSituation: 698 case tSituation:
681 case tVariable:
682 sValue = new Bu::String(); 699 sValue = new Bu::String();
683 break; 700 break;
701
702 case tVariable:
703 rValue = new VariableRef();
704 break;
684 705
685 case tList: 706 case tList:
686 lValue = new VList(); 707 lValue = new VList();
@@ -698,9 +719,12 @@ void Variable::deinitType()
698 { 719 {
699 case tString: 720 case tString:
700 case tSituation: 721 case tSituation:
701 case tVariable:
702 delete sValue; 722 delete sValue;
703 break; 723 break;
724
725 case tVariable:
726 delete rValue;
727 break;
704 728
705 case tList: 729 case tList:
706 delete lValue; 730 delete lValue;
@@ -729,8 +753,10 @@ template<> uint32_t Bu::__calcHashCode<Variable>( const Variable &k )
729 753
730 case Variable::tString: 754 case Variable::tString:
731 case Variable::tSituation: 755 case Variable::tSituation:
732 case Variable::tVariable:
733 return Bu::__calcHashCode( *k.sValue ); 756 return Bu::__calcHashCode( *k.sValue );
757
758 case Variable::tVariable:
759 throw VariableException("You cannot use a variable ref as a key in a dictionary.");
734 760
735 case Variable::tList: 761 case Variable::tList:
736 throw VariableException("You cannot use a list as a key in a dictionary."); 762 throw VariableException("You cannot use a list as a key in a dictionary.");
@@ -767,7 +793,7 @@ Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v )
767 return f << "<<" << *v.sValue << ">>"; 793 return f << "<<" << *v.sValue << ">>";
768 794
769 case Variable::tVariable: 795 case Variable::tVariable:
770 return f << "(varref:\"" << *v.sValue << "\")"; 796 return f << "(varref:\"" << v.rValue->sName << "\")";
771 797
772 case Variable::tList: 798 case Variable::tList:
773 return f << *v.lValue; 799 return f << *v.lValue;