}
CYExpression *CYDeclaration::Replace(CYContext &context) {
- CYIdentifier *identifier(identifier_->Replace(context));
- context.scope_->internal_.insert(CYIdentifierAddressFlagsMap::value_type(identifier, CYIdentifierVariable));
- return $ CYVariable(identifier);
+ context.Replace(identifier_);
+ context.scope_->Declare(context, identifier_, CYIdentifierVariable);
+ return $ CYVariable(identifier_);
}
CYProperty *CYDeclarations::Property(CYContext &context) { $T(NULL)
void CYFunction::Inject(CYContext &context) {
name_ = name_->Replace(context);
- context.scope_->internal_.insert(CYIdentifierAddressFlagsMap::value_type(name_, CYIdentifierOther));
+ context.scope_->Declare(context, name_, CYIdentifierOther);
}
void CYFunction::Replace_(CYContext &context, bool outer) {
void CYFunctionParameter::Replace(CYContext &context) { $T()
name_ = name_->Replace(context);
- context.scope_->internal_.insert(CYIdentifierAddressFlagsMap::value_type(name_, CYIdentifierArgument));
+ context.scope_->Declare(context, name_, CYIdentifierArgument);
next_->Replace(context);
}
}
CYIdentifier *CYIdentifier::Replace(CYContext &context) {
- if (replace_ != NULL)
- return replace_;
-
- CYIdentifierValueSet &identifiers(context.scope_->identifiers_);
- std::pair<CYIdentifierValueSet::iterator, bool> insert(identifiers.insert(this));
- if (!insert.second)
- return *insert.first;
-
- replace_ = this;
- return this;
+ if (replace_ == NULL)
+ replace_ = context.scope_->Lookup(context, this);
+ return replace_;
}
CYStatement *CYIf::Replace(CYContext &context) {
statements_ = statements_->ReplaceAll(context);
context.scope_ = parent_;
- Scope(context, statements_);
context.program_ = program;
+ Scope(context, statements_);
size_t offset(0);
return this;
}
-void CYScope::Add(CYContext &context, CYIdentifierAddressVector &external) {
+void CYScope::Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags) {
+ internal_.insert(CYIdentifierAddressFlagsMap::value_type(identifier, flags));
+}
+
+CYIdentifier *CYScope::Lookup(CYContext &context, CYIdentifier *identifier) {
+ std::pair<CYIdentifierValueSet::iterator, bool> insert(identifiers_.insert(identifier));
+ return *insert.first;
+}
+
+void CYScope::Merge(CYContext &context, CYIdentifierAddressVector &external) {
for (CYIdentifierAddressVector::const_iterator i(external.begin()); i != external.end(); ++i) {
std::pair<CYIdentifierAddressSet::iterator, bool> insert(identifiers_.insert(*i));
if (!insert.second)
if (parent_ != NULL) {
if (parent_->offset_ < offset_)
parent_->offset_ = offset_;
- parent_->Add(context, external);
+ parent_->Merge(context, external);
} else if (program != NULL)
for (CYIdentifierAddressVector::const_iterator i(external.begin()); i != external.end(); ++i)
program->external_.insert((*i)->Word());