2008-02-15 18:31:40 +01:00
|
|
|
/*
|
2013-08-12 23:24:47 +02:00
|
|
|
* Copyright (C) 2008-2013 Dynare Team
|
2008-02-15 18:31:40 +01:00
|
|
|
*
|
|
|
|
* This file is part of Dynare.
|
|
|
|
*
|
|
|
|
* Dynare is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Dynare is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
#include "MacroDriver.hh"
|
|
|
|
|
|
|
|
MacroValue::MacroValue(MacroDriver &driver_arg) : driver(driver_arg)
|
|
|
|
{
|
|
|
|
driver.values.insert(this);
|
|
|
|
}
|
2008-02-15 18:31:40 +01:00
|
|
|
|
2008-02-19 15:24:40 +01:00
|
|
|
MacroValue::~MacroValue()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-22 13:03:38 +01:00
|
|
|
MacroValue::operator+() const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Unary operator + does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
MacroValue::operator-(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Operator - does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
MacroValue::operator-() const throw (TypeError)
|
|
|
|
{
|
2008-02-22 13:03:38 +01:00
|
|
|
throw TypeError("Unary operator - does not exist for this type");
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
MacroValue::operator*(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Operator * does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
MacroValue::operator/(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Operator / does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
MacroValue::operator<(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Operator < does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
MacroValue::operator>(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Operator > does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
MacroValue::operator<=(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Operator <= does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
MacroValue::operator>=(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Operator >= does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
MacroValue::operator&&(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Operator && does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
MacroValue::operator||(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Operator || does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
MacroValue::operator!() const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Operator ! does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-22 13:03:38 +01:00
|
|
|
MacroValue::operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsError)
|
2008-02-15 18:31:40 +01:00
|
|
|
{
|
|
|
|
throw TypeError("Operator [] does not exist for this type");
|
|
|
|
}
|
|
|
|
|
2013-08-12 23:24:47 +02:00
|
|
|
const MacroValue *
|
|
|
|
MacroValue::length() const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("Length not supported for this type");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
|
|
|
MacroValue::append(const MacroValue *mv) const throw (TypeError)
|
2008-02-20 10:56:47 +01:00
|
|
|
{
|
|
|
|
throw TypeError("Cannot append an array at the end of another one. Should use concatenation.");
|
|
|
|
}
|
|
|
|
|
2008-12-08 16:13:08 +01:00
|
|
|
const MacroValue *
|
|
|
|
MacroValue::in(const MacroValue *array) const throw (TypeError)
|
|
|
|
{
|
|
|
|
throw TypeError("First argument of 'in' operator cannot be an array");
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
|
|
|
MacroValue::new_base_value(MacroDriver &driver, int i)
|
2008-02-22 13:03:38 +01:00
|
|
|
{
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, i);
|
2008-02-22 13:03:38 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
|
|
|
MacroValue::new_base_value(MacroDriver &driver, const string &s)
|
2008-02-22 13:03:38 +01:00
|
|
|
{
|
2008-02-29 17:21:01 +01:00
|
|
|
return new StringMV(driver, s);
|
2008-02-22 13:03:38 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
IntMV::IntMV(MacroDriver &driver, int value_arg) : MacroValue(driver), value(value_arg)
|
2008-02-15 18:31:40 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-02-19 15:24:40 +01:00
|
|
|
IntMV::~IntMV()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator+(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for operands of + operator");
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value + mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-22 13:03:38 +01:00
|
|
|
IntMV::operator+() const throw (TypeError)
|
|
|
|
{
|
2008-02-29 17:21:01 +01:00
|
|
|
return this;
|
2008-02-22 13:03:38 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator-(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for operands of - operator");
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value - mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator-() const throw (TypeError)
|
|
|
|
{
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, -value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator*(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for operands of * operator");
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value * mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator/(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for operands of / operator");
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value / mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator<(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for operands of < operator");
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value < mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator>(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for operands of > operator");
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value > mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator<=(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for operands of <= operator");
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value <= mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator>=(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for operands of >= operator");
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value >= mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator==(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, 0);
|
2008-02-15 18:31:40 +01:00
|
|
|
else
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value == mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator!=(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, 1);
|
2008-02-15 18:31:40 +01:00
|
|
|
else
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value != mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator&&(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for operands of && operator");
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value && mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator||(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const IntMV *mv2 = dynamic_cast<const IntMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for operands of || operator");
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value || mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
IntMV::operator!() const throw (TypeError)
|
|
|
|
{
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, !value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
IntMV::toString() const
|
|
|
|
{
|
|
|
|
ostringstream ss;
|
|
|
|
ss << value;
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-19 15:24:40 +01:00
|
|
|
IntMV::toArray() const
|
|
|
|
{
|
|
|
|
vector<int> v;
|
|
|
|
v.push_back(value);
|
2008-02-29 17:21:01 +01:00
|
|
|
return new ArrayMV<int>(driver, v);
|
2008-02-19 15:24:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
|
|
|
IntMV::append(const MacroValue *array) const throw (TypeError)
|
2008-02-19 15:24:40 +01:00
|
|
|
{
|
2008-02-29 17:21:01 +01:00
|
|
|
const ArrayMV<int> *array2 = dynamic_cast<const ArrayMV<int> *>(array);
|
2008-02-19 15:24:40 +01:00
|
|
|
if (array2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for append operation");
|
2008-02-20 10:56:47 +01:00
|
|
|
|
|
|
|
vector<int> v(array2->values);
|
|
|
|
v.push_back(value);
|
2008-02-29 17:21:01 +01:00
|
|
|
return new ArrayMV<int>(driver, v);
|
2008-02-20 10:56:47 +01:00
|
|
|
}
|
|
|
|
|
2008-12-08 16:13:08 +01:00
|
|
|
const MacroValue *
|
|
|
|
IntMV::in(const MacroValue *array) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const ArrayMV<int> *array2 = dynamic_cast<const ArrayMV<int> *>(array);
|
|
|
|
if (array2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for 'in' operator");
|
|
|
|
|
|
|
|
int result = 0;
|
2009-12-16 18:13:23 +01:00
|
|
|
for (vector<int>::const_iterator it = array2->values.begin();
|
|
|
|
it != array2->values.end(); it++)
|
2008-12-08 16:13:08 +01:00
|
|
|
if (*it == value)
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new IntMV(driver, result);
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
|
|
|
IntMV::new_range(MacroDriver &driver, const MacroValue *mv1, const MacroValue *mv2) throw (TypeError)
|
2008-02-20 10:56:47 +01:00
|
|
|
{
|
2008-02-29 17:21:01 +01:00
|
|
|
const IntMV *mv1i = dynamic_cast<const IntMV *>(mv1);
|
|
|
|
const IntMV *mv2i = dynamic_cast<const IntMV *>(mv2);
|
2008-02-20 10:56:47 +01:00
|
|
|
if (mv1i == NULL || mv2i == NULL)
|
|
|
|
throw TypeError("Arguments of range operator (:) must be integers");
|
|
|
|
|
|
|
|
int v1 = mv1i->value;
|
|
|
|
int v2 = mv2i->value;
|
|
|
|
|
|
|
|
vector<int> result;
|
2009-12-16 18:13:23 +01:00
|
|
|
for (; v1 <= v2; v1++)
|
2008-02-20 10:56:47 +01:00
|
|
|
result.push_back(v1);
|
2008-02-29 17:21:01 +01:00
|
|
|
return new ArrayMV<int>(driver, result);
|
2008-02-19 15:24:40 +01:00
|
|
|
}
|
|
|
|
|
2011-02-04 16:25:38 +01:00
|
|
|
StringMV::StringMV(MacroDriver &driver, const string &value_arg) :
|
|
|
|
MacroValue(driver), value(value_arg)
|
2008-02-15 18:31:40 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-02-19 15:24:40 +01:00
|
|
|
StringMV::~StringMV()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
StringMV::operator+(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const StringMV *mv2 = dynamic_cast<const StringMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for operands of + operator");
|
2008-02-29 17:21:01 +01:00
|
|
|
return new StringMV(driver, value + mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
StringMV::operator==(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const StringMV *mv2 = dynamic_cast<const StringMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, 0);
|
2008-02-15 18:31:40 +01:00
|
|
|
else
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value == mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-15 18:31:40 +01:00
|
|
|
StringMV::operator!=(const MacroValue &mv) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const StringMV *mv2 = dynamic_cast<const StringMV *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, 1);
|
2008-02-15 18:31:40 +01:00
|
|
|
else
|
2008-02-29 17:21:01 +01:00
|
|
|
return new IntMV(driver, value != mv2->value);
|
2008-02-15 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-22 13:03:38 +01:00
|
|
|
StringMV::operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsError)
|
2008-02-19 15:24:40 +01:00
|
|
|
{
|
|
|
|
const ArrayMV<int> *mv2 = dynamic_cast<const ArrayMV<int> *>(&mv);
|
|
|
|
if (mv2 == NULL)
|
|
|
|
throw TypeError("Expression inside [] must be an integer array");
|
|
|
|
string result;
|
2009-12-16 18:13:23 +01:00
|
|
|
for (vector<int>::const_iterator it = mv2->values.begin();
|
|
|
|
it != mv2->values.end(); it++)
|
2008-02-19 15:24:40 +01:00
|
|
|
{
|
2008-02-22 13:03:38 +01:00
|
|
|
if (*it < 1 || *it > (int) value.length())
|
|
|
|
throw OutOfBoundsError();
|
2008-02-19 15:24:40 +01:00
|
|
|
char c = value.at(*it - 1);
|
|
|
|
result.append(&c);
|
|
|
|
}
|
2008-02-29 17:21:01 +01:00
|
|
|
return new StringMV(driver, result);
|
2008-02-19 15:24:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-15 18:31:40 +01:00
|
|
|
string
|
|
|
|
StringMV::toString() const
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
2008-02-19 15:24:40 +01:00
|
|
|
StringMV::toArray() const
|
|
|
|
{
|
|
|
|
vector<string> v;
|
|
|
|
v.push_back(value);
|
2008-02-29 17:21:01 +01:00
|
|
|
return new ArrayMV<string>(driver, v);
|
2008-02-19 15:24:40 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 17:21:01 +01:00
|
|
|
const MacroValue *
|
|
|
|
StringMV::append(const MacroValue *array) const throw (TypeError)
|
2008-02-19 15:24:40 +01:00
|
|
|
{
|
2008-02-29 17:21:01 +01:00
|
|
|
const ArrayMV<string> *array2 = dynamic_cast<const ArrayMV<string> *>(array);
|
2008-02-19 15:24:40 +01:00
|
|
|
if (array2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for append operation");
|
2008-02-20 10:56:47 +01:00
|
|
|
|
|
|
|
vector<string> v(array2->values);
|
|
|
|
v.push_back(value);
|
2008-02-29 17:21:01 +01:00
|
|
|
return new ArrayMV<string>(driver, v);
|
2008-02-19 15:24:40 +01:00
|
|
|
}
|
2008-12-08 16:13:08 +01:00
|
|
|
|
|
|
|
const MacroValue *
|
|
|
|
StringMV::in(const MacroValue *array) const throw (TypeError)
|
|
|
|
{
|
|
|
|
const ArrayMV<string> *array2 = dynamic_cast<const ArrayMV<string> *>(array);
|
|
|
|
if (array2 == NULL)
|
|
|
|
throw TypeError("Type mismatch for 'in' operator");
|
|
|
|
|
|
|
|
int result = 0;
|
2009-12-16 18:13:23 +01:00
|
|
|
for (vector<string>::const_iterator it = array2->values.begin();
|
|
|
|
it != array2->values.end(); it++)
|
2008-12-08 16:13:08 +01:00
|
|
|
if (*it == value)
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new IntMV(driver, result);
|
|
|
|
}
|