Skip to content

Commit

Permalink
Minor code cleanups after compiling with Clang
Browse files Browse the repository at this point in the history
  • Loading branch information
cpp-tutor committed Aug 21, 2022
1 parent 081a3fc commit 225e3fd
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 22 deletions.
9 changes: 5 additions & 4 deletions Expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Expression : public Tree {
virtual bool isConstant() = 0;
virtual ExpI type() = 0;
virtual ExpT apply() = 0;
virtual ~Expression() {}
protected:
template<typename T>
inline static const std::unordered_map<Operator,std::function<BoolT(T,T)>> Rel_ops{
Expand All @@ -42,22 +43,22 @@ class Expression : public Tree {
inline static const std::unordered_map<Operator,std::function<BoolT(BoolT,BoolT)>> BoolT_ops{
{ Operator::OR, [](IntT a, IntT b){ return a | b; } },
{ Operator::AND, [](IntT a, IntT b){ return a & b; } },
{ Operator::NOT, [](IntT a, IntT b){ return ~a; } }
{ Operator::NOT, [](IntT a, [[maybe_unused]] IntT b){ return ~a; } }
};
inline static const std::unordered_map<Operator,std::function<IntT(IntT,IntT)>> IntT_ops{
{ Operator::plus, [](IntT a, IntT b){ return a + b; } },
{ Operator::minus, [](IntT a, IntT b){ return a - b; } },
{ Operator::multiply, [](IntT a, IntT b){ return a * b; } },
{ Operator::DIV, [](IntT a, IntT b){ return a / b; } },
{ Operator::MOD, [](IntT a, IntT b){ return a % b; } },
{ Operator::negative, [](IntT a, IntT b){ return -a; } }
{ Operator::negative, [](IntT a, [[maybe_unused]] IntT b){ return -a; } }
};
inline static const std::unordered_map<Operator,std::function<RealT(RealT,RealT)>> RealT_ops{
{ Operator::plus, [](RealT a, RealT b){ return a + b; } },
{ Operator::minus, [](RealT a, RealT b){ return a - b; } },
{ Operator::multiply, [](RealT a, RealT b){ return a * b; } },
{ Operator::divide, [](RealT a, RealT b){ return a / b; } },
{ Operator::negative, [](RealT a, RealT b){ return -a; } }
{ Operator::negative, [](RealT a, [[maybe_unused]] RealT b){ return -a; } }
};
inline static const std::unordered_map<Operator,std::function<StringT(StringT,StringT)>> StringT_ops{
{ Operator::plus, [](StringT a, StringT b){ return static_cast<StringT>(a.append(b)); } }
Expand Down Expand Up @@ -179,7 +180,7 @@ class Variable : public Expression {
ExpI tp;
public:
Variable(ExpI t, std::string_view l)
: tp{ t }, label{ l } {}
: label{ l }, tp{ t } {}
virtual bool isConstant() override {
return false;
}
Expand Down
9 changes: 1 addition & 8 deletions For.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ class For : public Tree {
right->emit();
}
}
virtual ~For() {
delete from;
delete to;
delete step;
}

};

class ForIn : public Tree {
Expand All @@ -63,9 +59,6 @@ class ForIn : public Tree {
right->emit();
}
}
virtual ~ForIn() {
delete exp;
}
};

#endif // FOR_HPP
1 change: 0 additions & 1 deletion Lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
namespace yy {

class Lexer : public yyFlexLexer {
size_t location_x{ 1 }, location_y{ 1 };
public:
Lexer(std::istream& arg_yyin, std::ostream& arg_yyout)
: yyFlexLexer(arg_yyin, arg_yyout) {}
Expand Down
7 changes: 0 additions & 7 deletions Utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class StringPos : public Expression {
virtual ExpI type() override {
return ExpI::IntT;
}
virtual ~StringPos() {
delete sub;
}
};

class StringSub : public Expression {
Expand Down Expand Up @@ -86,10 +83,6 @@ class StringSub : public Expression {
virtual ExpI type() override {
return ExpI::StringT;
}
virtual ~StringSub() {
delete from;
delete to;
}
};

class StringToInt : public Expression {
Expand Down
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const std::vector<std::pair<std::string_view,std::string_view>> Options{
#endif
};

const auto support_nodejs_code = 1 + R"(
const readline_sync = require('readline-sync');
const auto support_nodejs_code =
R"(const readline_sync = require('readline-sync');
function readline() {
return readline_sync.question('');
}
Expand Down

0 comments on commit 225e3fd

Please sign in to comment.