diff --git a/src/macro/Directives.hh b/src/macro/Directives.hh index d9b26d4e..943bc6d4 100644 --- a/src/macro/Directives.hh +++ b/src/macro/Directives.hh @@ -30,13 +30,13 @@ namespace macro { // A Parent class just for clarity public: - Directive(Environment &env_arg, Tokenizer::location location_arg) : Node(env_arg, move(location_arg)) - { - } + Directive(Environment &env_arg, Tokenizer::location location_arg) : + Node(env_arg, move(location_arg)) { } // Directives can be interpreted virtual void interpret(ostream &output, bool no_line_macro, vector &paths) = 0; }; + class TextNode : public Directive { // Class for text not interpreted by macroprocessor @@ -46,16 +46,11 @@ namespace macro const string text; public: TextNode(string text_arg, Environment &env_arg, Tokenizer::location location_arg) : - Directive(env_arg, move(location_arg)), text{move(text_arg)} - { - } - inline void - interpret(ostream &output, bool no_line_macro, vector &paths) override - { - output << text; - } + Directive(env_arg, move(location_arg)), text{move(text_arg)} { } + inline void interpret(ostream &output, bool no_line_macro, vector &paths) override { output << text; } }; + class Eval : public Directive { // Class for @{} statements @@ -65,36 +60,33 @@ namespace macro const ExpressionPtr expr; public: Eval(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) : - Directive(env_arg, move(location_arg)), expr{move(expr_arg)} - { - } + Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { } void interpret(ostream &output, bool no_line_macro, vector &paths) override; }; + class Include : public Directive { private: const ExpressionPtr expr; public: Include(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) : - Directive(env_arg, move(location_arg)), expr{move(expr_arg)} - { - } + Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { } void interpret(ostream &output, bool no_line_macro, vector &paths) override; }; + class IncludePath : public Directive { private: const ExpressionPtr expr; public: IncludePath(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) : - Directive(env_arg, move(location_arg)), expr{move(expr_arg)} - { - } + Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { } void interpret(ostream &output, bool no_line_macro, vector &paths) override; }; + class Define : public Directive { private: @@ -105,18 +97,15 @@ namespace macro Define(VariablePtr var_arg, ExpressionPtr value_arg, Environment &env_arg, Tokenizer::location location_arg) : - Directive(env_arg, move(location_arg)), var{move(var_arg)}, value{move(value_arg)} - { - } + Directive(env_arg, move(location_arg)), var{move(var_arg)}, value{move(value_arg)} { } Define(FunctionPtr func_arg, ExpressionPtr value_arg, Environment &env_arg, Tokenizer::location location_arg) : - Directive(env_arg, move(location_arg)), func{move(func_arg)}, value{move(value_arg)} - { - } + Directive(env_arg, move(location_arg)), func{move(func_arg)}, value{move(value_arg)} { } void interpret(ostream &output, bool no_line_macro, vector &paths) override; }; + class Echo : public Directive { private: @@ -124,12 +113,11 @@ namespace macro public: Echo(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) : - Directive(env_arg, move(location_arg)), expr{move(expr_arg)} - { - } + Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { } void interpret(ostream &output, bool no_line_macro, vector &paths) override; }; + class Error : public Directive { private: @@ -137,12 +125,11 @@ namespace macro public: Error(ExpressionPtr expr_arg, Environment &env_arg, Tokenizer::location location_arg) : - Directive(env_arg, move(location_arg)), expr{move(expr_arg)} - { - } + Directive(env_arg, move(location_arg)), expr{move(expr_arg)} { } void interpret(ostream &output, bool no_line_macro, vector &paths) override; }; + class EchoMacroVars : public Directive { private: @@ -151,17 +138,14 @@ namespace macro public: EchoMacroVars(bool save_arg, Environment &env_arg, Tokenizer::location location_arg) : - Directive(env_arg, move(location_arg)), save{save_arg} - { - } + Directive(env_arg, move(location_arg)), save{save_arg} { } EchoMacroVars(bool save_arg, vector vars_arg, Environment &env_arg, Tokenizer::location location_arg) : - Directive(env_arg, move(location_arg)), save{save_arg}, vars{move(vars_arg)} - { - } + Directive(env_arg, move(location_arg)), save{save_arg}, vars{move(vars_arg)} { } void interpret(ostream &output, bool no_line_macro, vector &paths) override; }; + class For : public Directive { private: @@ -174,12 +158,11 @@ namespace macro vector statements_arg, Environment &env_arg, Tokenizer::location location_arg) : Directive(env_arg, move(location_arg)), index_vec{move(index_vec_arg)}, - index_vals{move(index_vals_arg)}, statements{move(statements_arg)} - { - } + index_vals{move(index_vals_arg)}, statements{move(statements_arg)} { } void interpret(ostream &output, bool no_line_macro, vector &paths) override; }; + class If : public Directive { protected: @@ -195,33 +178,29 @@ namespace macro public: If(vector>> expr_and_body_arg, Environment &env_arg, Tokenizer::location location_arg) : - Directive(env_arg, move(location_arg)), expr_and_body{move(expr_and_body_arg)} - { - } + Directive(env_arg, move(location_arg)), expr_and_body{move(expr_and_body_arg)} { } void interpret(ostream &output, bool no_line_macro, vector &paths) override; protected: void interpretBody(const vector &body, ostream &output, bool no_line_macro, vector &paths); }; + class Ifdef : public If { public: Ifdef(vector>> expr_and_body_arg, Environment &env_arg, Tokenizer::location location_arg) : - If(move(expr_and_body_arg), env_arg, move(location_arg)) - { - } + If(move(expr_and_body_arg), env_arg, move(location_arg)) { } void interpret(ostream &output, bool no_line_macro, vector &paths) override; }; + class Ifndef : public If { public: Ifndef(vector>> expr_and_body_arg, Environment &env_arg, Tokenizer::location location_arg) : - If(move(expr_and_body_arg), env_arg, move(location_arg)) - { - } + If(move(expr_and_body_arg), env_arg, move(location_arg)) { } void interpret(ostream &output, bool no_line_macro, vector &paths) override; }; } diff --git a/src/macro/Driver.hh b/src/macro/Driver.hh index c0aaa71f..ad85494f 100644 --- a/src/macro/Driver.hh +++ b/src/macro/Driver.hh @@ -46,9 +46,7 @@ namespace macro class TokenizerFlex : public TokenizerFlexLexer { public: - TokenizerFlex(istream *in) : TokenizerFlexLexer{in} - { - } + TokenizerFlex(istream *in) : TokenizerFlexLexer{in} { } TokenizerFlex(const TokenizerFlex &) = delete; TokenizerFlex(TokenizerFlex &&) = delete; TokenizerFlex &operator=(const TokenizerFlex &) = delete; @@ -71,9 +69,7 @@ namespace macro stack> directive_stack; public: Driver(Environment &env_arg, bool no_line_macro_arg) : - env{env_arg}, no_line_macro(no_line_macro_arg) - { - } + env{env_arg}, no_line_macro(no_line_macro_arg) { } Driver(const Driver &) = delete; Driver(Driver &&) = delete; Driver &operator=(const Driver &) = delete; diff --git a/src/macro/Environment.hh b/src/macro/Environment.hh index f706edde..231b245d 100644 --- a/src/macro/Environment.hh +++ b/src/macro/Environment.hh @@ -34,12 +34,8 @@ namespace macro map variables; map> functions; public: - Environment() : parent{nullptr} - { - } - Environment(const Environment *parent_arg) : parent{parent_arg} - { - } + Environment() : parent{nullptr} { } + Environment(const Environment *parent_arg) : parent{parent_arg} { } void define(VariablePtr var, ExpressionPtr value); void define(FunctionPtr func, ExpressionPtr value); ExpressionPtr getVariable(const string &name) const; @@ -47,24 +43,12 @@ namespace macro codes::BaseType getType(const string &name); 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); - } + inline bool isSymbolDefined(const string &name) const noexcept { return isVariableDefined(name) || isFunctionDefined(name); } void print(ostream &output, const vector &vars, int line = -1, bool save = false) const; void printVariable(ostream &output, const string &name, int line, bool save) const; void printFunction(ostream &output, const tuple &function, 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(); - } + inline size_t size() const noexcept { return variables.size() + functions.size(); } + inline const Environment *getGlobalEnv() const noexcept { return parent == nullptr ? this : parent->getGlobalEnv(); } }; } #endif diff --git a/src/macro/Expressions.hh b/src/macro/Expressions.hh index 7bbdcac0..153bc6ca 100644 --- a/src/macro/Expressions.hh +++ b/src/macro/Expressions.hh @@ -36,23 +36,20 @@ namespace macro private: vector message; public: - StackTrace(string message_arg) : message{move(message_arg)} - { - } - StackTrace(const string &prefix, const char *standard_exception_message, const Tokenizer::location &location) + StackTrace (string message_arg) : message{move(message_arg)} { } + StackTrace (const string &prefix, const char *standard_exception_message, const Tokenizer::location &location) { stringstream ss; ss << prefix << ": " << location << " " << standard_exception_message; message = {ss.str()}; } - StackTrace(const string &prefix, const string &msg, const Tokenizer::location &location) + StackTrace (const string &prefix, const string &msg, const Tokenizer::location &location) { stringstream ss; ss << prefix << ": " << location << " " << msg; message = {ss.str()}; } - void - push(const string &prefix, const Tokenizer::location &location) + void push(const string &prefix, const Tokenizer::location &location) { stringstream ss; auto end_col = 0 < location.end.column ? location.end.column - 1 : 0; @@ -71,8 +68,7 @@ namespace macro ss << "-" << end_col; message.emplace_back(ss.str()); } - string - trace() const + string trace() const { stringstream ss; for (auto &msg : message) @@ -81,6 +77,7 @@ namespace macro } }; + class Node { protected: @@ -88,36 +85,25 @@ namespace macro const Tokenizer::location location; public: Node(Environment &env_arg, Tokenizer::location location_arg) : - env{env_arg}, location{move(location_arg)} - { - } - virtual - ~Node() = default; + env{env_arg}, location{move(location_arg)} { } + virtual ~Node() = default; public: - inline Tokenizer::location - getLocation() const noexcept - { - return location; - } - inline void - error(const StackTrace &e) const noexcept + inline Tokenizer::location getLocation() const noexcept { return location; } + inline 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 + inline void warning(const StackTrace &e) const noexcept { cerr << endl << "Macro-processing warning: backtrace..." << endl << e.trace(); } - inline void - printLineInfo(ostream &output, bool no_line_macro) const noexcept + inline void printLineInfo(ostream &output, bool no_line_macro) const noexcept { if (!no_line_macro) output << R"(@#line ")" << *(location.begin.filename) << R"(" )" << location.begin.line << endl; } - inline void - printEndLineInfo(ostream &output, bool no_line_macro) const noexcept + inline void printEndLineInfo(ostream &output, bool no_line_macro) const noexcept { if (!no_line_macro) // Add one to end line because we want to print the line number of the line *following* the end statement @@ -125,352 +111,95 @@ namespace macro } }; + class Expression : public Node { public: Expression(Environment &env_arg, Tokenizer::location location_arg) : - Node(env_arg, move(location_arg)) - { - } + Node(env_arg, move(location_arg)) { } virtual string to_string() const noexcept = 0; virtual void print(ostream &output, bool matlab_output = false) const noexcept = 0; virtual BaseTypePtr eval() = 0; virtual ExpressionPtr clone() const noexcept = 0; }; + class BaseType : public Expression, public enable_shared_from_this { public: BaseType(Environment &env_arg, Tokenizer::location location_arg = Tokenizer::location()) : - Expression(env_arg, move(location_arg)) - { - } + Expression(env_arg, move(location_arg)) { } virtual codes::BaseType getType() const noexcept = 0; - inline BaseTypePtr - eval() override - { - return shared_from_this(); - } + inline BaseTypePtr eval() 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"); - } - virtual BaseTypePtr - minus(const BaseTypePtr &bt) const - { - throw StackTrace("Operator - does not exist for this type"); - } - virtual BaseTypePtr - unary_minus() const - { - throw StackTrace("Unary operator - does not exist for this type"); - } - virtual BaseTypePtr - times(const BaseTypePtr &bt) const - { - throw StackTrace("Operator * does not exist for this type"); - } - virtual BaseTypePtr - divide(const BaseTypePtr &bt) const - { - throw StackTrace("Operator / does not exist for this type"); - } - virtual BaseTypePtr - power(const BaseTypePtr &btp) const - { - throw StackTrace("Operator ^ does not exist for this type"); - } - virtual BoolPtr - is_less(const BaseTypePtr &btp) const - { - throw StackTrace("Operator < does not exist for this type"); - } - virtual BoolPtr - is_greater(const BaseTypePtr &btp) const - { - throw StackTrace("Operator > does not exist for this type"); - } - virtual BoolPtr - is_less_equal(const BaseTypePtr &btp) const - { - throw StackTrace("Operator <= does not exist for this type"); - } - virtual BoolPtr - is_greater_equal(const BaseTypePtr &btp) const - { - throw StackTrace("Operator >= does not exist for this type"); - } + 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"); } + virtual BaseTypePtr minus(const BaseTypePtr &bt) const { throw StackTrace("Operator - does not exist for this type"); } + virtual BaseTypePtr unary_minus() const { throw StackTrace("Unary operator - does not exist for this type"); } + virtual BaseTypePtr times(const BaseTypePtr &bt) const { throw StackTrace("Operator * does not exist for this type"); } + virtual BaseTypePtr divide(const BaseTypePtr &bt) const { throw StackTrace("Operator / does not exist for this type"); } + virtual BaseTypePtr power(const BaseTypePtr &btp) const { throw StackTrace("Operator ^ does not exist for this type"); } + virtual BoolPtr is_less(const BaseTypePtr &btp) const { throw StackTrace("Operator < does not exist for this type"); } + virtual BoolPtr is_greater(const BaseTypePtr &btp) const { throw StackTrace("Operator > does not exist for this type"); } + virtual BoolPtr is_less_equal(const BaseTypePtr &btp) const { throw StackTrace("Operator <= does not exist for this type"); } + virtual BoolPtr is_greater_equal(const BaseTypePtr &btp) const { throw StackTrace("Operator >= does not exist for this type"); } virtual BoolPtr is_equal(const BaseTypePtr &btp) const = 0; virtual BoolPtr is_different(const BaseTypePtr &btp) const final; - virtual BoolPtr - logical_and(const ExpressionPtr &ep) const - { - throw StackTrace("Operator && does not exist for this type"); - } - virtual BoolPtr - logical_or(const ExpressionPtr &ep) const - { - throw StackTrace("Operator || does not exist for this type"); - } - virtual BoolPtr - logical_not() const - { - throw StackTrace("Operator ! does not exist for this type"); - } - virtual ArrayPtr - set_union(const BaseTypePtr &btp) const - { - throw StackTrace("Operator | does not exist for this type"); - } - virtual ArrayPtr - set_intersection(const BaseTypePtr &btp) const - { - throw StackTrace("Operator & does not exist for this type"); - } - virtual BoolPtr - contains(const BaseTypePtr &btp) const - { - throw StackTrace("Second argument of `in` operator must be an array"); - } - virtual RealPtr - length() const - { - throw StackTrace("Operator `length` does not exist for this type"); - } - virtual BoolPtr - isempty() const - { - throw StackTrace("Operator `isempty` does not exist for this type"); - } - virtual BoolPtr - isboolean() const noexcept - { - return make_shared(false, env, location); - } - virtual BoolPtr - isreal() const noexcept - { - return make_shared(false, env, location); - } - virtual BoolPtr - isinteger() const noexcept - { - return make_shared(false, env, location); - } - virtual BoolPtr - isstring() const noexcept - { - return make_shared(false, env, location); - } - virtual BoolPtr - istuple() const noexcept - { - return make_shared(false, env, location); - } - virtual BoolPtr - isarray() const noexcept - { - return make_shared(false, env, location); - } - virtual RealPtr - max(const BaseTypePtr &btp) const - { - throw StackTrace("Operator `max` does not exist for this type"); - } - virtual RealPtr - min(const BaseTypePtr &btp) const - { - throw StackTrace("Operator `min` does not exist for this type"); - } - virtual RealPtr - mod(const BaseTypePtr &btp) const - { - throw StackTrace("Operator `mod` does not exist for this type"); - } - virtual RealPtr - exp() const - { - throw StackTrace("Operator `exp` does not exist for this type"); - } - virtual RealPtr - ln() const - { - throw StackTrace("Operator `ln` does not exist for this type"); - } - virtual RealPtr - log10() const - { - throw StackTrace("Operator `log10` does not exist for this type"); - } - virtual BoolPtr - isinf() const - { - throw StackTrace("Operator `isinf` does not exist for this type"); - } - virtual BoolPtr - isnan() const - { - throw StackTrace("Operator `isnan` does not exist for this type"); - } - virtual BoolPtr - isfinite() const - { - throw StackTrace("Operator `isfinite` does not exist for this type"); - } - virtual BoolPtr - isnormal() const - { - throw StackTrace("Operator `isnormal` does not exist for this type"); - } - virtual RealPtr - sin() const - { - throw StackTrace("Operator `sin` does not exist for this type"); - } - virtual RealPtr - cos() const - { - throw StackTrace("Operator `cos` does not exist for this type"); - } - virtual RealPtr - tan() const - { - throw StackTrace("Operator `tan` does not exist for this type"); - } - virtual RealPtr - asin() const - { - throw StackTrace("Operator `asin` does not exist for this type"); - } - virtual RealPtr - acos() const - { - throw StackTrace("Operator `acos` does not exist for this type"); - } - virtual RealPtr - atan() const - { - throw StackTrace("Operator `atan` does not exist for this type"); - } - virtual RealPtr - sqrt() const - { - throw StackTrace("Operator `sqrt` does not exist for this type"); - } - virtual RealPtr - cbrt() const - { - throw StackTrace("Operator `cbrt` does not exist for this type"); - } - virtual RealPtr - sign() const - { - throw StackTrace("Operator `sign` does not exist for this type"); - } - virtual RealPtr - floor() const - { - throw StackTrace("Operator `floor` does not exist for this type"); - } - virtual RealPtr - ceil() const - { - throw StackTrace("Operator `ceil` does not exist for this type"); - } - virtual RealPtr - trunc() const - { - throw StackTrace("Operator `trunc` does not exist for this type"); - } - virtual RealPtr - sum() const - { - throw StackTrace("Operator `sum` does not exist for this type"); - } - virtual RealPtr - erf() const - { - throw StackTrace("Operator `erf` does not exist for this type"); - } - virtual RealPtr - erfc() const - { - throw StackTrace("Operator `erfc` does not exist for this type"); - } - virtual RealPtr - gamma() const - { - throw StackTrace("Operator `gamma` does not exist for this type"); - } - virtual RealPtr - lgamma() const - { - throw StackTrace("Operator `lgamma` does not exist for this type"); - } - virtual RealPtr - round() const - { - throw StackTrace("Operator `round` does not exist for this type"); - } - virtual RealPtr - normpdf() const - { - throw StackTrace("Operator `normpdf` does not exist for this type"); - } - virtual RealPtr - normpdf(const BaseTypePtr &btp1, const BaseTypePtr &btp2) const - { - throw StackTrace("Operator `normpdf` does not exist for this type"); - } - virtual RealPtr - normcdf() const - { - throw StackTrace("Operator `normcdf` does not exist for this type"); - } - virtual RealPtr - normcdf(const BaseTypePtr &btp1, const BaseTypePtr &btp2) const - { - throw StackTrace("Operator `normcdf` does not exist for this type"); - } - virtual BoolPtr - cast_bool() const - { - throw StackTrace("This type cannot be cast to a boolean"); - } - virtual RealPtr - cast_real() const - { - throw StackTrace("This type cannot be cast to a real"); - } - virtual StringPtr - cast_string() const - { - throw StackTrace("This type cannot be cast to a string"); - } - virtual TuplePtr - cast_tuple() const - { - throw StackTrace("This type cannot be cast to a tuple"); - } - virtual ArrayPtr - cast_array() const - { - throw StackTrace("This type cannot be cast to an array"); - } - virtual BoolPtr - defined() const - { - throw StackTrace("Operator `defined` does not exist for this type"); - } + virtual BoolPtr logical_and(const ExpressionPtr &ep) const { throw StackTrace("Operator && does not exist for this type"); } + virtual BoolPtr logical_or(const ExpressionPtr &ep) const { throw StackTrace("Operator || does not exist for this type"); } + virtual BoolPtr logical_not() const { throw StackTrace("Operator ! does not exist for this type"); } + virtual ArrayPtr set_union(const BaseTypePtr &btp) const { throw StackTrace("Operator | does not exist for this type"); } + virtual ArrayPtr set_intersection(const BaseTypePtr &btp) const { throw StackTrace("Operator & does not exist for this type"); } + virtual BoolPtr contains(const BaseTypePtr &btp) const { throw StackTrace("Second argument of `in` operator must be an array"); } + virtual RealPtr length() const { throw StackTrace("Operator `length` does not exist for this type"); } + virtual BoolPtr isempty() const { throw StackTrace("Operator `isempty` does not exist for this type"); } + virtual BoolPtr isboolean() const noexcept { return make_shared(false, env, location); } + virtual BoolPtr isreal() const noexcept { return make_shared(false, env, location); } + virtual BoolPtr isinteger() const noexcept { return make_shared(false, env, location); } + virtual BoolPtr isstring() const noexcept { return make_shared(false, env, location); } + virtual BoolPtr istuple() const noexcept { return make_shared(false, env, location); } + virtual BoolPtr isarray() const noexcept { return make_shared(false, env, location); } + virtual RealPtr max(const BaseTypePtr &btp) const { throw StackTrace("Operator `max` does not exist for this type"); } + virtual RealPtr min(const BaseTypePtr &btp) const { throw StackTrace("Operator `min` does not exist for this type"); } + virtual RealPtr mod(const BaseTypePtr &btp) const { throw StackTrace("Operator `mod` does not exist for this type"); } + virtual RealPtr exp() const { throw StackTrace("Operator `exp` does not exist for this type"); } + virtual RealPtr ln() const { throw StackTrace("Operator `ln` does not exist for this type"); } + virtual RealPtr log10() const { throw StackTrace("Operator `log10` does not exist for this type"); } + virtual BoolPtr isinf() const { throw StackTrace("Operator `isinf` does not exist for this type"); } + virtual BoolPtr isnan() const { throw StackTrace("Operator `isnan` does not exist for this type"); } + virtual BoolPtr isfinite() const { throw StackTrace("Operator `isfinite` does not exist for this type"); } + virtual BoolPtr isnormal() const { throw StackTrace("Operator `isnormal` does not exist for this type"); } + virtual RealPtr sin() const { throw StackTrace("Operator `sin` does not exist for this type"); } + virtual RealPtr cos() const { throw StackTrace("Operator `cos` does not exist for this type"); } + virtual RealPtr tan() const { throw StackTrace("Operator `tan` does not exist for this type"); } + virtual RealPtr asin() const { throw StackTrace("Operator `asin` does not exist for this type"); } + virtual RealPtr acos() const { throw StackTrace("Operator `acos` does not exist for this type"); } + virtual RealPtr atan() const { throw StackTrace("Operator `atan` does not exist for this type"); } + virtual RealPtr sqrt() const { throw StackTrace("Operator `sqrt` does not exist for this type"); } + virtual RealPtr cbrt() const { throw StackTrace("Operator `cbrt` does not exist for this type"); } + virtual RealPtr sign() const { throw StackTrace("Operator `sign` does not exist for this type"); } + virtual RealPtr floor() const { throw StackTrace("Operator `floor` does not exist for this type"); } + virtual RealPtr ceil() const { throw StackTrace("Operator `ceil` does not exist for this type"); } + virtual RealPtr trunc() const { throw StackTrace("Operator `trunc` does not exist for this type"); } + virtual RealPtr sum() const { throw StackTrace("Operator `sum` does not exist for this type"); } + virtual RealPtr erf() const { throw StackTrace("Operator `erf` does not exist for this type"); } + virtual RealPtr erfc() const { throw StackTrace("Operator `erfc` does not exist for this type"); } + virtual RealPtr gamma() const { throw StackTrace("Operator `gamma` does not exist for this type"); } + virtual RealPtr lgamma() const { throw StackTrace("Operator `lgamma` does not exist for this type"); } + virtual RealPtr round() const { throw StackTrace("Operator `round` does not exist for this type"); } + virtual RealPtr normpdf() const { throw StackTrace("Operator `normpdf` does not exist for this type"); } + virtual RealPtr normpdf(const BaseTypePtr &btp1, const BaseTypePtr &btp2) const { throw StackTrace("Operator `normpdf` does not exist for this type"); } + virtual RealPtr normcdf() const { throw StackTrace("Operator `normcdf` does not exist for this type"); } + virtual RealPtr normcdf(const BaseTypePtr &btp1, const BaseTypePtr &btp2) const { throw StackTrace("Operator `normcdf` does not exist for this type"); } + virtual BoolPtr cast_bool() const { throw StackTrace("This type cannot be cast to a boolean"); } + virtual RealPtr cast_real() const { throw StackTrace("This type cannot be cast to a real"); } + virtual StringPtr cast_string() const { throw StackTrace("This type cannot be cast to a string"); } + virtual TuplePtr cast_tuple() const { throw StackTrace("This type cannot be cast to a tuple"); } + virtual ArrayPtr cast_array() const { throw StackTrace("This type cannot be cast to an array"); } + virtual BoolPtr defined() const { throw StackTrace("Operator `defined` does not exist for this type"); } }; + class Bool final : public BaseType { private: @@ -479,67 +208,32 @@ namespace macro Bool(bool value_arg, Environment &env_arg, Tokenizer::location location_arg = Tokenizer::location()) : BaseType(env_arg, 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(value, env, location); - } + 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(value, env, location); } public: operator bool() const { return value; } BoolPtr is_equal(const BaseTypePtr &btp) const override; BoolPtr logical_and(const ExpressionPtr &ep) const override; BoolPtr logical_or(const ExpressionPtr &ep) const override; BoolPtr logical_not() const override; - inline BoolPtr - isboolean() const noexcept override - { - return make_shared(true, env, location); - } - inline BoolPtr - cast_bool() const override - { - return make_shared(value, env); - } - inline RealPtr - cast_real() const override - { - return value ? make_shared(1, env) : make_shared(0, env); - } - inline StringPtr - cast_string() const override - { - return make_shared(this->to_string(), env); - } - inline TuplePtr - cast_tuple() const override + inline BoolPtr isboolean() const noexcept override { return make_shared(true, env, location); } + inline BoolPtr cast_bool() const override { return make_shared(value, env); } + inline RealPtr cast_real() const override { return value ? make_shared(1, env) : make_shared(0, env); } + inline StringPtr cast_string() const override { return make_shared(this->to_string(), env); } + inline TuplePtr cast_tuple() const override { return make_shared(vector{make_shared(value, env)}, env); } - inline ArrayPtr - cast_array() const override + inline ArrayPtr cast_array() const override { return make_shared(vector{make_shared(value, env)}, env); } }; + class Real final : public BaseType { private: @@ -550,51 +244,26 @@ namespace macro Real(const string &value_arg, Environment &env_arg, Tokenizer::location location_arg = Tokenizer::location()) : BaseType(env_arg, move(location_arg)), - value{strtod(value_arg.c_str(), nullptr)} - { - } + value{strtod(value_arg.c_str(), nullptr)} { } Real(double value_arg, Environment &env_arg, Tokenizer::location location_arg = Tokenizer::location()) : BaseType(env_arg, move(location_arg)), - value{value_arg} - { - } - inline codes::BaseType - getType() const noexcept override - { - return codes::BaseType::Real; - } - inline string - to_string() const noexcept override + value{value_arg} { } + inline codes::BaseType getType() const noexcept override { return codes::BaseType::Real; } + inline 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(value, env, location); - } + inline void print(ostream &output, bool matlab_output = false) const noexcept override { output << to_string(); } + inline ExpressionPtr clone() const noexcept override { return make_shared(value, env, location); } public: operator double() const { return value; } BaseTypePtr plus(const BaseTypePtr &bt) const override; - inline BaseTypePtr - unary_plus() const override - { - return make_shared(value, env); - } + inline BaseTypePtr unary_plus() const override { return make_shared(value, env); } BaseTypePtr minus(const BaseTypePtr &bt) const override; - inline BaseTypePtr - unary_minus() const override - { - return make_shared(-value, env); - } + inline BaseTypePtr unary_minus() const override { return make_shared(-value, env); } BaseTypePtr times(const BaseTypePtr &bt) const override; BaseTypePtr divide(const BaseTypePtr &bt) const override; BaseTypePtr power(const BaseTypePtr &btp) const override; @@ -603,13 +272,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(true, env, location); - } - inline BoolPtr - isinteger() const noexcept override + inline BoolPtr isreal() const noexcept override { return make_shared(true, env, location); } + inline BoolPtr isinteger() const noexcept override { double intpart; return make_shared(modf(value, &intpart) == 0.0, env, location); @@ -620,160 +284,51 @@ 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(std::exp(value), env); - } - inline RealPtr - ln() const override - { - return make_shared(std::log(value), env); - } - inline RealPtr - log10() const override - { - return make_shared(std::log10(value), env); - } - inline BoolPtr - isinf() const override - { - return make_shared(std::isinf(value), env); - } - inline BoolPtr - isnan() const override - { - return make_shared(std::isnan(value), env); - } - inline BoolPtr - isfinite() const override - { - return make_shared(std::isfinite(value), env); - } - inline BoolPtr - isnormal() const override - { - return make_shared(std::isnormal(value), env); - } - inline RealPtr - sin() const override - { - return make_shared(std::sin(value), env); - } - inline RealPtr - cos() const override - { - return make_shared(std::cos(value), env); - } - inline RealPtr - tan() const override - { - return make_shared(std::tan(value), env); - } - inline RealPtr - asin() const override - { - return make_shared(std::asin(value), env); - } - inline RealPtr - acos() const override - { - return make_shared(std::acos(value), env); - } - inline RealPtr - atan() const override - { - return make_shared(std::atan(value), env); - } - inline RealPtr - sqrt() const override - { - return make_shared(std::sqrt(value), env); - } - inline RealPtr - cbrt() const override - { - return make_shared(std::cbrt(value), env); - } - inline RealPtr - sign() const override + inline RealPtr exp() const override { return make_shared(std::exp(value), env); } + inline RealPtr ln() const override { return make_shared(std::log(value), env); } + inline RealPtr log10() const override { return make_shared(std::log10(value), env); } + inline BoolPtr isinf() const override { return make_shared(std::isinf(value), env); } + inline BoolPtr isnan() const override { return make_shared(std::isnan(value), env); } + inline BoolPtr isfinite() const override { return make_shared(std::isfinite(value), env); } + inline BoolPtr isnormal() const override { return make_shared(std::isnormal(value), env); } + inline RealPtr sin() const override { return make_shared(std::sin(value), env); } + inline RealPtr cos() const override { return make_shared(std::cos(value), env); } + inline RealPtr tan() const override { return make_shared(std::tan(value), env); } + inline RealPtr asin() const override { return make_shared(std::asin(value), env); } + inline RealPtr acos() const override { return make_shared(std::acos(value), env); } + inline RealPtr atan() const override { return make_shared(std::atan(value), env); } + inline RealPtr sqrt() const override { return make_shared(std::sqrt(value), env); } + inline RealPtr cbrt() const override { return make_shared(std::cbrt(value), env); } + inline RealPtr sign() const override { return make_shared((value > 0) ? 1. : ((value < 0) ? -1. : 0.), env); } - inline RealPtr - floor() const override - { - return make_shared(std::floor(value), env); - } - inline RealPtr - ceil() const override - { - return make_shared(std::ceil(value), env); - } - inline RealPtr - trunc() const override - { - return make_shared(std::trunc(value), env); - } - inline RealPtr - erf() const override - { - return make_shared(std::erf(value), env); - } - inline RealPtr - erfc() const override - { - return make_shared(std::erfc(value), env); - } - inline RealPtr - gamma() const override - { - return make_shared(std::tgamma(value), env); - } - inline RealPtr - lgamma() const override - { - return make_shared(std::lgamma(value), env); - } - inline RealPtr - round() const override - { - return make_shared(std::round(value), env); - } - inline RealPtr - normpdf() const override + inline RealPtr floor() const override { return make_shared(std::floor(value), env); } + inline RealPtr ceil() const override { return make_shared(std::ceil(value), env); } + inline RealPtr trunc() const override { return make_shared(std::trunc(value), env); } + inline RealPtr erf() const override { return make_shared(std::erf(value), env); } + inline RealPtr erfc() const override { return make_shared(std::erfc(value), env); } + inline RealPtr gamma() const override { return make_shared(std::tgamma(value), env); } + inline RealPtr lgamma() const override { return make_shared(std::lgamma(value), env); } + inline RealPtr round() const override { return make_shared(std::round(value), env); } + inline RealPtr normpdf() const override { return normpdf(make_shared(0, env), make_shared(1, env)); } RealPtr normpdf(const BaseTypePtr &btp1, const BaseTypePtr &btp2) const override; - inline RealPtr - normcdf() const override + inline RealPtr normcdf() const override { return normcdf(make_shared(0, env), make_shared(1, env)); } RealPtr normcdf(const BaseTypePtr &btp1, const BaseTypePtr &btp2) const override; - inline BoolPtr - cast_bool() const override - { - return make_shared(static_cast(value), env); - } - inline RealPtr - cast_real() const override - { - return make_shared(value, env); - } - inline StringPtr - cast_string() const override - { - return make_shared(this->to_string(), env); - } - inline TuplePtr - cast_tuple() const override + inline BoolPtr cast_bool() const override { return make_shared(static_cast(value), env); } + inline RealPtr cast_real() const override { return make_shared(value, env); } + inline StringPtr cast_string() const override { return make_shared(this->to_string(), env); } + inline TuplePtr cast_tuple() const override { return make_shared(vector{make_shared(value, env)}, env); } - inline ArrayPtr - cast_array() const override + inline ArrayPtr cast_array() const override { return make_shared(vector{make_shared(value, env)}, env); } @@ -787,25 +342,11 @@ namespace macro String(string value_arg, Environment &env_arg, Tokenizer::location location_arg = Tokenizer::location()) : BaseType(env_arg, 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; - } + value{move(value_arg)} { } + inline codes::BaseType getType() const noexcept override { return codes::BaseType::String; } + inline 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(value, env, location); - } + inline ExpressionPtr clone() const noexcept override { return make_shared(value, env, location); } public: operator string() const { return value; } BaseTypePtr plus(const BaseTypePtr &bt) const override; @@ -814,45 +355,27 @@ 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(true, env, location); - } - inline RealPtr - length() const override - { - return make_shared(value.size(), env); - } - inline BoolPtr - isempty() const override - { - return make_shared(value.empty(), env); - } + inline BoolPtr isstring() const noexcept override { return make_shared(true, env, location); } + inline RealPtr length() const override { return make_shared(value.size(), env); } + inline BoolPtr isempty() const override { return make_shared(value.empty(), env); } BoolPtr cast_bool() const override; RealPtr cast_real() const override; - inline StringPtr - cast_string() const override - { - return make_shared(value, env); - } - inline TuplePtr - cast_tuple() const override + inline StringPtr cast_string() const override { return make_shared(value, env); } + inline TuplePtr cast_tuple() const override { return make_shared(vector{make_shared(value, env)}, env); } - inline ArrayPtr - cast_array() const override + inline ArrayPtr cast_array() const override { return make_shared(vector{make_shared(value, env)}, env); } - inline BoolPtr - defined() const override + inline BoolPtr defined() const override { return make_shared(env.isSymbolDefined(value), env); } }; + class Tuple final : public BaseType { private: @@ -861,75 +384,30 @@ namespace macro Tuple(vector tup_arg, Environment &env_arg, Tokenizer::location location_arg = Tokenizer::location()) : BaseType(env_arg, move(location_arg)), - tup{move(tup_arg)} - { - } - inline codes::BaseType - getType() const noexcept override - { - return codes::BaseType::Tuple; - } + tup{move(tup_arg)} { } + inline 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() 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 & - getValue() const - { - return tup; - } - inline const ExpressionPtr & - at(int i) const - { - return tup.at(i); - } + inline size_t size() const { return tup.size(); } + inline bool empty() const { return tup.empty(); } + inline const vector &getValue() const { return tup; } + inline 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(true, env, location); - } + inline BoolPtr istuple() const noexcept override { return make_shared(true, env, location); } BoolPtr contains(const BaseTypePtr &btp) const override; - inline RealPtr - length() const override - { - return make_shared(tup.size(), env); - } - inline BoolPtr - isempty() const override - { - return make_shared(empty(), env); - } + inline RealPtr length() const override { return make_shared(tup.size(), env); } + inline BoolPtr isempty() const override { return make_shared(empty(), env); } BoolPtr cast_bool() const override; RealPtr cast_real() const override; - inline StringPtr - cast_string() const override - { - return make_shared(this->to_string(), env); - } - inline TuplePtr - cast_tuple() const override - { - return make_shared(tup, env); - } - inline ArrayPtr - cast_array() const override - { - return make_shared(tup, env); - } + inline StringPtr cast_string() const override { return make_shared(this->to_string(), env); } + inline TuplePtr cast_tuple() const override { return make_shared(tup, env); } + inline ArrayPtr cast_array() const override { return make_shared(tup, env); } }; + class Array final : public BaseType { private: @@ -937,82 +415,37 @@ namespace macro public: Array(vector arr_arg, Environment &env_arg, Tokenizer::location location_arg = Tokenizer::location()) : - BaseType(env_arg, move(location_arg)), arr{move(arr_arg)} - { - } - inline codes::BaseType - getType() const noexcept override - { - return codes::BaseType::Array; - } + BaseType(env_arg, move(location_arg)), arr{move(arr_arg)} { } + inline 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() override; ExpressionPtr clone() const noexcept override; public: - inline size_t - size() const - { - return arr.size(); - } - inline const vector & - getValue() const - { - return arr; - } - inline const ExpressionPtr & - at(int i) const - { - return arr.at(i); - } - inline bool - empty() const - { - return arr.empty(); - } + inline size_t size() const { return arr.size(); } + inline const vector &getValue() const { return arr; } + inline const ExpressionPtr &at(int i) const { return arr.at(i); } + inline 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(true, env, location); - } + inline BoolPtr isarray() const noexcept override { return make_shared(true, env, 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(arr.size(), env); - } - inline BoolPtr - isempty() const override - { - return make_shared(empty(), env); - } + inline RealPtr length() const override { return make_shared(arr.size(), env); } + inline BoolPtr isempty() const override { return make_shared(empty(), env); } RealPtr sum() const override; BoolPtr cast_bool() const override; RealPtr cast_real() const override; - inline StringPtr - cast_string() const override - { - return make_shared(this->to_string(), env); - } - inline TuplePtr - cast_tuple() const override - { - return make_shared(arr, env); - } - inline ArrayPtr - cast_array() const override - { - return make_shared(arr, env); - } + inline StringPtr cast_string() const override { return make_shared(this->to_string(), env); } + inline TuplePtr cast_tuple() const override { return make_shared(arr, env); } + inline ArrayPtr cast_array() const override { return make_shared(arr, env); } }; + class Range final : public BaseType { private: @@ -1020,49 +453,35 @@ namespace macro public: Range(ExpressionPtr start_arg, ExpressionPtr end_arg, Environment &env_arg, Tokenizer::location location_arg) : - BaseType(env_arg, move(location_arg)), start{move(start_arg)}, end{move(end_arg)} - { - } + BaseType(env_arg, move(location_arg)), start{move(start_arg)}, end{move(end_arg)} { } Range(ExpressionPtr start_arg, ExpressionPtr inc_arg, ExpressionPtr end_arg, Environment &env_arg, Tokenizer::location location_arg) : BaseType(env_arg, 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 + 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 { 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(); - } + inline void print(ostream &output, bool matlab_output = false) const noexcept override { output << to_string(); } BaseTypePtr eval() override; - inline ExpressionPtr - clone() const noexcept override + inline ExpressionPtr clone() const noexcept override { return inc ? make_shared(start, inc, end, env, location) : make_shared(start, end, env, location); } public: - inline BoolPtr - is_equal(const BaseTypePtr &btp) const override + inline BoolPtr is_equal(const BaseTypePtr &btp) const override { throw StackTrace("Internal error: Range: Should not arrive here: is_equal"); } }; + class Variable final : public Expression { private: @@ -1071,44 +490,24 @@ namespace macro public: Variable(string name_arg, Environment &env_arg, Tokenizer::location location_arg) : - Expression(env_arg, move(location_arg)), name{move(name_arg)} - { - } + Expression(env_arg, move(location_arg)), name{move(name_arg)} { } Variable(string name_arg, ArrayPtr indices_arg, Environment &env_arg, Tokenizer::location location_arg) : - Expression(env_arg, 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; - } + Expression(env_arg, 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; } BaseTypePtr eval() override; - inline ExpressionPtr - clone() const noexcept override + inline ExpressionPtr clone() const noexcept override { return indices ? make_shared(name, indices, env, location) : make_shared(name, env, location); } public: - inline const string & - getName() const noexcept - { - return name; - } - inline codes::BaseType - getType() const - { - return env.getType(name); - } + inline const string &getName() const noexcept { return name; } + inline codes::BaseType getType() const { return env.getType(name); } }; + class Function final : public Expression { private: @@ -1118,36 +517,22 @@ namespace macro Function(string name_arg, vector args_arg, Environment &env_arg, Tokenizer::location location_arg) : - Expression(env_arg, move(location_arg)), name{move(name_arg)}, args{move(args_arg)} - { - } + Expression(env_arg, 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 + inline void print(ostream &output, bool matlab_output = false) const noexcept override { printName(output); printArgs(output); } BaseTypePtr eval() override; ExpressionPtr clone() const noexcept override; public: - inline void - printName(ostream &output) const noexcept - { - output << name; - } + inline void printName(ostream &output) const noexcept { output << name; } void printArgs(ostream &output) const noexcept; - inline const string & - getName() const - { - return name; - } - inline const vector & - getArgs() const - { - return args; - } + inline const string &getName() const { return name; } + inline const vector &getArgs() const { return args; } }; + class UnaryOp final : public Expression { private: @@ -1157,19 +542,17 @@ namespace macro UnaryOp(codes::UnaryOp op_code_arg, ExpressionPtr arg_arg, Environment &env_arg, Tokenizer::location location_arg) : - Expression(env_arg, move(location_arg)), op_code{move(op_code_arg)}, arg{move(arg_arg)} - { - } + Expression(env_arg, move(location_arg)), op_code{move(op_code_arg)}, arg{move(arg_arg)} { } string to_string() const noexcept override; void print(ostream &output, bool matlab_output = false) const noexcept override; BaseTypePtr eval() override; - inline ExpressionPtr - clone() const noexcept override + inline ExpressionPtr clone() const noexcept override { return make_shared(op_code, arg->clone(), env, location); } }; + class BinaryOp final : public Expression { private: @@ -1180,20 +563,18 @@ namespace macro ExpressionPtr arg1_arg, ExpressionPtr arg2_arg, Environment &env_arg, Tokenizer::location location_arg) : Expression(env_arg, move(location_arg)), op_code{op_code_arg}, - arg1{move(arg1_arg)}, arg2{move(arg2_arg)} - { - } + arg1{move(arg1_arg)}, arg2{move(arg2_arg)} { } public: string to_string() const noexcept override; void print(ostream &output, bool matlab_output = false) const noexcept override; BaseTypePtr eval() override; - inline ExpressionPtr - clone() const noexcept override + inline ExpressionPtr clone() const noexcept override { return make_shared(op_code, arg1->clone(), arg2->clone(), env, location); } }; + class TrinaryOp final : public Expression { private: @@ -1204,19 +585,17 @@ namespace macro ExpressionPtr arg1_arg, ExpressionPtr arg2_arg, ExpressionPtr arg3_arg, Environment &env_arg, Tokenizer::location location_arg) : Expression(env_arg, move(location_arg)), op_code{op_code_arg}, - arg1{move(arg1_arg)}, arg2{move(arg2_arg)}, arg3{move(arg3_arg)} - { - } + arg1{move(arg1_arg)}, arg2{move(arg2_arg)}, arg3{move(arg3_arg)} { } string to_string() const noexcept override; void print(ostream &output, bool matlab_output = false) const noexcept override; BaseTypePtr eval() override; - inline ExpressionPtr - clone() const noexcept override + inline ExpressionPtr clone() const noexcept override { return make_shared(op_code, arg1->clone(), arg2->clone(), arg3->clone(), env, location); } }; + class Comprehension final : public Expression { /* @@ -1234,26 +613,20 @@ namespace macro Environment &env_arg, Tokenizer::location location_arg) : Expression(env_arg, move(location_arg)), c_expr{move(c_expr_arg)}, c_vars{move(c_vars_arg)}, - c_set{move(c_set_arg)}, c_when{move(c_when_arg)} - { - } + c_set{move(c_set_arg)}, c_when{move(c_when_arg)} { } Comprehension(ExpressionPtr c_expr_arg, ExpressionPtr c_vars_arg, ExpressionPtr c_set_arg, Environment &env_arg, Tokenizer::location location_arg) : Expression(env_arg, move(location_arg)), - c_expr{move(c_expr_arg)}, c_vars{move(c_vars_arg)}, c_set{move(c_set_arg)} - { - } + c_expr{move(c_expr_arg)}, c_vars{move(c_vars_arg)}, c_set{move(c_set_arg)} { } Comprehension(bool filter_only_arg, ExpressionPtr c_vars_arg, ExpressionPtr c_set_arg, ExpressionPtr c_when_arg, Environment &env_arg, Tokenizer::location location_arg) : Expression(env_arg, move(location_arg)), - c_vars{move(c_vars_arg)}, c_set{move(c_set_arg)}, c_when{move(c_when_arg)} - { - } + c_vars{move(c_vars_arg)}, c_set{move(c_set_arg)}, c_when{move(c_when_arg)} { } string to_string() const noexcept override; void print(ostream &output, bool matlab_output = false) const noexcept override; BaseTypePtr eval() override;