From 50a3d79f79a223e8a119fe7531fd0a47ebd09d45 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sat, 21 Nov 2015 01:32:33 -0800 Subject: [PATCH] Simplify CYScope's declaration by embracing Close. --- Parser.hpp | 11 ++--------- Replace.cpp | 30 +++++++++++------------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/Parser.hpp b/Parser.hpp index de8d5a5..e02a166 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -313,24 +313,17 @@ typedef std::vector CYIdentifierUsageVector; struct CYScope { bool transparent_; - - CYContext &context_; - CYStatement *&statements_; - CYScope *parent_; CYIdentifierAddressFlagsMap internal_; CYIdentifierValueSet identifiers_; - CYScope(bool transparent, CYContext &context, CYStatement *&statements); - virtual ~CYScope(); - - void Close(); + CYScope(bool transparent, CYContext &context); void Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags); virtual CYIdentifier *Lookup(CYContext &context, CYIdentifier *identifier); void Merge(CYContext &context, CYIdentifier *identifier); - void Scope(CYContext &context, CYStatement *&statements); + void Close(CYContext &context, CYStatement *&statements); }; struct CYProgram : diff --git a/Replace.cpp b/Replace.cpp index bcaffca..0f53d92 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -124,13 +124,13 @@ namespace cy { namespace Syntax { void Catch::Replace(CYContext &context) { $T() - CYScope scope(true, context, code_.statements_); + CYScope scope(true, context); context.Replace(name_); context.scope_->Declare(context, name_, CYIdentifierCatch); code_.Replace(context); - scope.Close(); + scope.Close(context, code_.statements_); } } } @@ -468,7 +468,7 @@ void CYFunction::Replace_(CYContext &context, bool outer) { context.nextlocal_ = nonlocal_; } - CYScope scope(!localize, context, code_.statements_); + CYScope scope(!localize, context); if (!outer && name_ != NULL) Inject(context); @@ -489,7 +489,7 @@ void CYFunction::Replace_(CYContext &context, bool outer) { context.this_ = _this; - scope.Close(); + scope.Close(context, code_.statements_); } CYExpression *CYFunctionExpression::Replace(CYContext &context) { @@ -651,13 +651,13 @@ namespace { } void CYProgram::Replace(CYContext &context) { - CYScope scope(true, context, statements_); + CYScope scope(true, context); context.nextlocal_ = $ CYNonLocal(); context.ReplaceAll(statements_); context.NonLocal(statements_); - scope.Close(); + scope.Close(context, statements_); size_t offset(0); @@ -734,21 +734,11 @@ CYExpression *CYRubyProc::Replace(CYContext &context) { return CYNonLocalize(context, $ CYFunctionExpression(NULL, parameters_, code_)); } -CYScope::CYScope(bool transparent, CYContext &context, CYStatement *&statements) : +CYScope::CYScope(bool transparent, CYContext &context) : transparent_(transparent), - context_(context), - statements_(statements), parent_(context.scope_) { - context_.scope_ = this; -} - -CYScope::~CYScope() { -} - -void CYScope::Close() { - context_.scope_ = parent_; - Scope(context_, statements_); + context.scope_ = this; } void CYScope::Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags) { @@ -806,7 +796,9 @@ namespace { typedef std::set IdentifierOffsets; } -void CYScope::Scope(CYContext &context, CYStatement *&statements) { +void CYScope::Close(CYContext &context, CYStatement *&statements) { + context.scope_ = parent_; + if (parent_ == NULL) return; -- 2.45.2