Skip to content

Commit 46d3c52

Browse files
committed
Remove hack code in ArrayRange that is no longer necessary
1 parent 1911a7d commit 46d3c52

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/analyzer.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1938,13 +1938,13 @@ const ast::Expression *Analyzer::analyze(const pt::ValidPointerExpression * /*ex
19381938
const ast::Expression *Analyzer::analyze(const pt::RangeSubscriptExpression *expr)
19391939
{
19401940
const ast::Expression *base = analyze(expr->base.get());
1941-
const ast::Expression *first = analyze(expr->range->get_first());
1942-
const ast::Expression *last = analyze(expr->range->get_last());
1941+
const ast::Expression *first = analyze(expr->range->first.get());
1942+
const ast::Expression *last = analyze(expr->range->last.get());
19431943
if (not first->type->is_assignment_compatible(ast::TYPE_NUMBER)) {
1944-
error(3141, expr->range->get_first()->token, "range index must be a number");
1944+
error(3141, expr->range->first.get()->token, "range index must be a number");
19451945
}
19461946
if (not last->type->is_assignment_compatible(ast::TYPE_NUMBER)) {
1947-
error(3142, expr->range->get_last()->token, "range index must be a number");
1947+
error(3142, expr->range->last.get()->token, "range index must be a number");
19481948
}
19491949
const ast::Type *type = base->type;
19501950
const ast::TypeArray *arraytype = dynamic_cast<const ast::TypeArray *>(type);
@@ -2784,8 +2784,8 @@ static void deconstruct(const pt::Expression *expr, std::vector<const pt::Expres
27842784
deconstruct(ce->right.get(), parts);
27852785
} else if (re != nullptr) {
27862786
deconstruct(re->base.get(), parts);
2787-
deconstruct(re->range->get_first(), parts);
2788-
deconstruct(re->range->get_last(), parts);
2787+
deconstruct(re->range->first.get(), parts);
2788+
deconstruct(re->range->last.get(), parts);
27892789
} else if (dynamic_cast<const pt::BooleanLiteralExpression *>(expr) != nullptr
27902790
|| dynamic_cast<const pt::NumberLiteralExpression *>(expr) != nullptr
27912791
|| dynamic_cast<const pt::StringLiteralExpression *>(expr) != nullptr) {
@@ -4316,7 +4316,7 @@ class VariableChecker: public pt::IParseTreeVisitor {
43164316
}
43174317
virtual void visit(const pt::NewClassExpression *node) { node->expr->accept(this); }
43184318
virtual void visit(const pt::ValidPointerExpression *node) { for (auto &x: node->tests) x->expr->accept(this); }
4319-
virtual void visit(const pt::RangeSubscriptExpression *node) { node->base->accept(this); node->range->get_first()->accept(this); node->range->get_last()->accept(this); }
4319+
virtual void visit(const pt::RangeSubscriptExpression *node) { node->base->accept(this); node->range->first.get()->accept(this); node->range->last.get()->accept(this); }
43204320

43214321
virtual void visit(const pt::ImportDeclaration *) {}
43224322
virtual void visit(const pt::TypeDeclaration *) {}

src/pt.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,9 @@ class ArrayRange {
593593
public:
594594
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) {}
595595
const Token token;
596-
private: std::unique_ptr<Expression> first; public: Expression *get_first() { return first.get(); }
596+
std::unique_ptr<Expression> first;
597597
const bool first_from_end;
598-
// TODO: This private member is a bit of a hack to support 'first' and 'last' being the same thing.
599-
private: std::unique_ptr<Expression> last; public: Expression *get_last() { return last ? last.get() : first.get(); }
598+
std::unique_ptr<Expression> last;
600599
const bool last_from_end;
601600
};
602601

src/pt_dump.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ class Dumper: public IParseTreeVisitor {
229229
virtual void visit(const RangeSubscriptExpression *node) override {
230230
write("RangeSubscriptExpression");
231231
child(node->base.get());
232-
child(node->range->get_first());
233-
child(node->range->get_last());
232+
child(node->range->first.get());
233+
child(node->range->last.get());
234234
}
235235

236236
virtual void visit(const ImportDeclaration *node) override {

0 commit comments

Comments
 (0)