Remove unnecessary code
This commit is contained in:
parent
4f39417d3e
commit
fb06f6f483
@ -6,19 +6,14 @@
|
||||
|
||||
Environment::Environment(const Environment &other) : enclosing{other.enclosing}, values{other.values} {}
|
||||
|
||||
Environment::Environment(Environment &&other) noexcept : enclosing{std::move(other.enclosing)}, values{std::move(other.values)} {
|
||||
other.enclosing.reset();
|
||||
}
|
||||
Environment::Environment(Environment &&other) noexcept
|
||||
: enclosing{std::move(other.enclosing)}, values{std::move(other.values)} {}
|
||||
|
||||
Environment &Environment::operator=(const Environment &other) {
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (enclosing) {
|
||||
enclosing.reset();
|
||||
}
|
||||
|
||||
enclosing = other.enclosing;
|
||||
values = other.values;
|
||||
|
||||
@ -30,10 +25,6 @@ Environment &Environment::operator=(Environment &&other) noexcept {
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (enclosing) {
|
||||
enclosing.reset();
|
||||
}
|
||||
|
||||
enclosing = std::move(other.enclosing);
|
||||
values = std::move(other.values);
|
||||
|
||||
|
@ -1,94 +1,14 @@
|
||||
#include "expr.hh"
|
||||
#include "../tokenizer.hh"
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
Expr::Expr(ExprType type, ExprVariant value) : type{type}, value{value} {}
|
||||
|
||||
// Copy constructor
|
||||
Expr::Expr(const Expr &other) : type{other.type} {
|
||||
switch(type) {
|
||||
case ExprType::BINARY: {
|
||||
std::shared_ptr<_Binary> ptr = std::get<std::shared_ptr<_Binary>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Binary>(*ptr);
|
||||
break;
|
||||
}
|
||||
case ExprType::GROUPING: {
|
||||
std::shared_ptr<_Grouping> ptr = std::get<std::shared_ptr<_Grouping>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Grouping>(*ptr);
|
||||
break;
|
||||
}
|
||||
case ExprType::LITERAL: {
|
||||
std::shared_ptr<_Literal> ptr = std::get<std::shared_ptr<_Literal>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Literal>(*ptr);
|
||||
break;
|
||||
}
|
||||
case ExprType::UNARY: {
|
||||
std::shared_ptr<_Unary> ptr = std::get<std::shared_ptr<_Unary>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Unary>(*ptr);
|
||||
break;
|
||||
}
|
||||
case ExprType::VARIABLE: {
|
||||
std::shared_ptr<_Variable> ptr = std::get<std::shared_ptr<_Variable>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Variable>(*ptr);
|
||||
break;
|
||||
}
|
||||
case ExprType::ASSIGN: {
|
||||
std::shared_ptr<_Assign> ptr = std::get<std::shared_ptr<_Assign>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Assign>(*ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Expr::Expr(const Expr &other) : type{other.type}, value{other.value} {}
|
||||
|
||||
// Move constructor
|
||||
Expr::Expr(Expr &&other) : type{other.type}, value{std::move(other.value)} {
|
||||
switch(type) {
|
||||
case ExprType::BINARY: {
|
||||
std::shared_ptr<_Binary> ptr = std::get<std::shared_ptr<_Binary>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::GROUPING: {
|
||||
std::shared_ptr<_Grouping> ptr = std::get<std::shared_ptr<_Grouping>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::LITERAL: {
|
||||
std::shared_ptr<_Literal> ptr = std::get<std::shared_ptr<_Literal>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::UNARY: {
|
||||
std::shared_ptr<_Unary> ptr = std::get<std::shared_ptr<_Unary>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::VARIABLE: {
|
||||
std::shared_ptr<_Variable> ptr = std::get<std::shared_ptr<_Variable>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::ASSIGN: {
|
||||
std::shared_ptr<_Assign> ptr = std::get<std::shared_ptr<_Assign>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Expr::Expr(Expr &&other) noexcept : type{other.type}, value{std::move(other.value)} {}
|
||||
|
||||
// Copy assignment
|
||||
Expr &Expr::operator=(const Expr &other) {
|
||||
@ -96,180 +16,20 @@ Expr &Expr::operator=(const Expr &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case ExprType::BINARY: {
|
||||
std::shared_ptr<_Binary> ptr = std::get<std::shared_ptr<_Binary>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::GROUPING: {
|
||||
std::shared_ptr<_Grouping> ptr = std::get<std::shared_ptr<_Grouping>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::LITERAL: {
|
||||
std::shared_ptr<_Literal> ptr = std::get<std::shared_ptr<_Literal>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::UNARY: {
|
||||
std::shared_ptr<_Unary> ptr = std::get<std::shared_ptr<_Unary>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::VARIABLE: {
|
||||
std::shared_ptr<_Variable> ptr = std::get<std::shared_ptr<_Variable>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::ASSIGN: {
|
||||
std::shared_ptr<_Assign> ptr = std::get<std::shared_ptr<_Assign>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
type = other.type;
|
||||
|
||||
switch(type) {
|
||||
case ExprType::BINARY: {
|
||||
std::shared_ptr<_Binary> ptr = std::get<std::shared_ptr<_Binary>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Binary>(*ptr);
|
||||
break;
|
||||
}
|
||||
case ExprType::GROUPING: {
|
||||
std::shared_ptr<_Grouping> ptr = std::get<std::shared_ptr<_Grouping>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Grouping>(*ptr);
|
||||
break;
|
||||
}
|
||||
case ExprType::LITERAL: {
|
||||
std::shared_ptr<_Literal> ptr = std::get<std::shared_ptr<_Literal>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Literal>(*ptr);
|
||||
break;
|
||||
}
|
||||
case ExprType::UNARY: {
|
||||
std::shared_ptr<_Unary> ptr = std::get<std::shared_ptr<_Unary>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Unary>(*ptr);
|
||||
break;
|
||||
}
|
||||
case ExprType::VARIABLE: {
|
||||
std::shared_ptr<_Variable> ptr = std::get<std::shared_ptr<_Variable>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Variable>(*ptr);
|
||||
break;
|
||||
}
|
||||
case ExprType::ASSIGN: {
|
||||
std::shared_ptr<_Assign> ptr = std::get<std::shared_ptr<_Assign>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Assign>(*ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
value = other.value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Move assignment
|
||||
Expr &Expr::operator=(Expr &&other) {
|
||||
Expr &Expr::operator=(Expr &&other) noexcept {
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case ExprType::BINARY: {
|
||||
std::shared_ptr<_Binary> ptr = std::get<std::shared_ptr<_Binary>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::GROUPING: {
|
||||
std::shared_ptr<_Grouping> ptr = std::get<std::shared_ptr<_Grouping>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::LITERAL: {
|
||||
std::shared_ptr<_Literal> ptr = std::get<std::shared_ptr<_Literal>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::UNARY: {
|
||||
std::shared_ptr<_Unary> ptr = std::get<std::shared_ptr<_Unary>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::VARIABLE: {
|
||||
std::shared_ptr<_Variable> ptr = std::get<std::shared_ptr<_Variable>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::ASSIGN: {
|
||||
std::shared_ptr<_Assign> ptr = std::get<std::shared_ptr<_Assign>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
type = other.type;
|
||||
|
||||
switch(type) {
|
||||
case ExprType::BINARY: {
|
||||
std::shared_ptr<_Binary> ptr = std::get<std::shared_ptr<_Binary>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
type = std::move(other.type);
|
||||
value = std::move(other.value);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::GROUPING: {
|
||||
std::shared_ptr<_Grouping> ptr = std::get<std::shared_ptr<_Grouping>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::move(other.value);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::LITERAL: {
|
||||
std::shared_ptr<_Literal> ptr = std::get<std::shared_ptr<_Literal>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::move(other.value);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::UNARY: {
|
||||
std::shared_ptr<_Unary> ptr = std::get<std::shared_ptr<_Unary>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::move(other.value);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::VARIABLE: {
|
||||
std::shared_ptr<_Variable> ptr = std::get<std::shared_ptr<_Variable>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::move(other.value);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case ExprType::ASSIGN: {
|
||||
std::shared_ptr<_Assign> ptr = std::get<std::shared_ptr<_Assign>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::move(other.value);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -45,13 +45,15 @@ struct Expr {
|
||||
Expr(const Expr &other);
|
||||
|
||||
// Move constructor
|
||||
Expr(Expr &&other);
|
||||
Expr(Expr &&other) noexcept;
|
||||
|
||||
// Copy assignment
|
||||
Expr &operator=(const Expr &other);
|
||||
|
||||
// Move assignment
|
||||
Expr &operator=(Expr &&other);
|
||||
Expr &operator=(Expr &&other) noexcept;
|
||||
|
||||
~Expr() = default;
|
||||
|
||||
ExprType type;
|
||||
ExprVariant value;
|
||||
|
@ -5,52 +5,10 @@
|
||||
Stmt::Stmt(StmtType type, StmtVariant value) : type{type}, value{value} {}
|
||||
|
||||
// Copy constructor
|
||||
Stmt::Stmt(const Stmt &other) : type{other.type} {
|
||||
switch(type) {
|
||||
case StmtType::EXPRESSION: {
|
||||
std::shared_ptr<_Expression> ptr = std::get<std::shared_ptr<_Expression>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Expression>(*ptr);
|
||||
break;
|
||||
}
|
||||
case StmtType::PRINT: {
|
||||
std::shared_ptr<_Print> ptr = std::get<std::shared_ptr<_Print>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Print>(*ptr);
|
||||
break;
|
||||
}
|
||||
case StmtType::VAR: {
|
||||
std::shared_ptr<_Var> ptr = std::get<std::shared_ptr<_Var>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Var>(*ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Stmt::Stmt(const Stmt &other) : type{other.type}, value{other.value} {}
|
||||
|
||||
// Move constructor
|
||||
Stmt::Stmt(const Stmt &&other) : type{other.type}, value{std::move(other.value)} {
|
||||
switch(type) {
|
||||
case StmtType::EXPRESSION: {
|
||||
std::shared_ptr<_Expression> ptr = std::get<std::shared_ptr<_Expression>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case StmtType::PRINT: {
|
||||
std::shared_ptr<_Print> ptr = std::get<std::shared_ptr<_Print>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case StmtType::VAR: {
|
||||
std::shared_ptr<_Var> ptr = std::get<std::shared_ptr<_Var>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Stmt::Stmt(Stmt &&other) noexcept : type{other.type}, value{std::move(other.value)} {}
|
||||
|
||||
// Copy assignment
|
||||
Stmt &Stmt::operator=(const Stmt &other) {
|
||||
@ -58,105 +16,20 @@ Stmt &Stmt::operator=(const Stmt &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case StmtType::EXPRESSION: {
|
||||
std::shared_ptr<_Expression> ptr = std::get<std::shared_ptr<_Expression>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case StmtType::PRINT: {
|
||||
std::shared_ptr<_Print> ptr = std::get<std::shared_ptr<_Print>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case StmtType::VAR: {
|
||||
std::shared_ptr<_Var> ptr = std::get<std::shared_ptr<_Var>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
type = other.type;
|
||||
|
||||
switch(type) {
|
||||
case StmtType::EXPRESSION: {
|
||||
std::shared_ptr<_Expression> ptr = std::get<std::shared_ptr<_Expression>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Expression>(*ptr);
|
||||
break;
|
||||
}
|
||||
case StmtType::PRINT: {
|
||||
std::shared_ptr<_Print> ptr = std::get<std::shared_ptr<_Print>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Print>(*ptr);
|
||||
break;
|
||||
}
|
||||
case StmtType::VAR: {
|
||||
std::shared_ptr<_Var> ptr = std::get<std::shared_ptr<_Var>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::make_shared<_Var>(*ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
value = other.value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Move assignment
|
||||
Stmt &Stmt::operator=(const Stmt &&other) {
|
||||
Stmt &Stmt::operator=(Stmt &&other) noexcept {
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case StmtType::EXPRESSION: {
|
||||
std::shared_ptr<_Expression> ptr = std::get<std::shared_ptr<_Expression>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case StmtType::PRINT: {
|
||||
std::shared_ptr<_Print> ptr = std::get<std::shared_ptr<_Print>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case StmtType::VAR: {
|
||||
std::shared_ptr<_Var> ptr = std::get<std::shared_ptr<_Var>>(value);
|
||||
assert(ptr != nullptr);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
type = other.type;
|
||||
|
||||
switch(type) {
|
||||
case StmtType::EXPRESSION: {
|
||||
std::shared_ptr<_Expression> ptr = std::get<std::shared_ptr<_Expression>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
type = std::move(other.type);
|
||||
value = std::move(other.value);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case StmtType::PRINT: {
|
||||
std::shared_ptr<_Print> ptr = std::get<std::shared_ptr<_Print>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::move(other.value);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
case StmtType::VAR: {
|
||||
std::shared_ptr<_Var> ptr = std::get<std::shared_ptr<_Var>>(other.value);
|
||||
assert(ptr != nullptr);
|
||||
value = std::move(other.value);
|
||||
ptr.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -33,13 +33,15 @@ struct Stmt {
|
||||
Stmt(const Stmt &other);
|
||||
|
||||
// Move constructor
|
||||
Stmt(const Stmt &&other);
|
||||
Stmt(Stmt &&other) noexcept;
|
||||
|
||||
// Copy assignment
|
||||
Stmt &operator=(const Stmt &other);
|
||||
|
||||
// Move assignment
|
||||
Stmt &operator=(const Stmt &&other);
|
||||
Stmt &operator=(Stmt &&other) noexcept;
|
||||
|
||||
~Stmt() = default;
|
||||
|
||||
StmtType type;
|
||||
StmtVariant value;
|
||||
|
Loading…
x
Reference in New Issue
Block a user