Skip to content

Commit 73c9948

Browse files
author
Borja Lorente
committed
Remove some more crud
1 parent 454073d commit 73c9948

File tree

12 files changed

+3
-67
lines changed

12 files changed

+3
-67
lines changed

interpreter/src/core/model/ast/Statement.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ class Statement {
2222
int _line;
2323
int _col;
2424
bool _stoppable;
25-
int _nextLine;
2625

2726
public:
2827

29-
Statement() : _line{-1}, _col{-1}, _stoppable{false}, _nextLine{-1} {}
30-
Statement(int line, int col) : _line{line}, _col{col}, _stoppable{false}, _nextLine{-1} {}
28+
Statement() : _line{-1}, _col{-1}, _stoppable{false}{}
29+
Statement(int line, int col) : _line{line}, _col{col}, _stoppable{false}{}
3130

3231
virtual void accept(Evaluator &evaluator) = 0;
3332

@@ -36,9 +35,6 @@ class Statement {
3635

3736
bool stoppable() {return _stoppable;}
3837
void makeStoppable() {_stoppable = true;}
39-
40-
virtual void setLastLine(int line) {_nextLine = line;}
41-
int lastLine() const {return _nextLine;}
4238
};
4339

4440
}

interpreter/src/core/model/ast/declarations/ConstantDeclaration.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,4 @@ const std::string & ConstantDeclaration::name() const {
2424
ExpressionPtr ConstantDeclaration::value() const {
2525
return _value;
2626
}
27-
28-
void ConstantDeclaration::setLastLine(int line) {
29-
Statement::setLastLine(line);
30-
_value->setLastLine(line);
31-
}
32-
3327
}

interpreter/src/core/model/ast/declarations/ConstantDeclaration.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class ConstantDeclaration : public Declaration {
3131
const std::string &name() const;
3232

3333
ExpressionPtr value() const;
34-
35-
void setLastLine(int line) override;
3634
};
3735

3836
} // end namespace naylang

interpreter/src/core/model/ast/declarations/MethodDeclaration.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,4 @@ const std::vector<DeclarationPtr> &MethodDeclaration::params() const {
3131
return _params;
3232
}
3333

34-
void MethodDeclaration::setLastLine(int line) {
35-
Statement::setLastLine(line);
36-
_body.back()->setLastLine(line);
37-
}
3834
}

interpreter/src/core/model/ast/declarations/MethodDeclaration.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class MethodDeclaration : public Declaration {
3535
const std::string &name() const override;
3636
const std::vector<DeclarationPtr> &params() const;
3737
const std::vector<StatementPtr> &body() const;
38-
39-
void setLastLine(int line) override;
4038
};
4139

4240
} // end namespace naylang

interpreter/src/core/model/ast/declarations/VariableDeclaration.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,4 @@ const ExpressionPtr &VariableDeclaration::value() const {
3232
return _initialValue;
3333
}
3434

35-
void VariableDeclaration::setLastLine(int line) {
36-
Statement::setLastLine(line);
37-
_initialValue->setLastLine(line);
38-
}
39-
4035
}

interpreter/src/core/model/ast/declarations/VariableDeclaration.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class VariableDeclaration : public Declaration {
2828
const std::string &name() const;
2929
const ExpressionPtr &value() const;
3030

31-
void setLastLine(int line) override;
3231
};
3332

3433
}

interpreter/src/core/model/ast/expressions/ObjectConstructor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,4 @@ const std::vector<StatementPtr> &ObjectConstructor::statements() const {
2424
return _statements;
2525
}
2626

27-
void ObjectConstructor::setLastLine(int line) {
28-
Statement::setLastLine(line);
29-
_statements.back()->setLastLine(line);
30-
}
3127
}

interpreter/src/core/model/ast/expressions/ObjectConstructor.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ class ObjectConstructor : public Expression {
1919
ObjectConstructor(const std::vector<StatementPtr> &statements);
2020

2121
virtual void accept(Evaluator &evaluator);
22-
23-
void setLastLine(int line) override;
24-
22+
2523
const std::vector<StatementPtr> &statements() const;
2624
};
2725
} // end namespace naylang

