chromium/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc

// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef _MSC_VER
#include <unistd.h>
#endif
#include <climits>
#include <errno.h>
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <unordered_set>
#include <vector>

#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
#include <google/protobuf/compiler/objectivec/objectivec_nsobject_methods.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/io/io_win32.h>
#include <google/protobuf/port.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/strutil.h>

// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
// error cases, so it seems to be ok to use as a back door for errors.

namespace google {
namespace protobuf {
namespace compiler {
namespace objectivec {

// <io.h> is transitively included in this file. Import the functions explicitly
// in this port namespace to avoid ambiguous definition.
namespace posix {
#ifdef _WIN32
using ::google::protobuf::io::win32::open;
#else
open;
#endif
}  // namespace port

namespace {

bool BoolFromEnvVar(const char* env_var, bool default_value) {}

class SimpleLineCollector : public LineConsumer {};

class PackageToPrefixesCollector : public LineConsumer {};

class PrefixModeStorage {};

PrefixModeStorage::PrefixModeStorage() {}

std::string PrefixModeStorage::prefix_from_proto_package_mappings(const FileDescriptor* file) {}

bool PrefixModeStorage::is_package_exempted(const std::string& package) {}

PrefixModeStorage g_prefix_mode;

}  // namespace

std::string GetPackageToPrefixMappingsPath() {}

void SetPackageToPrefixMappingsPath(const std::string& file_path) {}

bool UseProtoPackageAsDefaultPrefix() {}

void SetUseProtoPackageAsDefaultPrefix(bool on_or_off) {}

std::string GetProtoPackagePrefixExceptionList() {}

void SetProtoPackagePrefixExceptionList(const std::string& file_path) {}

Options::Options() {}

namespace {

std::unordered_set<std::string> MakeWordsMap(const char* const words[],
                                             size_t num_words) {}

const char* const kUpperSegmentsList[] =;

std::unordered_set<std::string> kUpperSegments =;

bool ascii_isnewline(char c) {}

// Internal helper for name handing.
// Do not expose this outside of helpers, stick to having functions for specific
// cases (ClassName(), FieldName()), so there is always consistent suffix rules.
std::string UnderscoresToCamelCase(const std::string& input,
                                   bool first_capitalized) {}

const char* const kReservedWordList[] =;

// returns true is input starts with __ or _[A-Z] which are reserved identifiers
// in C/ C++. All calls should go through UnderscoresToCamelCase before getting here
// but this verifies and allows for future expansion if we decide to redefine what a
// reserved C identifier is (for example the GNU list
// https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html )
bool IsReservedCIdentifier(const std::string& input) {}

std::string SanitizeNameForObjC(const std::string& prefix,
                                const std::string& input,
                                const std::string& extension,
                                std::string* out_suffix_added) {}

std::string NameFromFieldDescriptor(const FieldDescriptor* field) {}

void PathSplit(const std::string& path, std::string* directory,
               std::string* basename) {}

bool IsSpecialName(const std::string& name, const std::string* special_names,
                   size_t count) {}

std::string GetZeroEnumNameForFlagType(const FlagType flag_type) {}

std::string GetEnumNameForFlagType(const FlagType flag_type) {}

void MaybeUnQuote(StringPiece* input) {}

}  // namespace

// Escape C++ trigraphs by escaping question marks to \?
std::string EscapeTrigraphs(const std::string& to_escape) {}

void TrimWhitespace(StringPiece* input) {}

bool IsRetainedName(const std::string& name) {}

bool IsInitName(const std::string& name) {}

std::string BaseFileName(const FileDescriptor* file) {}

std::string FileClassPrefix(const FileDescriptor* file) {}

std::string FilePath(const FileDescriptor* file) {}

std::string FilePathBasename(const FileDescriptor* file) {}

std::string FileClassName(const FileDescriptor* file) {}

std::string ClassNameWorker(const Descriptor* descriptor) {}

std::string ClassNameWorker(const EnumDescriptor* descriptor) {}

std::string ClassName(const Descriptor* descriptor) {}

std::string ClassName(const Descriptor* descriptor,
                      std::string* out_suffix_added) {}

std::string EnumName(const EnumDescriptor* descriptor) {}

std::string EnumValueName(const EnumValueDescriptor* descriptor) {}

std::string EnumValueShortName(const EnumValueDescriptor* descriptor) {}

std::string UnCamelCaseEnumShortName(const std::string& name) {}

std::string ExtensionMethodName(const FieldDescriptor* descriptor) {}

std::string FieldName(const FieldDescriptor* field) {}

std::string FieldNameCapitalized(const FieldDescriptor* field) {}

std::string OneofEnumName(const OneofDescriptor* descriptor) {}

std::string OneofName(const OneofDescriptor* descriptor) {}

std::string OneofNameCapitalized(const OneofDescriptor* descriptor) {}

std::string ObjCClass(const std::string& class_name) {}

std::string ObjCClassDeclaration(const std::string& class_name) {}

std::string UnCamelCaseFieldName(const std::string& name, const FieldDescriptor* field) {}

std::string GetCapitalizedType(const FieldDescriptor* field) {}

ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type) {}

bool IsPrimitiveType(const FieldDescriptor* field) {}

bool IsReferenceType(const FieldDescriptor* field) {}

static std::string HandleExtremeFloatingPoint(std::string val,
                                              bool add_float_suffix) {}

std::string GPBGenericValueFieldName(const FieldDescriptor* field) {}


std::string DefaultValue(const FieldDescriptor* field) {}

bool HasNonZeroDefaultValue(const FieldDescriptor* field) {}

std::string BuildFlagsString(const FlagType flag_type,
                             const std::vector<std::string>& strings) {}

std::string BuildCommentsString(const SourceLocation& location,
                           bool prefer_single_line) {}

// Making these a generator option for folks that don't use CocoaPods, but do
// want to put the library in a framework is an interesting question. The
// problem is it means changing sources shipped with the library to actually
// use a different value; so it isn't as simple as a option.
const char* const ProtobufLibraryFrameworkName =;

std::string ProtobufFrameworkImportSymbol(const std::string& framework_name) {}

bool IsProtobufLibraryBundledProtoFile(const FileDescriptor* file) {}

bool ReadLine(StringPiece* input, StringPiece* line) {}

void RemoveComment(StringPiece* input) {}

namespace {

bool PackageToPrefixesCollector::ConsumeLine(
    const StringPiece& line, std::string* out_error) {}

bool LoadExpectedPackagePrefixes(const std::string& expected_prefixes_path,
                                 std::map<std::string, std::string>* prefix_map,
                                 std::string* out_error) {}

bool ValidateObjCClassPrefix(
    const FileDescriptor* file, const std::string& expected_prefixes_path,
    const std::map<std::string, std::string>& expected_package_prefixes,
    bool prefixes_must_be_registered, bool require_prefixes,
    std::string* out_error) {}

}  // namespace

bool ValidateObjCClassPrefixes(const std::vector<const FileDescriptor*>& files,
                               std::string* out_error) {}

bool ValidateObjCClassPrefixes(const std::vector<const FileDescriptor*>& files,
                               const Options& generation_options,
                               std::string* out_error) {}

TextFormatDecodeData::TextFormatDecodeData() {}

TextFormatDecodeData::~TextFormatDecodeData() {}

void TextFormatDecodeData::AddString(int32_t key,
                                     const std::string& input_for_decode,
                                     const std::string& desired_output) {}

std::string TextFormatDecodeData::Data() const {}

namespace {

// Helper to build up the decode data for a string.
class DecodeDataBuilder {};

bool DecodeDataBuilder::AddCharacter(const char desired, const char input) {}

// If decode data can't be generated, a directive for the raw string
// is used instead.
std::string DirectDecodeString(const std::string& str) {}

}  // namespace

// static
std::string TextFormatDecodeData::DecodeDataForString(
    const std::string& input_for_decode, const std::string& desired_output) {}

namespace {

class Parser {};

bool Parser::ParseChunk(StringPiece chunk, std::string* out_error) {}

bool Parser::Finish(std::string* out_error) {}

std::string FullErrorString(const std::string& name, int line_num, const std::string& msg) {}

}  // namespace

LineConsumer::LineConsumer() {}

LineConsumer::~LineConsumer() {}

bool ParseSimpleFile(const std::string& path, LineConsumer* line_consumer,
                     std::string* out_error) {}

bool ParseSimpleStream(io::ZeroCopyInputStream& input_stream,
                       const std::string& stream_name,
                       LineConsumer* line_consumer,
                       std::string* out_error) {}

ImportWriter::ImportWriter(
    const std::string& generate_for_named_framework,
    const std::string& named_framework_to_proto_path_mappings_path,
    const std::string& runtime_import_prefix, bool include_wkt_imports)
    :{}

ImportWriter::~ImportWriter() {}

void ImportWriter::AddFile(const FileDescriptor* file,
                           const std::string& header_extension) {}

void ImportWriter::Print(io::Printer* printer) const {}

void ImportWriter::PrintRuntimeImports(
    io::Printer* printer, const std::vector<std::string>& header_to_import,
    const std::string& runtime_import_prefix, bool default_cpp_symbol) {}

void ImportWriter::ParseFrameworkMappings() {}

bool ImportWriter::ProtoFrameworkCollector::ConsumeLine(
    const StringPiece& line, std::string* out_error) {}

}  // namespace objectivec
}  // namespace compiler
}  // namespace protobuf
}  // namespace google