Minor code style cleanups for consistency

This commit is contained in:
Michael Hansen
2022-04-26 12:56:19 -07:00
parent 73ff7ef3fe
commit b0fa45840f
2 changed files with 14 additions and 25 deletions

View File

@@ -691,8 +691,8 @@ public:
ASTAnnotatedVar(PycRef<ASTNode> name, PycRef<ASTNode> type)
: ASTNode(NODE_ANNOTATED_VAR), m_name(std::move(name)), m_type(std::move(type)) { }
const PycRef<ASTNode> name() const { return m_name; }
const PycRef<ASTNode> type() const { return m_type; }
PycRef<ASTNode> name() const noexcept { return m_name; }
PycRef<ASTNode> type() const noexcept { return m_type; }
private:
PycRef<ASTNode> m_name;
@@ -702,25 +702,14 @@ private:
class ASTTernary : public ASTNode
{
public:
ASTTernary(PycRef<ASTNode> if_block, PycRef<ASTNode> if_expr, PycRef<ASTNode> 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<ASTNode>& if_block() const noexcept
{
return m_if_block;
}
const PycRef<ASTNode>& if_expr() const noexcept
{
return m_if_expr;
}
const PycRef<ASTNode>& else_expr() const noexcept
{
return m_else_expr;
}
ASTTernary(PycRef<ASTNode> if_block, PycRef<ASTNode> if_expr,
PycRef<ASTNode> 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<ASTNode> if_block() const noexcept { return m_if_block; }
PycRef<ASTNode> if_expr() const noexcept { return m_if_expr; }
PycRef<ASTNode> else_expr() const noexcept { return m_else_expr; }
private:
PycRef<ASTNode> m_if_block; // contains "condition" and "negative"

View File

@@ -53,15 +53,15 @@ static void CheckIfExpr(FastStack& stack, PycRef<ASTBlock> 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<ASTBlock>()->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)));
}