interpreter/src/core/parser/NaylangParserVisitor.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ antlrcpp::Any NaylangParserVisitor::visitPrefixExp(GraceParser::PrefixExpContext
7878
ctx->rec->accept(this);
7979
auto rec = popPartialExp();
8080
auto req = make_node<ExplicitRequestNode>(opname, rec, getLine(ctx), getCol(ctx));
81-
req->setLastLine(getLastLine(ctx));
8281
pushPartialExp(req);
8382
return 0;
8483
}
@@ -87,7 +86,6 @@ antlrcpp::Any NaylangParserVisitor::visitPrefixExp(GraceParser::PrefixExpContext
8786
antlrcpp::Any NaylangParserVisitor::visitNumber(GraceParser::NumberContext *ctx) {
8887
int lastLine = ctx->stop->getLine();
8988
auto num = make_node<NumberLiteral>(std::stod(ctx->getText()), getLine(ctx), getCol(ctx));
90-
num->setLastLine(lastLine);
9189
pushPartialExp(num);
9290
return 0;
9391
}
@@ -99,7 +97,6 @@ antlrcpp::Any NaylangParserVisitor::visitMulDivExp(GraceParser::MulDivExpContext
9997
auto op = ctx->op->getText() + "(_)";
10098
std::vector<ExpressionPtr> params{param};
10199
auto req = make_node<ExplicitRequestNode>(op, reciever, params, getLine(ctx), getCol(ctx));
102-
req->setLastLine(getLastLine(ctx));
103100
pushPartialExp(req);
104101
return 0;
105102
}
@@ -112,23 +109,20 @@ antlrcpp::Any NaylangParserVisitor::visitAddSubExp(GraceParser::AddSubExpContext
112109
auto op = ctx->op->getText() + "(_)";
113110
std::vector<ExpressionPtr> params{param};
114111
auto req = make_node<ExplicitRequestNode>(op, reciever, params, getLine(ctx), getCol(ctx));
115-
req->setLastLine(getLastLine(ctx));
116112
pushPartialExp(req);
117113
return 0;
118114
}
119115

120116
antlrcpp::Any NaylangParserVisitor::visitString(GraceParser::StringContext *ctx) {
121117
auto contents = ctx->content->getText();
122118
auto str = make_node<StringLiteral>(contents, getLine(ctx), getCol(ctx));
123-
str->setLastLine(getLastLine(ctx));
124119
pushPartialExp(str);
125120
return 0;
126121
}
127122

128123
antlrcpp::Any NaylangParserVisitor::visitBoolean(GraceParser::BooleanContext *ctx) {
129124
bool value = ctx->TRUE() != nullptr;
130125
auto bul = make_node<BooleanLiteral>(value, getLine(ctx), getCol(ctx));
131-
bul->setLastLine(getLastLine(ctx));
132126
pushPartialExp(bul);
133127
return 0;
134128
}
@@ -140,7 +134,6 @@ antlrcpp::Any NaylangParserVisitor::visitConstantDeclaration(GraceParser::Consta
140134
ctx->expression()->accept(this);
141135
auto value = popPartialExp();
142136
auto decl = make_node<ConstantDeclaration>(name, value, getLine(ctx), getCol(ctx));
143-
decl->setLastLine(lastLine);
144137
notifyBreakable(decl);
145138
pushPartialDecl(decl);
146139
return 0;
@@ -158,7 +151,6 @@ antlrcpp::Any NaylangParserVisitor::visitVariableDeclaration(GraceParser::Variab
158151
ctx->expression()->accept(this);
159152
auto value = popPartialExp();
160153
auto decl = make_node<VariableDeclaration>(name, value, getLine(ctx), getCol(ctx));
161-
decl->setLastLine(lastLine);
162154
notifyBreakable(decl);
163155
pushPartialDecl(decl);
164156
return 0;
@@ -186,7 +178,6 @@ antlrcpp::Any NaylangParserVisitor::visitUserMethod(GraceParser::UserMethodConte
186178
}
187179

188180
auto methodDeclaration = make_node<MethodDeclaration>(methodName, formalParams, body, getLine(ctx), getCol(ctx));
189-
methodDeclaration->setLastLine(getLastLine(ctx));
190181
pushPartialDecl(methodDeclaration);
191182
return 0;
192183
}

tests/src/core/model/ast/Statement_test.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,4 @@ TEST_CASE("Statements", "[AST]") {
3030
node->makeStoppable();
3131
REQUIRE(node->stoppable());
3232
}
33-
34-
SECTION("A Statement has the line number of the last line") {
35-
StatementPtr node = make_node<NumberLiteral>(0.0);
36-
REQUIRE(!node->stoppable());
37-
node->setLastLine(1337);
38-
REQUIRE(node->lastLine() == 1337);
39-
}
4033
}

tests/src/core/parser/NaylangParserVisitor_test.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -304,24 +304,6 @@ TEST_CASE("Stoppable nodes", "[Naylang Parser Visitor]") {
304304
REQUIRE(line->stoppable());
305305
}
306306
}
307-
308-
SECTION("Every stoppable node has a lastLine") {
309-
auto AST = translate("def obj = object {\ndef v1 = 1;\nvar v2 := 2;\nmethod add(n) {\n var m1 := n;\n}\n};");
310-
auto decl = static_cast<ConstantDeclaration &>(*(AST[0]));
311-
auto obj = static_cast<ObjectConstructor &>(*(decl.value()));
312-
REQUIRE(decl.line() == 1);
313-
REQUIRE(obj.statements()[0]->line() == 2);
314-
REQUIRE(obj.statements()[0]->lastLine() == 2);
315-
REQUIRE(obj.statements()[1]->line() == 3);
316-
REQUIRE(obj.statements()[1]->lastLine() == 3);
317-
REQUIRE(obj.statements()[2]->line() == 4);
318-
REQUIRE(obj.statements()[2]->lastLine() == 7);
319-
REQUIRE(decl.lastLine() == 7);
320-
321-
SECTION("The last line of the last stoppable inside a container is the last line of the container") {
322-
REQUIRE(obj.statements().back()->lastLine() == obj.lastLine());
323-
}
324-
}
325307
}
326308

327309
GraceAST translate(std::string line) {

0 commit comments

Comments
 (0)