Skip to content

Commit

Permalink
Remove hack code in ArrayRange that is no longer necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ghewgill committed Mar 30, 2017
1 parent 1911a7d commit 46d3c52
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1938,13 +1938,13 @@ const ast::Expression *Analyzer::analyze(const pt::ValidPointerExpression * /*ex
const ast::Expression *Analyzer::analyze(const pt::RangeSubscriptExpression *expr)
{
const ast::Expression *base = analyze(expr->base.get());
const ast::Expression *first = analyze(expr->range->get_first());
const ast::Expression *last = analyze(expr->range->get_last());
const ast::Expression *first = analyze(expr->range->first.get());
const ast::Expression *last = analyze(expr->range->last.get());
if (not first->type->is_assignment_compatible(ast::TYPE_NUMBER)) {
error(3141, expr->range->get_first()->token, "range index must be a number");
error(3141, expr->range->first.get()->token, "range index must be a number");
}
if (not last->type->is_assignment_compatible(ast::TYPE_NUMBER)) {
error(3142, expr->range->get_last()->token, "range index must be a number");
error(3142, expr->range->last.get()->token, "range index must be a number");
}
const ast::Type *type = base->type;
const ast::TypeArray *arraytype = dynamic_cast<const ast::TypeArray *>(type);
Expand Down Expand Up @@ -2784,8 +2784,8 @@ static void deconstruct(const pt::Expression *expr, std::vector<const pt::Expres
deconstruct(ce->right.get(), parts);
} else if (re != nullptr) {
deconstruct(re->base.get(), parts);
deconstruct(re->range->get_first(), parts);
deconstruct(re->range->get_last(), parts);
deconstruct(re->range->first.get(), parts);
deconstruct(re->range->last.get(), parts);
} else if (dynamic_cast<const pt::BooleanLiteralExpression *>(expr) != nullptr
|| dynamic_cast<const pt::NumberLiteralExpression *>(expr) != nullptr
|| dynamic_cast<const pt::StringLiteralExpression *>(expr) != nullptr) {
Expand Down Expand Up @@ -4316,7 +4316,7 @@ class VariableChecker: public pt::IParseTreeVisitor {
}
virtual void visit(const pt::NewClassExpression *node) { node->expr->accept(this); }
virtual void visit(const pt::ValidPointerExpression *node) { for (auto &x: node->tests) x->expr->accept(this); }
virtual void visit(const pt::RangeSubscriptExpression *node) { node->base->accept(this); node->range->get_first()->accept(this); node->range->get_last()->accept(this); }
virtual void visit(const pt::RangeSubscriptExpression *node) { node->base->accept(this); node->range->first.get()->accept(this); node->range->last.get()->accept(this); }

virtual void visit(const pt::ImportDeclaration *) {}
virtual void visit(const pt::TypeDeclaration *) {}
Expand Down
5 changes: 2 additions & 3 deletions src/pt.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,9 @@ class ArrayRange {
public:
ArrayRange(const Token &token, std::unique_ptr<Expression> &&first, bool first_from_end, std::unique_ptr<Expression> &&last, bool last_from_end): token(token), first(std::move(first)), first_from_end(first_from_end), last(std::move(last)), last_from_end(last_from_end) {}
const Token token;
private: std::unique_ptr<Expression> first; public: Expression *get_first() { return first.get(); }
std::unique_ptr<Expression> first;
const bool first_from_end;
// TODO: This private member is a bit of a hack to support 'first' and 'last' being the same thing.
private: std::unique_ptr<Expression> last; public: Expression *get_last() { return last ? last.get() : first.get(); }
std::unique_ptr<Expression> last;
const bool last_from_end;
};

Expand Down
4 changes: 2 additions & 2 deletions src/pt_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ class Dumper: public IParseTreeVisitor {
virtual void visit(const RangeSubscriptExpression *node) override {
write("RangeSubscriptExpression");
child(node->base.get());
child(node->range->get_first());
child(node->range->get_last());
child(node->range->first.get());
child(node->range->last.get());
}

virtual void visit(const ImportDeclaration *node) override {
Expand Down

0 comments on commit 46d3c52

Please sign in to comment.