From b0fa45840fbc5c4ca03f99915070320abd108f08 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Tue, 26 Apr 2022 12:56:19 -0700 Subject: [PATCH] Minor code style cleanups for consistency --- ASTNode.h | 31 ++++++++++--------------------- ASTree.cpp | 8 ++++---- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/ASTNode.h b/ASTNode.h index feef017..3331467 100644 --- a/ASTNode.h +++ b/ASTNode.h @@ -691,8 +691,8 @@ public: ASTAnnotatedVar(PycRef name, PycRef type) : ASTNode(NODE_ANNOTATED_VAR), m_name(std::move(name)), m_type(std::move(type)) { } - const PycRef name() const { return m_name; } - const PycRef type() const { return m_type; } + PycRef name() const noexcept { return m_name; } + PycRef type() const noexcept { return m_type; } private: PycRef m_name; @@ -702,25 +702,14 @@ private: class ASTTernary : public ASTNode { public: - ASTTernary(PycRef if_block, PycRef if_expr, PycRef else_expr) - : ASTNode(NODE_TERNARY), - m_if_block(std::move(if_block)), - m_if_expr(std::move(if_expr)), - m_else_expr(std::move(else_expr)) - { - } - const PycRef& if_block() const noexcept - { - return m_if_block; - } - const PycRef& if_expr() const noexcept - { - return m_if_expr; - } - const PycRef& else_expr() const noexcept - { - return m_else_expr; - } + ASTTernary(PycRef if_block, PycRef if_expr, + PycRef else_expr) + : ASTNode(NODE_TERNARY), m_if_block(std::move(if_block)), + m_if_expr(std::move(if_expr)), m_else_expr(std::move(else_expr)) { } + + PycRef if_block() const noexcept { return m_if_block; } + PycRef if_expr() const noexcept { return m_if_expr; } + PycRef else_expr() const noexcept { return m_else_expr; } private: PycRef m_if_block; // contains "condition" and "negative" diff --git a/ASTree.cpp b/ASTree.cpp index 9f928fc..62bb4eb 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -53,15 +53,15 @@ static void CheckIfExpr(FastStack& stack, PycRef curblock) return; if (curblock->nodes().size() < 2) return; - auto rit{ curblock->nodes().crbegin() }; + auto rit = curblock->nodes().crbegin(); ++rit; // the last is "else" block, the one before should be "if" (could be "for", ...) if ((*rit)->type() != ASTNode::NODE_BLOCK || (*rit).cast()->blktype() != ASTBlock::BLK_IF) return; - auto else_expr{ StackPopTop(stack) }; + auto else_expr = StackPopTop(stack); curblock->removeLast(); - auto if_block{ curblock->nodes().back() }; - auto if_expr{ StackPopTop(stack) }; + auto if_block = curblock->nodes().back(); + auto if_expr = StackPopTop(stack); curblock->removeLast(); stack.push(new ASTTernary(std::move(if_block), std::move(if_expr), std::move(else_expr))); }