#include <google/protobuf/compiler/parser.h>
#include <float.h>
#include <cstdint>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <google/protobuf/stubs/casts.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/hash.h>
namespace google {
namespace protobuf {
namespace compiler {
WireFormat;
namespace {
TypeNameMap;
const TypeNameMap& GetTypeNameTable() { … }
std::string MapEntryName(const std::string& field_name) { … }
bool IsUppercase(char c) { … }
bool IsLowercase(char c) { … }
bool IsNumber(char c) { … }
bool IsUpperCamelCase(const std::string& name) { … }
bool IsUpperUnderscore(const std::string& name) { … }
bool IsLowerUnderscore(const std::string& name) { … }
bool IsNumberFollowUnderscore(const std::string& name) { … }
}
#define DO(STATEMENT) …
Parser::Parser()
: … { … }
Parser::~Parser() { … }
inline bool Parser::LookingAt(const char* text) { … }
inline bool Parser::LookingAtType(io::Tokenizer::TokenType token_type) { … }
inline bool Parser::AtEnd() { … }
bool Parser::TryConsume(const char* text) { … }
bool Parser::Consume(const char* text, const char* error) { … }
bool Parser::Consume(const char* text) { … }
bool Parser::ConsumeIdentifier(std::string* output, const char* error) { … }
bool Parser::ConsumeInteger(int* output, const char* error) { … }
bool Parser::ConsumeSignedInteger(int* output, const char* error) { … }
bool Parser::ConsumeInteger64(uint64_t max_value, uint64_t* output,
const char* error) { … }
bool Parser::ConsumeNumber(double* output, const char* error) { … }
bool Parser::ConsumeString(std::string* output, const char* error) { … }
bool Parser::TryConsumeEndOfDeclaration(const char* text,
const LocationRecorder* location) { … }
bool Parser::ConsumeEndOfDeclaration(const char* text,
const LocationRecorder* location) { … }
void Parser::AddError(int line, int column, const std::string& error) { … }
void Parser::AddError(const std::string& error) { … }
void Parser::AddWarning(const std::string& warning) { … }
Parser::LocationRecorder::LocationRecorder(Parser* parser)
: … { … }
Parser::LocationRecorder::LocationRecorder(const LocationRecorder& parent) { … }
Parser::LocationRecorder::LocationRecorder(const LocationRecorder& parent,
int path1,
SourceCodeInfo* source_code_info) { … }
Parser::LocationRecorder::LocationRecorder(const LocationRecorder& parent,
int path1) { … }
Parser::LocationRecorder::LocationRecorder(const LocationRecorder& parent,
int path1, int path2) { … }
void Parser::LocationRecorder::Init(const LocationRecorder& parent,
SourceCodeInfo* source_code_info) { … }
Parser::LocationRecorder::~LocationRecorder() { … }
void Parser::LocationRecorder::AddPath(int path_component) { … }
void Parser::LocationRecorder::StartAt(const io::Tokenizer::Token& token) { … }
void Parser::LocationRecorder::StartAt(const LocationRecorder& other) { … }
void Parser::LocationRecorder::EndAt(const io::Tokenizer::Token& token) { … }
void Parser::LocationRecorder::RecordLegacyLocation(
const Message* descriptor,
DescriptorPool::ErrorCollector::ErrorLocation location) { … }
void Parser::LocationRecorder::RecordLegacyImportLocation(
const Message* descriptor, const std::string& name) { … }
int Parser::LocationRecorder::CurrentPathSize() const { … }
void Parser::LocationRecorder::AttachComments(
std::string* leading, std::string* trailing,
std::vector<std::string>* detached_comments) const { … }
void Parser::SkipStatement() { … }
void Parser::SkipRestOfBlock() { … }
bool Parser::ValidateEnum(const EnumDescriptorProto* proto) { … }
bool Parser::Parse(io::Tokenizer* input, FileDescriptorProto* file) { … }
bool Parser::ParseSyntaxIdentifier(const LocationRecorder& parent) { … }
bool Parser::ParseTopLevelStatement(FileDescriptorProto* file,
const LocationRecorder& root_location) { … }
bool Parser::ParseMessageDefinition(
DescriptorProto* message, const LocationRecorder& message_location,
const FileDescriptorProto* containing_file) { … }
namespace {
const int kMaxRangeSentinel = …;
bool IsMessageSetWireFormatMessage(const DescriptorProto& message) { … }
void AdjustExtensionRangesWithMaxEndNumber(DescriptorProto* message) { … }
void AdjustReservedRangesWithMaxEndNumber(DescriptorProto* message) { … }
}
bool Parser::ParseMessageBlock(DescriptorProto* message,
const LocationRecorder& message_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseMessageStatement(DescriptorProto* message,
const LocationRecorder& message_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseMessageField(FieldDescriptorProto* field,
RepeatedPtrField<DescriptorProto>* messages,
const LocationRecorder& parent_location,
int location_field_number_for_nested_type,
const LocationRecorder& field_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseMessageFieldNoLabel(
FieldDescriptorProto* field, RepeatedPtrField<DescriptorProto>* messages,
const LocationRecorder& parent_location,
int location_field_number_for_nested_type,
const LocationRecorder& field_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseMapType(MapField* map_field, FieldDescriptorProto* field,
LocationRecorder& type_name_location) { … }
void Parser::GenerateMapEntry(const MapField& map_field,
FieldDescriptorProto* field,
RepeatedPtrField<DescriptorProto>* messages) { … }
bool Parser::ParseFieldOptions(FieldDescriptorProto* field,
const LocationRecorder& field_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseDefaultAssignment(
FieldDescriptorProto* field, const LocationRecorder& field_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseJsonName(FieldDescriptorProto* field,
const LocationRecorder& field_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseOptionNamePart(UninterpretedOption* uninterpreted_option,
const LocationRecorder& part_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseUninterpretedBlock(std::string* value) { … }
bool Parser::ParseOption(Message* options,
const LocationRecorder& options_location,
const FileDescriptorProto* containing_file,
OptionStyle style) { … }
bool Parser::ParseExtensions(DescriptorProto* message,
const LocationRecorder& extensions_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseReserved(DescriptorProto* message,
const LocationRecorder& message_location) { … }
bool Parser::ParseReservedNames(DescriptorProto* message,
const LocationRecorder& parent_location) { … }
bool Parser::ParseReservedNumbers(DescriptorProto* message,
const LocationRecorder& parent_location) { … }
bool Parser::ParseReserved(EnumDescriptorProto* message,
const LocationRecorder& message_location) { … }
bool Parser::ParseReservedNames(EnumDescriptorProto* message,
const LocationRecorder& parent_location) { … }
bool Parser::ParseReservedNumbers(EnumDescriptorProto* message,
const LocationRecorder& parent_location) { … }
bool Parser::ParseExtend(RepeatedPtrField<FieldDescriptorProto>* extensions,
RepeatedPtrField<DescriptorProto>* messages,
const LocationRecorder& parent_location,
int location_field_number_for_nested_type,
const LocationRecorder& extend_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseOneof(OneofDescriptorProto* oneof_decl,
DescriptorProto* containing_type, int oneof_index,
const LocationRecorder& oneof_location,
const LocationRecorder& containing_type_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseEnumDefinition(EnumDescriptorProto* enum_type,
const LocationRecorder& enum_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseEnumBlock(EnumDescriptorProto* enum_type,
const LocationRecorder& enum_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseEnumStatement(EnumDescriptorProto* enum_type,
const LocationRecorder& enum_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseEnumConstant(EnumValueDescriptorProto* enum_value,
const LocationRecorder& enum_value_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseEnumConstantOptions(
EnumValueDescriptorProto* value,
const LocationRecorder& enum_value_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseServiceDefinition(
ServiceDescriptorProto* service, const LocationRecorder& service_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseServiceBlock(ServiceDescriptorProto* service,
const LocationRecorder& service_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseServiceStatement(ServiceDescriptorProto* service,
const LocationRecorder& service_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseServiceMethod(MethodDescriptorProto* method,
const LocationRecorder& method_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseMethodOptions(const LocationRecorder& parent_location,
const FileDescriptorProto* containing_file,
const int optionsFieldNumber,
Message* mutable_options) { … }
bool Parser::ParseLabel(FieldDescriptorProto::Label* label,
const LocationRecorder& field_location) { … }
bool Parser::ParseType(FieldDescriptorProto::Type* type,
std::string* type_name) { … }
bool Parser::ParseUserDefinedType(std::string* type_name) { … }
bool Parser::ParsePackage(FileDescriptorProto* file,
const LocationRecorder& root_location,
const FileDescriptorProto* containing_file) { … }
bool Parser::ParseImport(RepeatedPtrField<std::string>* dependency,
RepeatedField<int32_t>* public_dependency,
RepeatedField<int32_t>* weak_dependency,
const LocationRecorder& root_location,
const FileDescriptorProto* containing_file) { … }
SourceLocationTable::SourceLocationTable() { … }
SourceLocationTable::~SourceLocationTable() { … }
bool SourceLocationTable::Find(
const Message* descriptor,
DescriptorPool::ErrorCollector::ErrorLocation location, int* line,
int* column) const { … }
bool SourceLocationTable::FindImport(const Message* descriptor,
const std::string& name, int* line,
int* column) const { … }
void SourceLocationTable::Add(
const Message* descriptor,
DescriptorPool::ErrorCollector::ErrorLocation location, int line,
int column) { … }
void SourceLocationTable::AddImport(const Message* descriptor,
const std::string& name, int line,
int column) { … }
void SourceLocationTable::Clear() { … }
}
}
}