Skip to content

Commit 6238cb2

Browse files
committed
Clang-Tidy: Fix src/antlr/BaseAST.*.
1 parent 30cf8b3 commit 6238cb2

File tree

2 files changed

+40
-41
lines changed

2 files changed

+40
-41
lines changed

src/antlr/BaseAST.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,19 @@ BaseAST::BaseAST() : AST()
2525
{
2626
}
2727

28-
BaseAST::~BaseAST()
29-
{
30-
}
28+
BaseAST::~BaseAST() = default;
3129

3230
BaseAST::BaseAST(const BaseAST& other)
3331
: AST(other) // RK: don't copy links! , down(other.down), right(other.right)
3432
{
3533
}
3634

37-
const char* BaseAST::typeName( void ) const
35+
const char* BaseAST::typeName() const
3836
{
3937
return BaseAST::TYPE_NAME;
4038
}
4139

42-
RefAST BaseAST::clone( void ) const
40+
RefAST BaseAST::clone() const
4341
{
4442
ANTLR_USE_NAMESPACE(std)cerr << "BaseAST::clone()" << ANTLR_USE_NAMESPACE(std)endl;
4543
return nullAST;
@@ -81,7 +79,8 @@ size_t BaseAST::getNumberOfChildren() const
8179

8280
void BaseAST::doWorkForFindAll(
8381
ANTLR_USE_NAMESPACE(std)vector<RefAST>& v,
84-
RefAST target,bool partialMatch)
82+
const RefAST& target,
83+
bool partialMatch)
8584
{
8685
// Start walking sibling lists, looking for matches.
8786
for (RefAST sibling=this;
@@ -248,7 +247,7 @@ ANTLR_USE_NAMESPACE(std)string BaseAST::toString() const
248247

249248
ANTLR_USE_NAMESPACE(std)string BaseAST::toStringList() const
250249
{
251-
ANTLR_USE_NAMESPACE(std)string ts="";
250+
ANTLR_USE_NAMESPACE(std)string ts;
252251

253252
if (getFirstChild())
254253
{
@@ -271,7 +270,7 @@ ANTLR_USE_NAMESPACE(std)string BaseAST::toStringList() const
271270

272271
ANTLR_USE_NAMESPACE(std)string BaseAST::toStringTree() const
273272
{
274-
ANTLR_USE_NAMESPACE(std)string ts = "";
273+
ANTLR_USE_NAMESPACE(std)string ts;
275274

276275
if (getFirstChild())
277276
{
@@ -331,7 +330,7 @@ ANTLR_API RefAST nullAST;
331330
#if defined(_MSC_VER) && !defined(__ICL) // Microsoft Visual C++
332331
extern ANTLR_API AST* const nullASTptr = 0;
333332
#else
334-
ANTLR_API AST* const nullASTptr = 0;
333+
ANTLR_API AST* const nullASTptr = nullptr;
335334
#endif
336335

337336
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE

src/antlr/BaseAST.hpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef INC_BaseAST_hpp__
2-
#define INC_BaseAST_hpp__
1+
#ifndef INC_BaseAST_hpp_
2+
#define INC_BaseAST_hpp_
33

44
/* ANTLR Translator Generator
55
* Project led by Terence Parr at http://www.jGuru.com
@@ -23,100 +23,100 @@ class ANTLR_API BaseAST : public AST {
2323
BaseAST();
2424
BaseAST(const BaseAST& other);
2525

26-
virtual ~BaseAST();
26+
~BaseAST() override;
2727

2828
/// Return the class name
29-
virtual const char* typeName( void ) const;
29+
const char* typeName() const override;
3030

3131
/// Clone this AST node.
32-
virtual RefAST clone( void ) const;
32+
RefAST clone() const override;
3333

3434
/// Is node t equal to this in terms of token type and text?
35-
virtual bool equals(RefAST t) const;
35+
bool equals(RefAST t) const override;
3636

3737
/** Is t an exact structural and equals() match of this tree. The
3838
* 'this' reference is considered the start of a sibling list.
3939
*/
40-
virtual bool equalsList(RefAST t) const;
40+
bool equalsList(RefAST t) const override;
4141

4242
/** Is 't' a subtree of this list? The siblings of the root are NOT ignored.
4343
*/
44-
virtual bool equalsListPartial(RefAST t) const;
44+
bool equalsListPartial(RefAST t) const override;
4545

4646
/** Is tree rooted at 'this' equal to 't'? The siblings of 'this' are
4747
* ignored.
4848
*/
49-
virtual bool equalsTree(RefAST t) const;
49+
bool equalsTree(RefAST t) const override;
5050

5151
/** Is 't' a subtree of the tree rooted at 'this'? The siblings of
5252
* 'this' are ignored.
5353
*/
54-
virtual bool equalsTreePartial(RefAST t) const;
54+
bool equalsTreePartial(RefAST t) const override;
5555

5656
/** Walk the tree looking for all exact subtree matches. Return
5757
* an ASTEnumerator that lets the caller walk the list
5858
* of subtree roots found herein.
5959
*/
60-
virtual ANTLR_USE_NAMESPACE(std)vector<RefAST> findAll(RefAST t);
60+
ANTLR_USE_NAMESPACE(std)vector<RefAST> findAll(RefAST t) override;
6161

6262
/** Walk the tree looking for all subtrees. Return
6363
* an ASTEnumerator that lets the caller walk the list
6464
* of subtree roots found herein.
6565
*/
66-
virtual ANTLR_USE_NAMESPACE(std)vector<RefAST> findAllPartial(RefAST t);
66+
ANTLR_USE_NAMESPACE(std)vector<RefAST> findAllPartial(RefAST t) override;
6767

6868
/// Add a node to the end of the child list for this node
69-
virtual void addChild(RefAST c);
69+
void addChild(RefAST c) override;
7070
/** Get the number of child nodes of this node (shallow e.g. not of the
7171
* whole tree it spans).
7272
*/
73-
virtual size_t getNumberOfChildren() const;
73+
size_t getNumberOfChildren() const override;
7474

7575
/// Get the first child of this node; null if no children
76-
virtual RefAST getFirstChild() const
76+
RefAST getFirstChild() const override
7777
{
78-
return RefAST(down);
78+
return {down};
7979
}
8080
/// Get the next sibling in line after this one
81-
virtual RefAST getNextSibling() const
81+
RefAST getNextSibling() const override
8282
{
83-
return RefAST(right);
83+
return {right};
8484
}
8585

8686
/// Get the token text for this node
87-
virtual ANTLR_USE_NAMESPACE(std)string getText() const
87+
ANTLR_USE_NAMESPACE(std)string getText() const override
8888
{
8989
return "";
9090
}
9191
/// Get the token type for this node
92-
virtual int getType() const
92+
int getType() const override
9393
{
9494
return 0;
9595
}
9696

9797
/// Remove all children
9898
virtual void removeChildren()
9999
{
100-
down = static_cast<BaseAST*>(static_cast<AST*>(nullAST));
100+
down = dynamic_cast<BaseAST*>(static_cast<AST*>(nullAST));
101101
}
102102

103103
/// Set the first child of a node.
104-
virtual void setFirstChild(RefAST c)
104+
void setFirstChild(RefAST c) override
105105
{
106-
down = static_cast<BaseAST*>(static_cast<AST*>(c));
106+
down = dynamic_cast<BaseAST*>(static_cast<AST*>(c));
107107
}
108108

109109
/// Set the next sibling after this one.
110-
void setNextSibling(RefAST n)
110+
void setNextSibling(RefAST n) override
111111
{
112-
right = static_cast<BaseAST*>(static_cast<AST*>(n));
112+
right = dynamic_cast<BaseAST*>(static_cast<AST*>(n));
113113
}
114114

115115
/// Set the token text for this node
116-
virtual void setText(const ANTLR_USE_NAMESPACE(std)string& txt);
116+
void setText(const ANTLR_USE_NAMESPACE(std)string& txt) override;
117117

118118
/// Set the token type for this node
119-
virtual void setType(int type);
119+
void setType(int type) override;
120120

121121
#ifdef ANTLR_SUPPORT_XML
122122
/** print attributes of this node to 'out'. Override to customize XML
@@ -132,19 +132,19 @@ class ANTLR_API BaseAST : public AST {
132132
#endif
133133

134134
/// Return string representation for the AST
135-
virtual ANTLR_USE_NAMESPACE(std)string toString() const;
135+
ANTLR_USE_NAMESPACE(std)string toString() const override;
136136

137137
/// Print out a child sibling tree in LISP notation
138-
virtual ANTLR_USE_NAMESPACE(std)string toStringList() const;
139-
virtual ANTLR_USE_NAMESPACE(std)string toStringTree() const;
138+
ANTLR_USE_NAMESPACE(std)string toStringList() const override;
139+
ANTLR_USE_NAMESPACE(std)string toStringTree() const override;
140140

141141
static const char* const TYPE_NAME;
142142
protected:
143143
RefBaseAST down;
144144
RefBaseAST right;
145145
private:
146146
void doWorkForFindAll(ANTLR_USE_NAMESPACE(std)vector<RefAST>& v,
147-
RefAST target,
147+
const RefAST& target,
148148
bool partialMatch);
149149
};
150150

@@ -161,4 +161,4 @@ inline bool BaseAST::equals(RefAST t) const
161161
}
162162
#endif
163163

164-
#endif //INC_BaseAST_hpp__
164+
#endif //INC_BaseAST_hpp_

0 commit comments

Comments
 (0)