From 35f71b12dc48a928d98743f607f62b2f6dbe7307 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 29 Dec 2011 23:30:49 -0700 Subject: Goto works, scopes work. --- src/variable.cpp | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'src/variable.cpp') 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 @@ #include typedef Bu::ExceptionBase VariableException; + +bool VariableRef::operator==( const VariableRef &rhs ) const +{ + return sid == rhs.sid && sName == rhs.sName; +} Variable::Variable() : eType( tNull ), @@ -62,10 +67,11 @@ Variable Variable::newSituationName( const Bu::String &s ) return v; } -Variable Variable::newVariableName( const Bu::String &s ) +Variable Variable::newVariableName( const Bu::String &s, ScopeId sid ) { Variable v( tVariable ); - (*v.sValue) = s; + v.rValue->sName = s; + v.rValue->sid = sid; return v; } @@ -86,9 +92,16 @@ double Variable::getFloat() const Bu::String Variable::getString() const { + if( eType != tString && eType != tSituation ) + throw Bu::ExceptionBase("That's not a string."); return *sValue; } +VariableRef Variable::getVariableRef() const +{ + return *rValue; +} + Variable Variable::to( Type e ) const { if( e == eType ) @@ -222,10 +235,13 @@ Variable &Variable::operator=( const Variable &rhs ) case tString: case tSituation: - case tVariable: (*sValue) = *rhs.sValue; break; + case tVariable: + (*rValue) = *rhs.rValue; + break; + case tList: (*lValue) = *rhs.lValue; break; @@ -527,8 +543,10 @@ bool Variable::operator==( const Variable &rhs ) const case tString: case tSituation: - case tVariable: return (*sValue) == (*rhs.sValue); + + case tVariable: + return (*rValue) == (*rhs.rValue); case tList: return (*lValue) == (*rhs.lValue); @@ -678,9 +696,12 @@ void Variable::initType() { case tString: case tSituation: - case tVariable: sValue = new Bu::String(); break; + + case tVariable: + rValue = new VariableRef(); + break; case tList: lValue = new VList(); @@ -698,9 +719,12 @@ void Variable::deinitType() { case tString: case tSituation: - case tVariable: delete sValue; break; + + case tVariable: + delete rValue; + break; case tList: delete lValue; @@ -729,8 +753,10 @@ template<> uint32_t Bu::__calcHashCode( const Variable &k ) case Variable::tString: case Variable::tSituation: - case Variable::tVariable: return Bu::__calcHashCode( *k.sValue ); + + case Variable::tVariable: + throw VariableException("You cannot use a variable ref as a key in a dictionary."); case Variable::tList: 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 ) return f << "<<" << *v.sValue << ">>"; case Variable::tVariable: - return f << "(varref:\"" << *v.sValue << "\")"; + return f << "(varref:\"" << v.rValue->sName << "\")"; case Variable::tList: return f << *v.lValue; -- cgit v1.2.3