|
|
|
@ -434,14 +434,14 @@ struct PointerStringPairHash { |
|
|
|
|
|
|
|
|
|
const Symbol kNullSymbol; |
|
|
|
|
|
|
|
|
|
typedef HASH_MAP<const char*, Symbol, HASH_FXN<const char*>, streq> |
|
|
|
|
typedef HASH_MAP<StringPiece, Symbol, HASH_FXN<StringPiece>> |
|
|
|
|
SymbolsByNameMap; |
|
|
|
|
|
|
|
|
|
typedef HASH_MAP<PointerStringPair, Symbol, PointerStringPairHash> |
|
|
|
|
SymbolsByParentMap; |
|
|
|
|
|
|
|
|
|
typedef HASH_MAP<const char*, const FileDescriptor*, HASH_FXN<const char*>, |
|
|
|
|
streq> |
|
|
|
|
typedef HASH_MAP<StringPiece, const FileDescriptor*, |
|
|
|
|
HASH_FXN<StringPiece>> |
|
|
|
|
FilesByNameMap; |
|
|
|
|
|
|
|
|
|
typedef HASH_MAP<PointerStringPair, const FieldDescriptor*, |
|
|
|
@ -576,16 +576,16 @@ class DescriptorPool::Tables { |
|
|
|
|
|
|
|
|
|
// Find symbols. This returns a null Symbol (symbol.IsNull() is true)
|
|
|
|
|
// if not found.
|
|
|
|
|
inline Symbol FindSymbol(const std::string& key) const; |
|
|
|
|
inline Symbol FindSymbol(StringPiece key) const; |
|
|
|
|
|
|
|
|
|
// This implements the body of DescriptorPool::Find*ByName(). It should
|
|
|
|
|
// really be a private method of DescriptorPool, but that would require
|
|
|
|
|
// declaring Symbol in descriptor.h, which would drag all kinds of other
|
|
|
|
|
// stuff into the header. Yay C++.
|
|
|
|
|
Symbol FindByNameHelper(const DescriptorPool* pool, const std::string& name); |
|
|
|
|
Symbol FindByNameHelper(const DescriptorPool* pool, StringPiece name); |
|
|
|
|
|
|
|
|
|
// These return nullptr if not found.
|
|
|
|
|
inline const FileDescriptor* FindFile(const std::string& key) const; |
|
|
|
|
inline const FileDescriptor* FindFile(StringPiece key) const; |
|
|
|
|
inline const FieldDescriptor* FindExtension(const Descriptor* extendee, |
|
|
|
|
int number) const; |
|
|
|
|
inline void FindAllExtensions(const Descriptor* extendee, |
|
|
|
@ -619,7 +619,7 @@ class DescriptorPool::Tables { |
|
|
|
|
|
|
|
|
|
// Allocate a string which will be destroyed when the pool is destroyed.
|
|
|
|
|
// The string is initialized to the given value for convenience.
|
|
|
|
|
std::string* AllocateString(const std::string& value); |
|
|
|
|
std::string* AllocateString(StringPiece value); |
|
|
|
|
|
|
|
|
|
// Allocate empty string which will be destroyed when the pool is destroyed.
|
|
|
|
|
std::string* AllocateEmptyString(); |
|
|
|
@ -715,9 +715,9 @@ class FileDescriptorTables { |
|
|
|
|
inline const FieldDescriptor* FindFieldByNumber(const Descriptor* parent, |
|
|
|
|
int number) const; |
|
|
|
|
inline const FieldDescriptor* FindFieldByLowercaseName( |
|
|
|
|
const void* parent, const std::string& lowercase_name) const; |
|
|
|
|
const void* parent, StringPiece lowercase_name) const; |
|
|
|
|
inline const FieldDescriptor* FindFieldByCamelcaseName( |
|
|
|
|
const void* parent, const std::string& camelcase_name) const; |
|
|
|
|
const void* parent, StringPiece camelcase_name) const; |
|
|
|
|
inline const EnumValueDescriptor* FindEnumValueByNumber( |
|
|
|
|
const EnumDescriptor* parent, int number) const; |
|
|
|
|
// This creates a new EnumValueDescriptor if not found, in a thread-safe way.
|
|
|
|
@ -884,8 +884,8 @@ void DescriptorPool::Tables::RollbackToLastCheckpoint() { |
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
inline Symbol DescriptorPool::Tables::FindSymbol(const std::string& key) const { |
|
|
|
|
const Symbol* result = FindOrNull(symbols_by_name_, key.c_str()); |
|
|
|
|
inline Symbol DescriptorPool::Tables::FindSymbol(StringPiece key) const { |
|
|
|
|
const Symbol* result = FindOrNull(symbols_by_name_, key); |
|
|
|
|
if (result == nullptr) { |
|
|
|
|
return kNullSymbol; |
|
|
|
|
} else { |
|
|
|
@ -912,7 +912,7 @@ inline Symbol FileDescriptorTables::FindNestedSymbolOfType( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Symbol DescriptorPool::Tables::FindByNameHelper(const DescriptorPool* pool, |
|
|
|
|
const std::string& name) { |
|
|
|
|
StringPiece name) { |
|
|
|
|
if (pool->mutex_ != nullptr) { |
|
|
|
|
// Fast path: the Symbol is already cached. This is just a hash lookup.
|
|
|
|
|
ReaderMutexLock lock(pool->mutex_); |
|
|
|
@ -944,8 +944,8 @@ Symbol DescriptorPool::Tables::FindByNameHelper(const DescriptorPool* pool, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline const FileDescriptor* DescriptorPool::Tables::FindFile( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
return FindPtrOrNull(files_by_name_, key.c_str()); |
|
|
|
|
StringPiece key) const { |
|
|
|
|
return FindPtrOrNull(files_by_name_, key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline const FieldDescriptor* FileDescriptorTables::FindFieldByNumber( |
|
|
|
@ -982,12 +982,12 @@ void FileDescriptorTables::FieldsByLowercaseNamesLazyInitInternal() const { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline const FieldDescriptor* FileDescriptorTables::FindFieldByLowercaseName( |
|
|
|
|
const void* parent, const std::string& lowercase_name) const { |
|
|
|
|
const void* parent, StringPiece lowercase_name) const { |
|
|
|
|
internal::call_once( |
|
|
|
|
fields_by_lowercase_name_once_, |
|
|
|
|
&FileDescriptorTables::FieldsByLowercaseNamesLazyInitStatic, this); |
|
|
|
|
return FindPtrOrNull(fields_by_lowercase_name_, |
|
|
|
|
PointerStringPair(parent, lowercase_name.c_str())); |
|
|
|
|
PointerStringPair(parent, lowercase_name)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic( |
|
|
|
@ -1006,12 +1006,12 @@ void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitInternal() const { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline const FieldDescriptor* FileDescriptorTables::FindFieldByCamelcaseName( |
|
|
|
|
const void* parent, const std::string& camelcase_name) const { |
|
|
|
|
const void* parent, StringPiece camelcase_name) const { |
|
|
|
|
internal::call_once( |
|
|
|
|
fields_by_camelcase_name_once_, |
|
|
|
|
FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic, this); |
|
|
|
|
return FindPtrOrNull(fields_by_camelcase_name_, |
|
|
|
|
PointerStringPair(parent, camelcase_name.c_str())); |
|
|
|
|
PointerStringPair(parent, camelcase_name)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline const EnumValueDescriptor* FileDescriptorTables::FindEnumValueByNumber( |
|
|
|
@ -1181,7 +1181,7 @@ Type* DescriptorPool::Tables::AllocateArray(int count) { |
|
|
|
|
return reinterpret_cast<Type*>(AllocateBytes(sizeof(Type) * count)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string* DescriptorPool::Tables::AllocateString(const std::string& value) { |
|
|
|
|
std::string* DescriptorPool::Tables::AllocateString(StringPiece value) { |
|
|
|
|
std::string* result = new std::string(value); |
|
|
|
|
strings_.emplace_back(result); |
|
|
|
|
return result; |
|
|
|
@ -1293,16 +1293,16 @@ void DescriptorPool::InternalDontEnforceDependencies() { |
|
|
|
|
enforce_dependencies_ = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DescriptorPool::AddUnusedImportTrackFile(const std::string& file_name, |
|
|
|
|
void DescriptorPool::AddUnusedImportTrackFile(ConstStringParam file_name, |
|
|
|
|
bool is_error) { |
|
|
|
|
unused_import_track_files_[file_name] = is_error; |
|
|
|
|
unused_import_track_files_[std::string(file_name)] = is_error; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DescriptorPool::ClearUnusedImportTrackFiles() { |
|
|
|
|
unused_import_track_files_.clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool DescriptorPool::InternalIsFileLoaded(const std::string& filename) const { |
|
|
|
|
bool DescriptorPool::InternalIsFileLoaded(ConstStringParam filename) const { |
|
|
|
|
MutexLockMaybe lock(mutex_); |
|
|
|
|
return tables_->FindFile(filename) != nullptr; |
|
|
|
|
} |
|
|
|
@ -1379,7 +1379,7 @@ void DescriptorPool::InternalAddGeneratedFile( |
|
|
|
|
// there's nothing more important to do (read: never).
|
|
|
|
|
|
|
|
|
|
const FileDescriptor* DescriptorPool::FindFileByName( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
ConstStringParam name) const { |
|
|
|
|
MutexLockMaybe lock(mutex_); |
|
|
|
|
if (fallback_database_ != nullptr) { |
|
|
|
|
tables_->known_bad_symbols_.clear(); |
|
|
|
@ -1399,7 +1399,7 @@ const FileDescriptor* DescriptorPool::FindFileByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FileDescriptor* DescriptorPool::FindFileContainingSymbol( |
|
|
|
|
const std::string& symbol_name) const { |
|
|
|
|
ConstStringParam symbol_name) const { |
|
|
|
|
MutexLockMaybe lock(mutex_); |
|
|
|
|
if (fallback_database_ != nullptr) { |
|
|
|
|
tables_->known_bad_symbols_.clear(); |
|
|
|
@ -1420,13 +1420,13 @@ const FileDescriptor* DescriptorPool::FindFileContainingSymbol( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const Descriptor* DescriptorPool::FindMessageTypeByName( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
ConstStringParam name) const { |
|
|
|
|
Symbol result = tables_->FindByNameHelper(this, name); |
|
|
|
|
return (result.type == Symbol::MESSAGE) ? result.descriptor : nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* DescriptorPool::FindFieldByName( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
ConstStringParam name) const { |
|
|
|
|
Symbol result = tables_->FindByNameHelper(this, name); |
|
|
|
|
if (result.type == Symbol::FIELD && |
|
|
|
|
!result.field_descriptor->is_extension()) { |
|
|
|
@ -1437,7 +1437,7 @@ const FieldDescriptor* DescriptorPool::FindFieldByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* DescriptorPool::FindExtensionByName( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
ConstStringParam name) const { |
|
|
|
|
Symbol result = tables_->FindByNameHelper(this, name); |
|
|
|
|
if (result.type == Symbol::FIELD && result.field_descriptor->is_extension()) { |
|
|
|
|
return result.field_descriptor; |
|
|
|
@ -1447,32 +1447,32 @@ const FieldDescriptor* DescriptorPool::FindExtensionByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const OneofDescriptor* DescriptorPool::FindOneofByName( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
ConstStringParam name) const { |
|
|
|
|
Symbol result = tables_->FindByNameHelper(this, name); |
|
|
|
|
return (result.type == Symbol::ONEOF) ? result.oneof_descriptor : nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const EnumDescriptor* DescriptorPool::FindEnumTypeByName( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
ConstStringParam name) const { |
|
|
|
|
Symbol result = tables_->FindByNameHelper(this, name); |
|
|
|
|
return (result.type == Symbol::ENUM) ? result.enum_descriptor : nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const EnumValueDescriptor* DescriptorPool::FindEnumValueByName( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
ConstStringParam name) const { |
|
|
|
|
Symbol result = tables_->FindByNameHelper(this, name); |
|
|
|
|
return (result.type == Symbol::ENUM_VALUE) ? result.enum_value_descriptor |
|
|
|
|
: nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const ServiceDescriptor* DescriptorPool::FindServiceByName( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
ConstStringParam name) const { |
|
|
|
|
Symbol result = tables_->FindByNameHelper(this, name); |
|
|
|
|
return (result.type == Symbol::SERVICE) ? result.service_descriptor : nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const MethodDescriptor* DescriptorPool::FindMethodByName( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
ConstStringParam name) const { |
|
|
|
|
Symbol result = tables_->FindByNameHelper(this, name); |
|
|
|
|
return (result.type == Symbol::METHOD) ? result.method_descriptor : nullptr; |
|
|
|
|
} |
|
|
|
@ -1529,7 +1529,7 @@ const FieldDescriptor* DescriptorPool::InternalFindExtensionByNumberNoLock( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* DescriptorPool::FindExtensionByPrintableName( |
|
|
|
|
const Descriptor* extendee, const std::string& printable_name) const { |
|
|
|
|
const Descriptor* extendee, ConstStringParam printable_name) const { |
|
|
|
|
if (extendee->extension_range_count() == 0) return nullptr; |
|
|
|
|
const FieldDescriptor* result = FindExtensionByName(printable_name); |
|
|
|
|
if (result != nullptr && result->containing_type() == extendee) { |
|
|
|
@ -1600,7 +1600,7 @@ const FieldDescriptor* Descriptor::FindFieldByNumber(int key) const { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* Descriptor::FindFieldByLowercaseName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
const FieldDescriptor* result = |
|
|
|
|
file()->tables_->FindFieldByLowercaseName(this, key); |
|
|
|
|
if (result == nullptr || result->is_extension()) { |
|
|
|
@ -1611,7 +1611,7 @@ const FieldDescriptor* Descriptor::FindFieldByLowercaseName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* Descriptor::FindFieldByCamelcaseName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
const FieldDescriptor* result = |
|
|
|
|
file()->tables_->FindFieldByCamelcaseName(this, key); |
|
|
|
|
if (result == nullptr || result->is_extension()) { |
|
|
|
@ -1621,8 +1621,7 @@ const FieldDescriptor* Descriptor::FindFieldByCamelcaseName( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* Descriptor::FindFieldByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
const FieldDescriptor* Descriptor::FindFieldByName(ConstStringParam key) const { |
|
|
|
|
Symbol result = |
|
|
|
|
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::FIELD); |
|
|
|
|
if (!result.IsNull() && !result.field_descriptor->is_extension()) { |
|
|
|
@ -1632,8 +1631,7 @@ const FieldDescriptor* Descriptor::FindFieldByName( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const OneofDescriptor* Descriptor::FindOneofByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
const OneofDescriptor* Descriptor::FindOneofByName(ConstStringParam key) const { |
|
|
|
|
Symbol result = |
|
|
|
|
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::ONEOF); |
|
|
|
|
if (!result.IsNull()) { |
|
|
|
@ -1644,7 +1642,7 @@ const OneofDescriptor* Descriptor::FindOneofByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* Descriptor::FindExtensionByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
Symbol result = |
|
|
|
|
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::FIELD); |
|
|
|
|
if (!result.IsNull() && result.field_descriptor->is_extension()) { |
|
|
|
@ -1655,7 +1653,7 @@ const FieldDescriptor* Descriptor::FindExtensionByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* Descriptor::FindExtensionByLowercaseName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
const FieldDescriptor* result = |
|
|
|
|
file()->tables_->FindFieldByLowercaseName(this, key); |
|
|
|
|
if (result == nullptr || !result->is_extension()) { |
|
|
|
@ -1666,7 +1664,7 @@ const FieldDescriptor* Descriptor::FindExtensionByLowercaseName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* Descriptor::FindExtensionByCamelcaseName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
const FieldDescriptor* result = |
|
|
|
|
file()->tables_->FindFieldByCamelcaseName(this, key); |
|
|
|
|
if (result == nullptr || !result->is_extension()) { |
|
|
|
@ -1676,8 +1674,7 @@ const FieldDescriptor* Descriptor::FindExtensionByCamelcaseName( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const Descriptor* Descriptor::FindNestedTypeByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
const Descriptor* Descriptor::FindNestedTypeByName(ConstStringParam key) const { |
|
|
|
|
Symbol result = |
|
|
|
|
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::MESSAGE); |
|
|
|
|
if (!result.IsNull()) { |
|
|
|
@ -1688,7 +1685,7 @@ const Descriptor* Descriptor::FindNestedTypeByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const EnumDescriptor* Descriptor::FindEnumTypeByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
Symbol result = |
|
|
|
|
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::ENUM); |
|
|
|
|
if (!result.IsNull()) { |
|
|
|
@ -1699,7 +1696,7 @@ const EnumDescriptor* Descriptor::FindEnumTypeByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const EnumValueDescriptor* Descriptor::FindEnumValueByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
Symbol result = |
|
|
|
|
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::ENUM_VALUE); |
|
|
|
|
if (!result.IsNull()) { |
|
|
|
@ -1742,7 +1739,7 @@ const EnumValueDescriptor* EnumDescriptor::FindValueByNumberCreatingIfUnknown( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const MethodDescriptor* ServiceDescriptor::FindMethodByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
Symbol result = |
|
|
|
|
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::METHOD); |
|
|
|
|
if (!result.IsNull()) { |
|
|
|
@ -1753,7 +1750,7 @@ const MethodDescriptor* ServiceDescriptor::FindMethodByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const Descriptor* FileDescriptor::FindMessageTypeByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
Symbol result = tables_->FindNestedSymbolOfType(this, key, Symbol::MESSAGE); |
|
|
|
|
if (!result.IsNull()) { |
|
|
|
|
return result.descriptor; |
|
|
|
@ -1763,7 +1760,7 @@ const Descriptor* FileDescriptor::FindMessageTypeByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const EnumDescriptor* FileDescriptor::FindEnumTypeByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
Symbol result = tables_->FindNestedSymbolOfType(this, key, Symbol::ENUM); |
|
|
|
|
if (!result.IsNull()) { |
|
|
|
|
return result.enum_descriptor; |
|
|
|
@ -1773,7 +1770,7 @@ const EnumDescriptor* FileDescriptor::FindEnumTypeByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const EnumValueDescriptor* FileDescriptor::FindEnumValueByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
Symbol result = |
|
|
|
|
tables_->FindNestedSymbolOfType(this, key, Symbol::ENUM_VALUE); |
|
|
|
|
if (!result.IsNull()) { |
|
|
|
@ -1784,7 +1781,7 @@ const EnumValueDescriptor* FileDescriptor::FindEnumValueByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const ServiceDescriptor* FileDescriptor::FindServiceByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
Symbol result = tables_->FindNestedSymbolOfType(this, key, Symbol::SERVICE); |
|
|
|
|
if (!result.IsNull()) { |
|
|
|
|
return result.service_descriptor; |
|
|
|
@ -1794,7 +1791,7 @@ const ServiceDescriptor* FileDescriptor::FindServiceByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* FileDescriptor::FindExtensionByName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
Symbol result = tables_->FindNestedSymbolOfType(this, key, Symbol::FIELD); |
|
|
|
|
if (!result.IsNull() && result.field_descriptor->is_extension()) { |
|
|
|
|
return result.field_descriptor; |
|
|
|
@ -1804,7 +1801,7 @@ const FieldDescriptor* FileDescriptor::FindExtensionByName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* FileDescriptor::FindExtensionByLowercaseName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
const FieldDescriptor* result = tables_->FindFieldByLowercaseName(this, key); |
|
|
|
|
if (result == nullptr || !result->is_extension()) { |
|
|
|
|
return nullptr; |
|
|
|
@ -1814,7 +1811,7 @@ const FieldDescriptor* FileDescriptor::FindExtensionByLowercaseName( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* FileDescriptor::FindExtensionByCamelcaseName( |
|
|
|
|
const std::string& key) const { |
|
|
|
|
ConstStringParam key) const { |
|
|
|
|
const FieldDescriptor* result = tables_->FindFieldByCamelcaseName(this, key); |
|
|
|
|
if (result == nullptr || !result->is_extension()) { |
|
|
|
|
return nullptr; |
|
|
|
@ -1871,22 +1868,23 @@ EnumDescriptor::FindReservedRangeContainingNumber(int number) const { |
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
bool DescriptorPool::TryFindFileInFallbackDatabase( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
StringPiece name) const { |
|
|
|
|
if (fallback_database_ == nullptr) return false; |
|
|
|
|
|
|
|
|
|
if (tables_->known_bad_files_.count(name) > 0) return false; |
|
|
|
|
auto name_string = std::string(name); |
|
|
|
|
if (tables_->known_bad_files_.count(name_string) > 0) return false; |
|
|
|
|
|
|
|
|
|
FileDescriptorProto file_proto; |
|
|
|
|
if (!fallback_database_->FindFileByName(name, &file_proto) || |
|
|
|
|
if (!fallback_database_->FindFileByName(name_string, &file_proto) || |
|
|
|
|
BuildFileFromDatabase(file_proto) == nullptr) { |
|
|
|
|
tables_->known_bad_files_.insert(name); |
|
|
|
|
tables_->known_bad_files_.insert(std::move(name_string)); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool DescriptorPool::IsSubSymbolOfBuiltType(const std::string& name) const { |
|
|
|
|
std::string prefix = name; |
|
|
|
|
bool DescriptorPool::IsSubSymbolOfBuiltType(StringPiece name) const { |
|
|
|
|
auto prefix = std::string(name); |
|
|
|
|
for (;;) { |
|
|
|
|
std::string::size_type dot_pos = prefix.find_last_of('.'); |
|
|
|
|
if (dot_pos == std::string::npos) { |
|
|
|
@ -1908,10 +1906,11 @@ bool DescriptorPool::IsSubSymbolOfBuiltType(const std::string& name) const { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool DescriptorPool::TryFindSymbolInFallbackDatabase( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
StringPiece name) const { |
|
|
|
|
if (fallback_database_ == nullptr) return false; |
|
|
|
|
|
|
|
|
|
if (tables_->known_bad_symbols_.count(name) > 0) return false; |
|
|
|
|
auto name_string = std::string(name); |
|
|
|
|
if (tables_->known_bad_symbols_.count(name_string) > 0) return false; |
|
|
|
|
|
|
|
|
|
FileDescriptorProto file_proto; |
|
|
|
|
if ( // We skip looking in the fallback database if the name is a sub-symbol
|
|
|
|
@ -1933,7 +1932,7 @@ bool DescriptorPool::TryFindSymbolInFallbackDatabase( |
|
|
|
|
IsSubSymbolOfBuiltType(name) |
|
|
|
|
|
|
|
|
|
// Look up file containing this symbol in fallback database.
|
|
|
|
|
|| !fallback_database_->FindFileContainingSymbol(name, &file_proto) |
|
|
|
|
|| !fallback_database_->FindFileContainingSymbol(name_string, &file_proto) |
|
|
|
|
|
|
|
|
|
// Check if we've already built this file. If so, it apparently doesn't
|
|
|
|
|
// contain the symbol we're looking for. Some DescriptorDatabases
|
|
|
|
@ -1942,7 +1941,7 @@ bool DescriptorPool::TryFindSymbolInFallbackDatabase( |
|
|
|
|
|
|
|
|
|
// Build the file.
|
|
|
|
|
|| BuildFileFromDatabase(file_proto) == nullptr) { |
|
|
|
|
tables_->known_bad_symbols_.insert(name); |
|
|
|
|
tables_->known_bad_symbols_.insert(std::move(name_string)); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -3864,7 +3863,7 @@ Symbol DescriptorBuilder::LookupSymbol( |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool ValidateQualifiedName(const std::string& name) { |
|
|
|
|
static bool ValidateQualifiedName(StringPiece name) { |
|
|
|
|
bool last_was_period = false; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < name.size(); i++) { |
|
|
|
@ -3884,14 +3883,14 @@ static bool ValidateQualifiedName(const std::string& name) { |
|
|
|
|
return !name.empty() && !last_was_period; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Symbol DescriptorPool::NewPlaceholder(const std::string& name, |
|
|
|
|
Symbol DescriptorPool::NewPlaceholder(StringPiece name, |
|
|
|
|
PlaceholderType placeholder_type) const { |
|
|
|
|
MutexLockMaybe lock(mutex_); |
|
|
|
|
return NewPlaceholderWithMutexHeld(name, placeholder_type); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Symbol DescriptorPool::NewPlaceholderWithMutexHeld( |
|
|
|
|
const std::string& name, PlaceholderType placeholder_type) const { |
|
|
|
|
StringPiece name, PlaceholderType placeholder_type) const { |
|
|
|
|
if (mutex_) { |
|
|
|
|
mutex_->AssertHeld(); |
|
|
|
|
} |
|
|
|
@ -3989,13 +3988,13 @@ Symbol DescriptorPool::NewPlaceholderWithMutexHeld( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FileDescriptor* DescriptorPool::NewPlaceholderFile( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
StringPiece name) const { |
|
|
|
|
MutexLockMaybe lock(mutex_); |
|
|
|
|
return NewPlaceholderFileWithMutexHeld(name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FileDescriptor* DescriptorPool::NewPlaceholderFileWithMutexHeld( |
|
|
|
|
const std::string& name) const { |
|
|
|
|
StringPiece name) const { |
|
|
|
|
if (mutex_) { |
|
|
|
|
mutex_->AssertHeld(); |
|
|
|
|
} |
|
|
|
@ -7269,9 +7268,9 @@ void DescriptorBuilder::LogUnusedDependency(const FileDescriptorProto& proto, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Symbol DescriptorPool::CrossLinkOnDemandHelper(const std::string& name, |
|
|
|
|
Symbol DescriptorPool::CrossLinkOnDemandHelper(StringPiece name, |
|
|
|
|
bool expecting_enum) const { |
|
|
|
|
std::string lookup_name = name; |
|
|
|
|
auto lookup_name = std::string(name); |
|
|
|
|
if (!lookup_name.empty() && lookup_name[0] == '.') { |
|
|
|
|
lookup_name = lookup_name.substr(1); |
|
|
|
|
} |
|
|
|
@ -7399,7 +7398,7 @@ void LazyDescriptor::Set(const Descriptor* descriptor) { |
|
|
|
|
descriptor_ = descriptor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void LazyDescriptor::SetLazy(const std::string& name, |
|
|
|
|
void LazyDescriptor::SetLazy(StringPiece name, |
|
|
|
|
const FileDescriptor* file) { |
|
|
|
|
// verify Init() has been called and Set hasn't been called yet.
|
|
|
|
|
GOOGLE_CHECK(!descriptor_); |
|
|
|
|