Skip to content

Commit

Permalink
Implemented unary minus. Nuked some compiler warnings.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@731 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
ankar committed Feb 13, 2002
1 parent 5fd7b2b commit a6555b2
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 21 deletions.
7 changes: 0 additions & 7 deletions mosh/src/modelica_type.cpp
Expand Up @@ -339,10 +339,3 @@ ostream& operator<< (ostream& o, const modelica_type& v)
return o;
}

ostream& modelica_type::print_dims(ostream& o)
{
for (int i = 0; i < m_dimensions.size();++i)
{
o << "dimensions[" << i << "] : " << m_dimensions[i];
}
}
1 change: 0 additions & 1 deletion mosh/src/modelica_type.hpp
Expand Up @@ -76,7 +76,6 @@ class modelica_type

type_en m_type;

ostream& print_dims(ostream& o);
};

#endif
2 changes: 1 addition & 1 deletion mosh/src/mosh.cpp
Expand Up @@ -86,7 +86,7 @@ void read_and_evaluate(istream& instream)

antlr::RefAST ast = parser.getAST();

parse_tree_dumper dumper(std::cout);
// parse_tree_dumper dumper(std::cout);

if (ast)
{
Expand Down
18 changes: 16 additions & 2 deletions mosh/src/runtime/numerical_array.hpp
Expand Up @@ -34,6 +34,8 @@ class numerical_array : public modelica_array<Tp>
const numerical_array<Tp>& operator-= (const numerical_array<Tp>& arr);
numerical_array<Tp> operator-(const numerical_array<Tp>& arr) const;

numerical_array<Tp> operator- () const;

numerical_array() {};
numerical_array(std::vector<int> dims) : modelica_array<Tp>(dims) {};
numerical_array(std::vector<int> dims,std::vector<Tp> scalars) : modelica_array<Tp>(dims,scalars) {};
Expand Down Expand Up @@ -89,7 +91,7 @@ const numerical_array<Tp>& numerical_array<Tp>::operator+= (const numerical_arra
{
assert(m_dim_size == arr.m_dim_size);

for (int i = 0; i < m_data.size(); ++i)
for (size_t i = 0; i < m_data.size(); ++i)
{
m_data[i] += arr.m_data[i];
}
Expand All @@ -110,7 +112,7 @@ const numerical_array<Tp>& numerical_array<Tp>::operator-= (const numerical_arra
{
assert(m_dim_size == arr.m_dim_size);

for (int i = 0; i < m_data.size(); ++i)
for (size_t i = 0; i < m_data.size(); ++i)
{
m_data[i] -= arr.m_data[i];
}
Expand All @@ -125,6 +127,18 @@ numerical_array<Tp> numerical_array<Tp>::operator-(const numerical_array<Tp>& ar
tmp -= arr;
return tmp;
}

template<typename Tp>
numerical_array<Tp> numerical_array<Tp>::operator- () const
{
numerical_array<Tp> tmp(*this);
for (size_t i = 0; i < m_data.size(); ++i)
{
tmp.m_data[i] = -m_data[i];
}
return tmp;
}

// typedef numerical_array<double> real_array;
// typedef numerical_array<int> integer_array;

Expand Down
38 changes: 30 additions & 8 deletions mosh/src/value.cpp
Expand Up @@ -451,7 +451,7 @@ const value& value::operator+= (const value& val)
}
else
{
throw modelica_runtime_error("Types does not match\n");
throw modelica_runtime_error("Types do not match\n");
}

return *this;
Expand Down Expand Up @@ -498,7 +498,7 @@ const value& value::operator-= (const value& val)
}
else
{
throw modelica_runtime_error("Adding non-numerical value\n");
throw modelica_runtime_error("Types do not match\n");
}

// if (val.is_array() || is_array())
Expand Down Expand Up @@ -607,21 +607,43 @@ double value::to_double() const

value value::operator-() const
{
if (!is_numeric())
if (!is_numeric())
{
throw modelica_runtime_error("unary minus on non-numerical value\n");
}

value tmp(*this);
value tmp(*this);

if (is_integer())
if (is_real_array())
{
tmp.m_real_array = - m_real_array;
}
else if (is_integer_array())
{
tmp.m_integer = - m_integer;
tmp.m_integer_array = - m_integer_array;
}
else
else if (is_real())
{
tmp.m_real = - m_real;
}
else if (is_integer())
{
tmp.m_real = - m_real;
tmp.m_integer = - m_integer;
}
else
{
throw modelica_runtime_error("Internal error in value +=");
}

return tmp;
// if (is_integer())
// {
// tmp.m_integer = - m_integer;
// }
// else
// {
// tmp.m_real = - m_real;
// }

return tmp;
}
Expand Down
4 changes: 2 additions & 2 deletions mosh/src/walker.g
Expand Up @@ -1188,7 +1188,7 @@ expression_list_array returns [value val]
{
if (exp_list[0].is_real())
{
for (int i=0; i < exp_list.size();++i)
for (size_t i=0; i < exp_list.size();++i)
{
tmp_real.push_back(exp_list[i].get_real());
}
Expand All @@ -1198,7 +1198,7 @@ expression_list_array returns [value val]
}
else if (exp_list[0].is_integer())
{
for (int i=0; i < exp_list.size();++i)
for (size_t i=0; i < exp_list.size();++i)
{
tmp_integer.push_back(exp_list[i].get_integer());
}
Expand Down

0 comments on commit a6555b2

Please sign in to comment.