| 358 | } |
| 359 | |
| 360 | string Scope::Impl::GetUniqueName(const string& prefix, |
| 361 | bool check_single_use) const { |
| 362 | if (check_single_use && single_use_scope()) { |
| 363 | if (*scope_used_) { |
| 364 | *status_ = |
| 365 | errors::AlreadyExists(prefix, " already exists in the current scope"); |
| 366 | return ""; |
| 367 | } |
| 368 | *scope_used_ = true; |
| 369 | return prefix; |
| 370 | } |
| 371 | auto entry = name_map_->find(prefix); |
| 372 | if (entry == name_map_->end()) { |
| 373 | name_map_->insert({prefix, 0}); |
| 374 | return prefix; |
| 375 | } |
| 376 | string unique_name; |
| 377 | do { |
| 378 | unique_name = strings::StrCat(prefix, kSuffixSeparator, ++entry->second); |
| 379 | } while (name_map_->find(unique_name) != name_map_->end()); |
| 380 | name_map_->insert({unique_name, 0}); |
| 381 | return unique_name; |
| 382 | } |
| 383 | |
| 384 | string Scope::Impl::GetNameForOp(const string& default_name) const { |
| 385 | const string unique_name = |
no test coverage detected