Remove unnecessary inline specifiers

A function defined entirely inside a class/struct/union definition is
implicitly an inline function.
master
Sébastien Villemot 2022-06-24 15:08:49 +02:00
parent b307097f85
commit b390390a98
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
9 changed files with 190 additions and 138 deletions

View File

@ -36,7 +36,7 @@ public:
private:
map<string, string> hooks;
public:
inline map<string, string>
map<string, string>
get_hooks() const
{
return hooks;
@ -50,7 +50,7 @@ public:
private:
map<string, vector<string>> paths;
public:
inline map<string, vector<string>>
map<string, vector<string>>
get_paths() const
{
return paths;

View File

@ -363,13 +363,13 @@ public:
//! Tells whether Hessian has been computed
/*! This is needed to know whether no non-zero equation in Hessian means a
zero Hessian or Hessian not computed */
inline bool
bool
isHessianComputed() const
{
return computed_derivs_order >= 2;
}
//! Returns equations that have non-zero second derivatives
inline set<int>
set<int>
getNonZeroHessianEquations() const
{
return nonzero_hessian_eqs;
@ -505,13 +505,13 @@ public:
//! Transforms the model by removing trends specified by the user
void detrendEquations();
inline const nonstationary_symbols_map_t &
const nonstationary_symbols_map_t &
getNonstationarySymbolsMap() const
{
return nonstationary_symbols_map;
}
inline const map<int, expr_t> &
const map<int, expr_t> &
getTrendSymbolsMap() const
{
return trend_symbols_map;

View File

@ -42,7 +42,8 @@ public:
};
// Add multiple equation tags for the given equation
inline void add(int eqn, map<string, string> tags)
void
add(int eqn, map<string, string> tags)
{
if (eqn_tags.contains(eqn))
eqn_tags[eqn].insert(move_iterator{tags.begin()}, move_iterator{tags.end()});
@ -51,13 +52,15 @@ public:
}
//! Add a single equation tag for the given equation
inline void add(int eqn, string key, string value)
void
add(int eqn, string key, string value)
{
eqn_tags[eqn][move(key)] = move(value);
}
//! Clear all equation tag information
inline void clear()
void
clear()
{
eqn_tags.clear();
}
@ -68,7 +71,8 @@ public:
//! Various functions to get info from equation tags
//! Get equation tags for a given equation
inline map<string, string> getTagsByEqn(const int eqn) const
map<string, string>
getTagsByEqn(const int eqn) const
{
if (auto it = eqn_tags.find(eqn); it != eqn_tags.end())
return it->second;
@ -85,19 +89,22 @@ public:
int getEqnByTag(const string &key, const string &value) const;
//! Get the tag value given the equation number and key
inline string getTagValueByEqnAndKey(int eqn, const string &key) const
string
getTagValueByEqnAndKey(int eqn, const string &key) const
{
return exists(eqn, key) ? eqn_tags.at(eqn).at(key) : "";
}
//! Get the equations marked dynamic
inline set<int> getDynamicEqns() const
set<int>
getDynamicEqns() const
{
return getEqnsByTag("dynamic", "");
}
//! Returns true if equation tag with key and value exists
inline bool exists(const string &key, const string &value) const
bool
exists(const string &key, const string &value) const
{
try
{
@ -110,19 +117,22 @@ public:
return true;
}
inline bool exists(const int eqn) const
bool
exists(const int eqn) const
{
return eqn_tags.contains(eqn);
}
//! Returns true if equation tag with key exists for a given equation
inline bool exists(const int eqn, const string &key) const
bool
exists(const int eqn, const string &key) const
{
return exists(eqn) && eqn_tags.at(eqn).contains(key);
}
//! Returns true if equation tag with key and value exists for a given equation
inline bool exists(const int eqn, const string &key, const string &value) const
bool
exists(const int eqn, const string &key, const string &value) const
{
return exists(eqn, key) && eqn_tags.at(eqn).at(key) == value;
}

View File

@ -184,7 +184,11 @@ protected:
int max_exo_det_lag{0}, max_exo_det_lead{0};
int max_lag{0}, max_lead{0}; // The max over all endo/exo variables
inline int getRecursiveSize() const { return size - mfs_size; };
int
getRecursiveSize() const
{
return size - mfs_size;
};
};
// Stores various informations on the blocks
@ -453,34 +457,34 @@ public:
expr_t getRHSFromLHS(expr_t lhs) const;
//! Returns all the equation tags associated to an equation
inline map<string, string>
map<string, string>
getEquationTags(int eq) const
{
return equation_tags.getTagsByEqn(eq);
}
//! Returns the vector of non-zero derivative counts
inline const vector<int> &
const vector<int> &
getNNZDerivatives() const
{
return NNZDerivatives;
}
//! Returns the vector of temporary terms derivatives
inline const vector<temporary_terms_t> &
const vector<temporary_terms_t> &
getTemporaryTermsDerivatives() const
{
return temporary_terms_derivatives;
}
//!Returns the maximum order of computed derivatives
inline int
int
getComputedDerivsOrder() const
{
return computed_derivs_order;
}
inline static string
static string
BlockSim(BlockSimulationType type)
{
switch (type)

View File

@ -43,12 +43,12 @@ public:
friend WarningConsolidation &operator<<(WarningConsolidation &wcc, const Dynare::location &loc);
friend WarningConsolidation &operator<<(WarningConsolidation &wcc, ostream &(*pf)(ostream &));
inline void
void
addWarning(const string &w)
{
warnings << w;
};
inline void
void
addWarning(ostream &(*pf)(ostream &))
{
warnings << pf;

View File

@ -47,7 +47,11 @@ namespace macro
public:
TextNode(string text_arg, Tokenizer::location location_arg) :
Directive(move(location_arg)), text{move(text_arg)} { }
inline void interpret(ostream &output, Environment &env, vector<filesystem::path> &paths) override { output << text; }
void
interpret(ostream &output, Environment &env, vector<filesystem::path> &paths) override
{
output << text;
}
};

View File

@ -96,31 +96,31 @@ namespace macro
//! Error handler
void error(const Tokenizer::parser::location_type &location, const string &message) const;
inline bool
bool
inContext() const
{
return !directive_stack.empty();
}
inline void
void
pushContext()
{
directive_stack.emplace(vector<DirectivePtr>());
}
inline void
void
pushContextTop(DirectivePtr statement)
{
directive_stack.top().emplace_back(move(statement));
}
inline void
void
pushStatements(DirectivePtr statement)
{
statements.emplace_back(move(statement));
}
inline vector<DirectivePtr>
vector<DirectivePtr>
popContext()
{
auto top = move(directive_stack.top());

View File

@ -44,12 +44,23 @@ namespace macro
codes::BaseType getType(const string &name) const;
bool isVariableDefined(const string &name) const noexcept;
bool isFunctionDefined(const string &name) const noexcept;
inline bool isSymbolDefined(const string &name) const noexcept { return isVariableDefined(name) || isFunctionDefined(name); }
bool isSymbolDefined(const string &name) const noexcept
{
return isVariableDefined(name) || isFunctionDefined(name);
}
void print(ostream &output, const vector<string> &vars, const optional<int> &line = nullopt, bool save = false) const;
void printVariable(ostream &output, const string &name, const optional<int> &line, bool save) const;
void printFunction(ostream &output, const tuple<FunctionPtr, ExpressionPtr> &function, const optional<int> &line, bool save) const;
inline size_t size() const noexcept { return variables.size() + functions.size(); }
inline const Environment *getGlobalEnv() const noexcept { return parent == nullptr ? this : parent->getGlobalEnv(); }
size_t
size() const noexcept
{
return variables.size() + functions.size();
}
const Environment *
getGlobalEnv() const noexcept
{
return parent == nullptr ? this : parent->getGlobalEnv();
}
};
}
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2019-2020 Dynare Team
* Copyright © 2019-2022 Dynare Team
*
* This file is part of Dynare.
*
@ -87,21 +87,25 @@ namespace macro
location{move(location_arg)} { }
virtual ~Node() = default;
public:
inline Tokenizer::location getLocation() const noexcept { return location; }
inline void error(const StackTrace &e) const noexcept
Tokenizer::location getLocation() const noexcept { return location; }
void
error(const StackTrace &e) const noexcept
{
cerr << endl << "Macro-processing error: backtrace..." << endl << e.trace();
exit(EXIT_FAILURE);
}
inline void warning(const StackTrace &e) const noexcept
void
warning(const StackTrace &e) const noexcept
{
cerr << endl << "Macro-processing warning: backtrace..." << endl << e.trace();
}
inline void printLineInfo(ostream &output) const noexcept
void
printLineInfo(ostream &output) const noexcept
{
output << R"(@#line ")" << *(location.begin.filename) << R"(" )" << location.begin.line << endl;
}
inline void printEndLineInfo(ostream &output) const noexcept
void
printEndLineInfo(ostream &output) const noexcept
{
// Add one to end line because we want to print the line number of the line *following* the end statement
output << R"(@#line ")" << *(location.begin.filename) << R"(" )" << location.end.line + 1 << endl;
@ -127,7 +131,7 @@ namespace macro
explicit BaseType(Tokenizer::location location_arg = Tokenizer::location()) :
Expression(move(location_arg)) { }
virtual codes::BaseType getType() const noexcept = 0;
inline BaseTypePtr eval(Environment &env) override { return shared_from_this(); }
BaseTypePtr eval(Environment &env) override { return shared_from_this(); }
public:
virtual BaseTypePtr plus(const BaseTypePtr &bt) const { throw StackTrace("Operator + does not exist for this type"); }
virtual BaseTypePtr unary_plus() const { throw StackTrace("Unary operator + does not exist for this type"); }
@ -206,25 +210,27 @@ namespace macro
Tokenizer::location location_arg = Tokenizer::location()) :
BaseType(move(location_arg)),
value{value_arg} { }
inline codes::BaseType getType() const noexcept override { return codes::BaseType::Bool; }
inline string to_string() const noexcept override { return value ? "true" : "false"; }
inline void print(ostream &output, bool matlab_output = false) const noexcept override { output << to_string(); }
inline ExpressionPtr clone() const noexcept override { return make_shared<Bool>(value, location); }
codes::BaseType getType() const noexcept override { return codes::BaseType::Bool; }
string to_string() const noexcept override { return value ? "true" : "false"; }
void print(ostream &output, bool matlab_output = false) const noexcept override { output << to_string(); }
ExpressionPtr clone() const noexcept override { return make_shared<Bool>(value, location); }
public:
operator bool() const { return value; }
BoolPtr is_equal(const BaseTypePtr &btp) const override;
BoolPtr logical_and(const ExpressionPtr &ep, Environment &env) const override;
BoolPtr logical_or(const ExpressionPtr &ep, Environment &env) const override;
BoolPtr logical_not() const override;
inline BoolPtr isboolean() const noexcept override { return make_shared<Bool>(true, location); }
inline BoolPtr cast_bool(Environment &env) const override { return make_shared<Bool>(value); }
inline RealPtr cast_real(Environment &env) const override { return value ? make_shared<Real>(1) : make_shared<Real>(0); }
inline StringPtr cast_string() const override { return make_shared<String>(this->to_string()); }
inline TuplePtr cast_tuple() const override
BoolPtr isboolean() const noexcept override { return make_shared<Bool>(true, location); }
BoolPtr cast_bool(Environment &env) const override { return make_shared<Bool>(value); }
RealPtr cast_real(Environment &env) const override { return value ? make_shared<Real>(1) : make_shared<Real>(0); }
StringPtr cast_string() const override { return make_shared<String>(this->to_string()); }
TuplePtr
cast_tuple() const override
{
return make_shared<Tuple>(vector<ExpressionPtr>{make_shared<Bool>(value)});
}
inline ArrayPtr cast_array() const override
ArrayPtr
cast_array() const override
{
return make_shared<Array>(vector<ExpressionPtr>{make_shared<Bool>(value)});
}
@ -246,21 +252,22 @@ namespace macro
Tokenizer::location location_arg = Tokenizer::location()) :
BaseType(move(location_arg)),
value{value_arg} { }
inline codes::BaseType getType() const noexcept override { return codes::BaseType::Real; }
inline string to_string() const noexcept override
codes::BaseType getType() const noexcept override { return codes::BaseType::Real; }
string
to_string() const noexcept override
{
ostringstream strs;
strs << setprecision(15) << value;
return strs.str();
}
inline void print(ostream &output, bool matlab_output = false) const noexcept override { output << to_string(); }
inline ExpressionPtr clone() const noexcept override { return make_shared<Real>(value, location); }
void print(ostream &output, bool matlab_output = false) const noexcept override { output << to_string(); }
ExpressionPtr clone() const noexcept override { return make_shared<Real>(value, location); }
public:
operator double() const { return value; }
BaseTypePtr plus(const BaseTypePtr &bt) const override;
inline BaseTypePtr unary_plus() const override { return make_shared<Real>(value); }
BaseTypePtr unary_plus() const override { return make_shared<Real>(value); }
BaseTypePtr minus(const BaseTypePtr &bt) const override;
inline BaseTypePtr unary_minus() const override { return make_shared<Real>(-value); }
BaseTypePtr unary_minus() const override { return make_shared<Real>(-value); }
BaseTypePtr times(const BaseTypePtr &bt) const override;
BaseTypePtr divide(const BaseTypePtr &bt) const override;
BaseTypePtr power(const BaseTypePtr &btp) const override;
@ -269,8 +276,8 @@ namespace macro
BoolPtr is_less_equal(const BaseTypePtr &btp) const override;
BoolPtr is_greater_equal(const BaseTypePtr &btp) const override;
BoolPtr is_equal(const BaseTypePtr &btp) const override;
inline BoolPtr isreal() const noexcept override { return make_shared<Bool>(true, location); }
inline BoolPtr isinteger() const noexcept override
BoolPtr isreal() const noexcept override { return make_shared<Bool>(true, location); }
BoolPtr isinteger() const noexcept override
{
double intpart;
return make_shared<Bool>(modf(value, &intpart) == 0.0, location);
@ -281,51 +288,56 @@ namespace macro
RealPtr max(const BaseTypePtr &btp) const override;
RealPtr min(const BaseTypePtr &btp) const override;
RealPtr mod(const BaseTypePtr &btp) const override;
inline RealPtr exp() const override { return make_shared<Real>(std::exp(value)); }
inline RealPtr ln() const override { return make_shared<Real>(std::log(value)); }
inline RealPtr log10() const override { return make_shared<Real>(std::log10(value)); }
inline BoolPtr isinf() const override { return make_shared<Bool>(std::isinf(value)); }
inline BoolPtr isnan() const override { return make_shared<Bool>(std::isnan(value)); }
inline BoolPtr isfinite() const override { return make_shared<Bool>(std::isfinite(value)); }
inline BoolPtr isnormal() const override { return make_shared<Bool>(std::isnormal(value)); }
inline RealPtr sin() const override { return make_shared<Real>(std::sin(value)); }
inline RealPtr cos() const override { return make_shared<Real>(std::cos(value)); }
inline RealPtr tan() const override { return make_shared<Real>(std::tan(value)); }
inline RealPtr asin() const override { return make_shared<Real>(std::asin(value)); }
inline RealPtr acos() const override { return make_shared<Real>(std::acos(value)); }
inline RealPtr atan() const override { return make_shared<Real>(std::atan(value)); }
inline RealPtr sqrt() const override { return make_shared<Real>(std::sqrt(value)); }
inline RealPtr cbrt() const override { return make_shared<Real>(std::cbrt(value)); }
inline RealPtr sign() const override
RealPtr exp() const override { return make_shared<Real>(std::exp(value)); }
RealPtr ln() const override { return make_shared<Real>(std::log(value)); }
RealPtr log10() const override { return make_shared<Real>(std::log10(value)); }
BoolPtr isinf() const override { return make_shared<Bool>(std::isinf(value)); }
BoolPtr isnan() const override { return make_shared<Bool>(std::isnan(value)); }
BoolPtr isfinite() const override { return make_shared<Bool>(std::isfinite(value)); }
BoolPtr isnormal() const override { return make_shared<Bool>(std::isnormal(value)); }
RealPtr sin() const override { return make_shared<Real>(std::sin(value)); }
RealPtr cos() const override { return make_shared<Real>(std::cos(value)); }
RealPtr tan() const override { return make_shared<Real>(std::tan(value)); }
RealPtr asin() const override { return make_shared<Real>(std::asin(value)); }
RealPtr acos() const override { return make_shared<Real>(std::acos(value)); }
RealPtr atan() const override { return make_shared<Real>(std::atan(value)); }
RealPtr sqrt() const override { return make_shared<Real>(std::sqrt(value)); }
RealPtr cbrt() const override { return make_shared<Real>(std::cbrt(value)); }
RealPtr
sign() const override
{
return make_shared<Real>((value > 0) ? 1. : ((value < 0) ? -1. : 0.));
}
inline RealPtr floor() const override { return make_shared<Real>(std::floor(value)); }
inline RealPtr ceil() const override { return make_shared<Real>(std::ceil(value)); }
inline RealPtr trunc() const override { return make_shared<Real>(std::trunc(value)); }
inline RealPtr erf() const override { return make_shared<Real>(std::erf(value)); }
inline RealPtr erfc() const override { return make_shared<Real>(std::erfc(value)); }
inline RealPtr gamma() const override { return make_shared<Real>(std::tgamma(value)); }
inline RealPtr lgamma() const override { return make_shared<Real>(std::lgamma(value)); }
inline RealPtr round() const override { return make_shared<Real>(std::round(value)); }
inline RealPtr normpdf() const override
RealPtr floor() const override { return make_shared<Real>(std::floor(value)); }
RealPtr ceil() const override { return make_shared<Real>(std::ceil(value)); }
RealPtr trunc() const override { return make_shared<Real>(std::trunc(value)); }
RealPtr erf() const override { return make_shared<Real>(std::erf(value)); }
RealPtr erfc() const override { return make_shared<Real>(std::erfc(value)); }
RealPtr gamma() const override { return make_shared<Real>(std::tgamma(value)); }
RealPtr lgamma() const override { return make_shared<Real>(std::lgamma(value)); }
RealPtr round() const override { return make_shared<Real>(std::round(value)); }
RealPtr
normpdf() const override
{
return normpdf(make_shared<Real>(0), make_shared<Real>(1));
}
RealPtr normpdf(const BaseTypePtr &btp1, const BaseTypePtr &btp2) const override;
inline RealPtr normcdf() const override
RealPtr
normcdf() const override
{
return normcdf(make_shared<Real>(0), make_shared<Real>(1));
}
RealPtr normcdf(const BaseTypePtr &btp1, const BaseTypePtr &btp2) const override;
inline BoolPtr cast_bool(Environment &env) const override { return make_shared<Bool>(static_cast<bool>(value)); }
inline RealPtr cast_real(Environment &env) const override { return make_shared<Real>(value); }
inline StringPtr cast_string() const override { return make_shared<String>(this->to_string()); }
inline TuplePtr cast_tuple() const override
BoolPtr cast_bool(Environment &env) const override { return make_shared<Bool>(static_cast<bool>(value)); }
RealPtr cast_real(Environment &env) const override { return make_shared<Real>(value); }
StringPtr cast_string() const override { return make_shared<String>(this->to_string()); }
TuplePtr
cast_tuple() const override
{
return make_shared<Tuple>(vector<ExpressionPtr>{make_shared<Real>(value)});
}
inline ArrayPtr cast_array() const override
ArrayPtr
cast_array() const override
{
return make_shared<Array>(vector<ExpressionPtr>{make_shared<Real>(value)});
}
@ -340,10 +352,10 @@ namespace macro
Tokenizer::location location_arg = Tokenizer::location()) :
BaseType(move(location_arg)),
value{move(value_arg)} { }
inline codes::BaseType getType() const noexcept override { return codes::BaseType::String; }
inline string to_string() const noexcept override { return value; }
codes::BaseType getType() const noexcept override { return codes::BaseType::String; }
string to_string() const noexcept override { return value; }
void print(ostream &output, bool matlab_output = false) const noexcept override;
inline ExpressionPtr clone() const noexcept override { return make_shared<String>(value, location); }
ExpressionPtr clone() const noexcept override { return make_shared<String>(value, location); }
public:
operator string() const { return value; }
BaseTypePtr plus(const BaseTypePtr &bt) const override;
@ -352,21 +364,24 @@ namespace macro
BoolPtr is_less_equal(const BaseTypePtr &btp) const override;
BoolPtr is_greater_equal(const BaseTypePtr &btp) const override;
BoolPtr is_equal(const BaseTypePtr &btp) const override;
inline BoolPtr isstring() const noexcept override { return make_shared<Bool>(true, location); }
inline RealPtr length() const override { return make_shared<Real>(value.size()); }
inline BoolPtr isempty() const override { return make_shared<Bool>(value.empty()); }
BoolPtr isstring() const noexcept override { return make_shared<Bool>(true, location); }
RealPtr length() const override { return make_shared<Real>(value.size()); }
BoolPtr isempty() const override { return make_shared<Bool>(value.empty()); }
BoolPtr cast_bool(Environment &env) const override;
RealPtr cast_real(Environment &env) const override;
inline StringPtr cast_string() const override { return make_shared<String>(value); }
inline TuplePtr cast_tuple() const override
StringPtr cast_string() const override { return make_shared<String>(value); }
TuplePtr
cast_tuple() const override
{
return make_shared<Tuple>(vector<ExpressionPtr>{make_shared<String>(value)});
}
inline ArrayPtr cast_array() const override
ArrayPtr
cast_array() const override
{
return make_shared<Array>(vector<ExpressionPtr>{make_shared<String>(value)});
}
inline BoolPtr defined(const Environment &env) const override
BoolPtr
defined(const Environment &env) const override
{
return make_shared<Bool>(env.isSymbolDefined(value));
}
@ -382,26 +397,26 @@ namespace macro
Tokenizer::location location_arg = Tokenizer::location()) :
BaseType(move(location_arg)),
tup{move(tup_arg)} { }
inline codes::BaseType getType() const noexcept override { return codes::BaseType::Tuple; }
codes::BaseType getType() const noexcept override { return codes::BaseType::Tuple; }
string to_string() const noexcept override;
void print(ostream &output, bool matlab_output = false) const noexcept override;
BaseTypePtr eval(Environment &env) override;
ExpressionPtr clone() const noexcept override;
public:
inline size_t size() const { return tup.size(); }
inline bool empty() const { return tup.empty(); }
inline const vector<ExpressionPtr> &getValue() const { return tup; }
inline const ExpressionPtr &at(int i) const { return tup.at(i); }
size_t size() const { return tup.size(); }
bool empty() const { return tup.empty(); }
const vector<ExpressionPtr> &getValue() const { return tup; }
const ExpressionPtr &at(int i) const { return tup.at(i); }
BoolPtr is_equal(const BaseTypePtr &btp) const override;
inline BoolPtr istuple() const noexcept override { return make_shared<Bool>(true, location); }
BoolPtr istuple() const noexcept override { return make_shared<Bool>(true, location); }
BoolPtr contains(const BaseTypePtr &btp) const override;
inline RealPtr length() const override { return make_shared<Real>(tup.size()); }
inline BoolPtr isempty() const override { return make_shared<Bool>(empty()); }
RealPtr length() const override { return make_shared<Real>(tup.size()); }
BoolPtr isempty() const override { return make_shared<Bool>(empty()); }
BoolPtr cast_bool(Environment &env) const override;
RealPtr cast_real(Environment &env) const override;
inline StringPtr cast_string() const override { return make_shared<String>(this->to_string()); }
inline TuplePtr cast_tuple() const override { return make_shared<Tuple>(tup); }
inline ArrayPtr cast_array() const override { return make_shared<Array>(tup); }
StringPtr cast_string() const override { return make_shared<String>(this->to_string()); }
TuplePtr cast_tuple() const override { return make_shared<Tuple>(tup); }
ArrayPtr cast_array() const override { return make_shared<Array>(tup); }
};
@ -413,33 +428,33 @@ namespace macro
Array(vector<ExpressionPtr> arr_arg,
Tokenizer::location location_arg = Tokenizer::location()) :
BaseType(move(location_arg)), arr{move(arr_arg)} { }
inline codes::BaseType getType() const noexcept override { return codes::BaseType::Array; }
codes::BaseType getType() const noexcept override { return codes::BaseType::Array; }
string to_string() const noexcept override;
void print(ostream &output, bool matlab_output = false) const noexcept override;
BaseTypePtr eval(Environment &env) override;
ExpressionPtr clone() const noexcept override;
public:
inline size_t size() const { return arr.size(); }
inline const vector<ExpressionPtr> &getValue() const { return arr; }
inline const ExpressionPtr &at(int i) const { return arr.at(i); }
inline bool empty() const { return arr.empty(); }
size_t size() const { return arr.size(); }
const vector<ExpressionPtr> &getValue() const { return arr; }
const ExpressionPtr &at(int i) const { return arr.at(i); }
bool empty() const { return arr.empty(); }
BaseTypePtr plus(const BaseTypePtr &bt) const override;
BaseTypePtr minus(const BaseTypePtr &bt) const override;
BaseTypePtr times(const BaseTypePtr &bt) const override;
BaseTypePtr power(const BaseTypePtr &btp) const override;
BoolPtr is_equal(const BaseTypePtr &btp) const override;
inline BoolPtr isarray() const noexcept override { return make_shared<Bool>(true, location); }
BoolPtr isarray() const noexcept override { return make_shared<Bool>(true, location); }
ArrayPtr set_union(const BaseTypePtr &btp) const override;
ArrayPtr set_intersection(const BaseTypePtr &btp) const override;
BoolPtr contains(const BaseTypePtr &btp) const override;
inline RealPtr length() const override { return make_shared<Real>(arr.size()); }
inline BoolPtr isempty() const override { return make_shared<Bool>(empty()); }
RealPtr length() const override { return make_shared<Real>(arr.size()); }
BoolPtr isempty() const override { return make_shared<Bool>(empty()); }
RealPtr sum() const override;
BoolPtr cast_bool(Environment &env) const override;
RealPtr cast_real(Environment &env) const override;
inline StringPtr cast_string() const override { return make_shared<String>(this->to_string()); }
inline TuplePtr cast_tuple() const override { return make_shared<Tuple>(arr); }
inline ArrayPtr cast_array() const override { return make_shared<Array>(arr); }
StringPtr cast_string() const override { return make_shared<String>(this->to_string()); }
TuplePtr cast_tuple() const override { return make_shared<Tuple>(arr); }
ArrayPtr cast_array() const override { return make_shared<Array>(arr); }
};
@ -455,24 +470,27 @@ namespace macro
Tokenizer::location location_arg) :
BaseType(move(location_arg)),
start{move(start_arg)}, inc{move(inc_arg)}, end{move(end_arg)} { }
inline codes::BaseType getType() const noexcept override { return codes::BaseType::Range; }
inline string to_string() const noexcept override
codes::BaseType getType() const noexcept override { return codes::BaseType::Range; }
string
to_string() const noexcept override
{
string retval = "[" + start->to_string() + ":";
if (inc)
retval += inc->to_string() + ":";
return retval + end->to_string() + "]";
}
inline void print(ostream &output, bool matlab_output = false) const noexcept override { output << to_string(); }
void print(ostream &output, bool matlab_output = false) const noexcept override { output << to_string(); }
BaseTypePtr eval(Environment &env) override;
inline ExpressionPtr clone() const noexcept override
ExpressionPtr
clone() const noexcept override
{
return inc ?
make_shared<Range>(start, inc, end, location)
: make_shared<Range>(start, end, location);
}
public:
inline BoolPtr is_equal(const BaseTypePtr &btp) const override
BoolPtr
is_equal(const BaseTypePtr &btp) const override
{
throw StackTrace("Internal error: Range: Should not arrive here: is_equal");
}
@ -491,17 +509,18 @@ namespace macro
Variable(string name_arg, ArrayPtr indices_arg,
Tokenizer::location location_arg) :
Expression(move(location_arg)), name{move(name_arg)}, indices{move(indices_arg)} { }
inline string to_string() const noexcept override { return name; }
inline void print(ostream &output, bool matlab_output = false) const noexcept override { output << name; }
string to_string() const noexcept override { return name; }
void print(ostream &output, bool matlab_output = false) const noexcept override { output << name; }
BaseTypePtr eval(Environment &env) override;
inline ExpressionPtr clone() const noexcept override
ExpressionPtr
clone() const noexcept override
{
return indices ? make_shared<Variable>(name, indices, location) :
make_shared<Variable>(name, location);
}
public:
inline const string &getName() const noexcept { return name; }
inline codes::BaseType getType(const Environment &env) const { return env.getType(name); }
const string &getName() const noexcept { return name; }
codes::BaseType getType(const Environment &env) const { return env.getType(name); }
};
@ -516,17 +535,18 @@ namespace macro
Tokenizer::location location_arg) :
Expression(move(location_arg)), name{move(name_arg)}, args{move(args_arg)} { }
string to_string() const noexcept override;
inline void print(ostream &output, bool matlab_output = false) const noexcept override
void
print(ostream &output, bool matlab_output = false) const noexcept override
{
printName(output); printArgs(output);
}
BaseTypePtr eval(Environment &env) override;
ExpressionPtr clone() const noexcept override;
public:
inline void printName(ostream &output) const noexcept { output << name; }
void printName(ostream &output) const noexcept { output << name; }
void printArgs(ostream &output) const noexcept;
inline const string &getName() const { return name; }
inline const vector<ExpressionPtr> &getArgs() const { return args; }
const string &getName() const { return name; }
const vector<ExpressionPtr> &getArgs() const { return args; }
};
@ -543,7 +563,8 @@ namespace macro
string to_string() const noexcept override;
void print(ostream &output, bool matlab_output = false) const noexcept override;
BaseTypePtr eval(Environment &env) override;
inline ExpressionPtr clone() const noexcept override
ExpressionPtr
clone() const noexcept override
{
return make_shared<UnaryOp>(op_code, arg->clone(), location);
}
@ -565,7 +586,8 @@ namespace macro
string to_string() const noexcept override;
void print(ostream &output, bool matlab_output = false) const noexcept override;
BaseTypePtr eval(Environment &env) override;
inline ExpressionPtr clone() const noexcept override
ExpressionPtr
clone() const noexcept override
{
return make_shared<BinaryOp>(op_code, arg1->clone(), arg2->clone(), location);
}
@ -586,7 +608,8 @@ namespace macro
string to_string() const noexcept override;
void print(ostream &output, bool matlab_output = false) const noexcept override;
BaseTypePtr eval(Environment &env) override;
inline ExpressionPtr clone() const noexcept override
ExpressionPtr
clone() const noexcept override
{
return make_shared<TrinaryOp>(op_code, arg1->clone(), arg2->clone(), arg3->clone(), location);
}