Cleanups to allow for import by Copybara. (#5826)

* Some fixes to make the code work in google3.

* Removed plugin.h.

* Some more fixes to be namespace-independent.

* More fixes for namespace independence.

* A few final fixes.

* Another fix (hide ToUpper from Copybara).

* Fix for charp_unittest.
pull/5855/head
Joshua Haberman 6 years ago committed by GitHub
parent e41e2dde55
commit e2dd7403bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/google/protobuf/compiler/cpp/cpp_helpers.cc
  2. 3
      src/google/protobuf/compiler/csharp/csharp_doc_comment.cc
  3. 1
      src/google/protobuf/compiler/csharp/csharp_enum.cc
  4. 5
      src/google/protobuf/compiler/csharp/csharp_enum.h
  5. 1
      src/google/protobuf/compiler/csharp/csharp_enum_field.cc
  6. 12
      src/google/protobuf/compiler/csharp/csharp_enum_field.h
  7. 7
      src/google/protobuf/compiler/csharp/csharp_field_base.cc
  8. 5
      src/google/protobuf/compiler/csharp/csharp_field_base.h
  9. 4
      src/google/protobuf/compiler/csharp/csharp_generator.cc
  10. 3
      src/google/protobuf/compiler/csharp/csharp_generator.h
  11. 12
      src/google/protobuf/compiler/csharp/csharp_helpers.cc
  12. 1
      src/google/protobuf/compiler/csharp/csharp_map_field.cc
  13. 6
      src/google/protobuf/compiler/csharp/csharp_map_field.h
  14. 1
      src/google/protobuf/compiler/csharp/csharp_message.cc
  15. 5
      src/google/protobuf/compiler/csharp/csharp_message.h
  16. 1
      src/google/protobuf/compiler/csharp/csharp_message_field.cc
  17. 13
      src/google/protobuf/compiler/csharp/csharp_message_field.h
  18. 8
      src/google/protobuf/compiler/csharp/csharp_names.h
  19. 8
      src/google/protobuf/compiler/csharp/csharp_options.h
  20. 1
      src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
  21. 13
      src/google/protobuf/compiler/csharp/csharp_primitive_field.h
  22. 1
      src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
  23. 5
      src/google/protobuf/compiler/csharp/csharp_reflection_class.h
  24. 1
      src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
  25. 11
      src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h
  26. 1
      src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
  27. 7
      src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h
  28. 1
      src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
  29. 9
      src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h
  30. 1
      src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
  31. 5
      src/google/protobuf/compiler/csharp/csharp_source_generator_base.h
  32. 1
      src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc
  33. 10
      src/google/protobuf/compiler/csharp/csharp_wrapper_field.h
  34. 15
      src/google/protobuf/compiler/java/java_helpers.cc
  35. 12
      src/google/protobuf/compiler/php/php_generator.h
  36. 88
      src/google/protobuf/compiler/ruby/ruby_generator.cc
  37. 3
      src/google/protobuf/compiler/ruby/ruby_generator.h

@ -69,10 +69,6 @@ static const char kAnyMessageName[] = "Any";
static const char kAnyProtoFile[] = "google/protobuf/any.proto";
static const char kGoogleProtobufPrefix[] = "google/protobuf/";
std::string DotsToUnderscores(const std::string& name) {
return StringReplace(name, ".", "_", true);
}
std::string DotsToColons(const std::string& name) {
return StringReplace(name, ".", "::", true);
}

@ -56,7 +56,8 @@ void WriteDocCommentBodyImpl(io::Printer* printer, SourceLocation location) {
// node of a summary element, not part of an attribute.
comments = StringReplace(comments, "&", "&", true);
comments = StringReplace(comments, "<", "&lt;", true);
std::vector<string> lines = Split(comments, "\n", false /* skip_empty */);
std::vector<string> lines;
SplitStringAllowEmpty(comments, "\n", &lines);
// TODO: We really should work out which part to put in the summary and which to put in the remarks...
// but that needs to be part of a bigger effort to understand the markdown better anyway.
printer->Print("/// <summary>\n");

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -48,12 +48,13 @@ class EnumGenerator : public SourceGeneratorBase {
EnumGenerator(const EnumDescriptor* descriptor, const Options* options);
~EnumGenerator();
EnumGenerator(const EnumGenerator&) = delete;
EnumGenerator& operator=(const EnumGenerator&) = delete;
void Generate(io::Printer* printer);
private:
const EnumDescriptor* descriptor_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator);
};
} // namespace csharp

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -48,13 +48,13 @@ class EnumFieldGenerator : public PrimitiveFieldGenerator {
const Options *options);
~EnumFieldGenerator();
EnumFieldGenerator(const EnumFieldGenerator&) = delete;
EnumFieldGenerator& operator=(const EnumFieldGenerator&) = delete;
virtual void GenerateCodecCode(io::Printer* printer);
virtual void GenerateParsingCode(io::Printer* printer);
virtual void GenerateSerializationCode(io::Printer* printer);
virtual void GenerateSerializedSizeCode(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator);
};
class EnumOneofFieldGenerator : public PrimitiveOneofFieldGenerator {
@ -64,13 +64,13 @@ class EnumOneofFieldGenerator : public PrimitiveOneofFieldGenerator {
const Options *options);
~EnumOneofFieldGenerator();
EnumOneofFieldGenerator(const EnumOneofFieldGenerator&) = delete;
EnumOneofFieldGenerator& operator=(const EnumOneofFieldGenerator&) = delete;
virtual void GenerateMergingCode(io::Printer* printer);
virtual void GenerateParsingCode(io::Printer* printer);
virtual void GenerateSerializationCode(io::Printer* printer);
virtual void GenerateSerializedSizeCode(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumOneofFieldGenerator);
};
} // namespace csharp

@ -28,17 +28,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cmath>
#include <limits>
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.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.h>
#include <google/protobuf/stubs/mathlimits.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/wire_format.h>
@ -323,7 +322,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
return "double.PositiveInfinity";
} else if (value == -std::numeric_limits<double>::infinity()) {
return "double.NegativeInfinity";
} else if (MathLimits<double>::IsNaN(value)) {
} else if (std::isnan(value)) {
return "double.NaN";
}
return SimpleDtoa(value) + "D";
@ -334,7 +333,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
return "float.PositiveInfinity";
} else if (value == -std::numeric_limits<float>::infinity()) {
return "float.NegativeInfinity";
} else if (MathLimits<float>::IsNaN(value)) {
} else if (std::isnan(value)) {
return "float.NaN";
}
return SimpleFtoa(value) + "F";

@ -51,6 +51,9 @@ class FieldGeneratorBase : public SourceGeneratorBase {
const Options* options);
~FieldGeneratorBase();
FieldGeneratorBase(const FieldGeneratorBase&) = delete;
FieldGeneratorBase& operator=(const FieldGeneratorBase&) = delete;
virtual void GenerateCloningCode(io::Printer* printer) = 0;
virtual void GenerateFreezingCode(io::Printer* printer);
virtual void GenerateCodecCode(io::Printer* printer);
@ -93,8 +96,6 @@ class FieldGeneratorBase : public SourceGeneratorBase {
void SetCommonFieldVariables(std::map<string, string>* variables);
std::string GetStringDefaultValueInternal(const FieldDescriptor* descriptor);
std::string GetBytesDefaultValueInternal(const FieldDescriptor* descriptor);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorBase);
};
} // namespace csharp

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>
@ -49,8 +48,7 @@ namespace protobuf {
namespace compiler {
namespace csharp {
void GenerateFile(const google::protobuf::FileDescriptor* file,
io::Printer* printer,
void GenerateFile(const FileDescriptor* file, io::Printer* printer,
const Options* options) {
ReflectionClassGenerator reflectionClassGenerator(file, options);
reflectionClassGenerator.Generate(printer);

@ -48,8 +48,7 @@ namespace csharp {
// header. If you create your own protocol compiler binary and you want
// it to support C# output, you can do so by registering an instance of this
// CodeGenerator with the CommandLineInterface in your main() function.
class PROTOC_EXPORT Generator
: public PROTOBUF_NAMESPACE_ID::compiler::CodeGenerator {
class PROTOC_EXPORT Generator : public CodeGenerator {
public:
virtual bool Generate(
const FileDescriptor* file,

@ -33,7 +33,6 @@
// Sanjay Ghemawat, Jeff Dean, and others.
#include <algorithm>
#include <google/protobuf/stubs/hash.h>
#include <limits>
#include <vector>
#include <sstream>
@ -44,7 +43,6 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/csharp/csharp_field_base.h>
#include <google/protobuf/compiler/csharp/csharp_enum_field.h>
@ -355,12 +353,10 @@ std::string GetPropertyName(const FieldDescriptor* descriptor) {
return property_name;
}
std::string GetOutputFile(
const google::protobuf::FileDescriptor* descriptor,
const std::string file_extension,
const bool generate_directories,
const std::string base_namespace,
string* error) {
std::string GetOutputFile(const FileDescriptor* descriptor,
const std::string file_extension,
const bool generate_directories,
const std::string base_namespace, string* error) {
string relative_filename = GetFileNameBase(descriptor) + file_extension;
if (!generate_directories) {
return relative_filename;

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -48,6 +48,9 @@ class MapFieldGenerator : public FieldGeneratorBase {
const Options* options);
~MapFieldGenerator();
MapFieldGenerator(const MapFieldGenerator&) = delete;
MapFieldGenerator& operator=(const MapFieldGenerator&) = delete;
virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateFreezingCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer);
@ -59,9 +62,6 @@ class MapFieldGenerator : public FieldGeneratorBase {
virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer);
virtual void WriteToString(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldGenerator);
};
} // namespace csharp

@ -33,7 +33,6 @@
#include <map>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -50,6 +50,9 @@ class MessageGenerator : public SourceGeneratorBase {
MessageGenerator(const Descriptor* descriptor, const Options* options);
~MessageGenerator();
MessageGenerator(const MessageGenerator&) = delete;
MessageGenerator& operator=(const MessageGenerator&) = delete;
void GenerateCloningCode(io::Printer* printer);
void GenerateFreezingCode(io::Printer* printer);
void GenerateFrameworkMethods(io::Printer* printer);
@ -78,8 +81,6 @@ class MessageGenerator : public SourceGeneratorBase {
// field descriptors sorted by number
const std::vector<const FieldDescriptor*>& fields_by_number();
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator);
};
} // namespace csharp

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -48,6 +48,9 @@ class MessageFieldGenerator : public FieldGeneratorBase {
const Options *options);
~MessageFieldGenerator();
MessageFieldGenerator(const MessageFieldGenerator&) = delete;
MessageFieldGenerator& operator=(const MessageFieldGenerator&) = delete;
virtual void GenerateCodecCode(io::Printer* printer);
virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateFreezingCode(io::Printer* printer);
@ -60,9 +63,6 @@ class MessageFieldGenerator : public FieldGeneratorBase {
virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer);
virtual void WriteToString(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator);
};
class MessageOneofFieldGenerator : public MessageFieldGenerator {
@ -72,14 +72,15 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator {
const Options *options);
~MessageOneofFieldGenerator();
MessageOneofFieldGenerator(const MessageOneofFieldGenerator&) = delete;
MessageOneofFieldGenerator& operator=(const MessageOneofFieldGenerator&) =
delete;
virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer);
virtual void GenerateMergingCode(io::Printer* printer);
virtual void WriteToString(io::Printer* printer);
virtual void GenerateParsingCode(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageOneofFieldGenerator);
};
} // namespace csharp

@ -91,10 +91,10 @@ string PROTOC_EXPORT GetReflectionClassName(const FileDescriptor* descriptor);
// The file name to use as output file for given file descriptor. In case
// of failure, this function will return empty string and error parameter
// will contain the error message.
string PROTOC_EXPORT
GetOutputFile(const google::protobuf::FileDescriptor* descriptor,
const string file_extension, const bool generate_directories,
const string base_namespace, string* error);
string PROTOC_EXPORT GetOutputFile(const FileDescriptor* descriptor,
const string file_extension,
const bool generate_directories,
const string base_namespace, string* error);
} // namespace csharp
} // namespace compiler

@ -33,7 +33,6 @@
#include <string>
#include <google/protobuf/stubs/common.h>
namespace google {
namespace protobuf {
namespace compiler {
@ -49,7 +48,7 @@ struct Options {
serializable(false) {
}
// Extension of the generated file. Defaults to ".cs"
string file_extension;
std::string file_extension;
// Base namespace to use to create directory hierarchy. Defaults to "".
// This option allows the simple creation of a conventional C# file layout,
// where directories are created relative to a project-specific base
@ -60,7 +59,7 @@ struct Options {
//
// If no base namespace is specified, all files are generated in the
// --csharp_out directory, with no subdirectories created automatically.
string base_namespace;
std::string base_namespace;
// Whether the base namespace has been explicitly specified by the user.
// This is required as the base namespace can be explicitly set to the empty
// string, meaning "create a full directory hierarchy, starting from the first
@ -77,7 +76,6 @@ struct Options {
} // namespace csharp
} // namespace compiler
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_OPTIONS_H__

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -50,6 +50,9 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase {
const Options *options);
~PrimitiveFieldGenerator();
PrimitiveFieldGenerator(const PrimitiveFieldGenerator&) = delete;
PrimitiveFieldGenerator& operator=(const PrimitiveFieldGenerator&) = delete;
virtual void GenerateCodecCode(io::Printer* printer);
virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer);
@ -64,9 +67,6 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase {
protected:
bool is_value_type;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator);
};
class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator {
@ -76,14 +76,15 @@ class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator {
const Options *options);
~PrimitiveOneofFieldGenerator();
PrimitiveOneofFieldGenerator(const PrimitiveOneofFieldGenerator&) = delete;
PrimitiveOneofFieldGenerator& operator=(const PrimitiveOneofFieldGenerator&) =
delete;
virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer);
virtual void GenerateMergingCode(io::Printer* printer);
virtual void WriteToString(io::Printer* printer);
virtual void GenerateParsingCode(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveOneofFieldGenerator);
};
} // namespace csharp

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -48,6 +48,9 @@ class ReflectionClassGenerator : public SourceGeneratorBase {
ReflectionClassGenerator(const FileDescriptor* file, const Options* options);
~ReflectionClassGenerator();
ReflectionClassGenerator(const ReflectionClassGenerator&) = delete;
ReflectionClassGenerator& operator=(const ReflectionClassGenerator&) = delete;
void Generate(io::Printer* printer);
private:
@ -61,8 +64,6 @@ class ReflectionClassGenerator : public SourceGeneratorBase {
void WriteGeneratedCodeInfo(const Descriptor* descriptor,
io::Printer* printer,
bool last);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReflectionClassGenerator);
};
} // namespace csharp

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -41,8 +41,8 @@ namespace protobuf {
namespace compiler {
namespace csharp {
// TODO(jonskeet): Refactor repeated field support; all the implementations are *really* similar. We
// should probably have a RepeatedFieldGeneratorBase.
// TODO(jonskeet): Refactor repeated field support; all the implementations are
// *really* similar. We should probably have a RepeatedFieldGeneratorBase.
class RepeatedEnumFieldGenerator : public FieldGeneratorBase {
public:
RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor,
@ -50,6 +50,10 @@ class RepeatedEnumFieldGenerator : public FieldGeneratorBase {
const Options *options);
~RepeatedEnumFieldGenerator();
RepeatedEnumFieldGenerator(const RepeatedEnumFieldGenerator&) = delete;
RepeatedEnumFieldGenerator& operator=(const RepeatedEnumFieldGenerator&) =
delete;
virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateFreezingCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer);
@ -61,9 +65,6 @@ class RepeatedEnumFieldGenerator : public FieldGeneratorBase {
virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer);
virtual void WriteToString(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator);
};
} // namespace csharp

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -50,6 +50,10 @@ class RepeatedMessageFieldGenerator : public FieldGeneratorBase {
const Options *options);
~RepeatedMessageFieldGenerator();
RepeatedMessageFieldGenerator(const RepeatedMessageFieldGenerator&) = delete;
RepeatedMessageFieldGenerator& operator=(
const RepeatedMessageFieldGenerator&) = delete;
virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateFreezingCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer);
@ -61,9 +65,6 @@ class RepeatedMessageFieldGenerator : public FieldGeneratorBase {
virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer);
virtual void WriteToString(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator);
};
} // namespace csharp

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -43,9 +43,13 @@ namespace csharp {
class RepeatedPrimitiveFieldGenerator : public FieldGeneratorBase {
public:
RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, int presenceIndex, const Options *options);
RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor,
int presenceIndex, const Options* options);
~RepeatedPrimitiveFieldGenerator();
RepeatedPrimitiveFieldGenerator(const RepeatedPrimitiveFieldGenerator&) = delete;
RepeatedPrimitiveFieldGenerator& operator=(const RepeatedPrimitiveFieldGenerator&) = delete;
virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateFreezingCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer);
@ -57,9 +61,6 @@ class RepeatedPrimitiveFieldGenerator : public FieldGeneratorBase {
virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer);
virtual void WriteToString(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator);
};
} // namespace csharp

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -48,6 +48,9 @@ class SourceGeneratorBase {
SourceGeneratorBase(const FileDescriptor* descriptor, const Options* options);
virtual ~SourceGeneratorBase();
SourceGeneratorBase(const SourceGeneratorBase&) = delete;
SourceGeneratorBase& operator=(const SourceGeneratorBase&) = delete;
std::string class_access_level();
const Options* options();
@ -58,8 +61,6 @@ class SourceGeneratorBase {
private:
const FileDescriptor* descriptor_;
const Options *options_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceGeneratorBase);
};
} // namespace csharp

@ -31,7 +31,6 @@
#include <sstream>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>

@ -50,6 +50,9 @@ class WrapperFieldGenerator : public FieldGeneratorBase {
const Options *options);
~WrapperFieldGenerator();
WrapperFieldGenerator(const WrapperFieldGenerator&) = delete;
WrapperFieldGenerator& operator=(const WrapperFieldGenerator&) = delete;
virtual void GenerateCodecCode(io::Printer* printer);
virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer);
@ -64,7 +67,6 @@ class WrapperFieldGenerator : public FieldGeneratorBase {
private:
bool is_value_type; // True for int32 etc; false for bytes and string
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WrapperFieldGenerator);
};
class WrapperOneofFieldGenerator : public WrapperFieldGenerator {
@ -74,14 +76,14 @@ class WrapperOneofFieldGenerator : public WrapperFieldGenerator {
const Options *options);
~WrapperOneofFieldGenerator();
WrapperOneofFieldGenerator(const WrapperOneofFieldGenerator&) = delete;
WrapperOneofFieldGenerator& operator=(const WrapperOneofFieldGenerator&) = delete;
virtual void GenerateMembers(io::Printer* printer);
virtual void GenerateMergingCode(io::Printer* printer);
virtual void GenerateParsingCode(io::Printer* printer);
virtual void GenerateSerializationCode(io::Printer* printer);
virtual void GenerateSerializedSizeCode(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WrapperOneofFieldGenerator);
};
} // namespace csharp

@ -105,21 +105,6 @@ std::string FieldName(const FieldDescriptor* field) {
return field_name;
}
// Judge whether should use table or use look up.
// Copied from com.google.protobuf.SchemaUtil.shouldUseTableSwitch
bool ShouldUseTable(int lo, int hi, int number_of_fields) {
if (hi < kDefaultLookUpStartFieldNumber) {
return true;
}
int64 table_space_cost = (static_cast<int64>(hi) - lo + 1); // words
int64 table_time_cost = 3; // comparisons
int64 lookup_space_cost = 3 + 2 * static_cast<int64>(number_of_fields);
int64 lookup_time_cost = 3 + number_of_fields;
return table_space_cost + 3 * table_time_cost <=
lookup_space_cost + 3 * lookup_time_cost;
}
} // namespace
void PrintGeneratedAnnotation(io::Printer* printer, char delimiter,

@ -43,8 +43,7 @@ namespace protobuf {
namespace compiler {
namespace php {
class PROTOC_EXPORT Generator
: public PROTOBUF_NAMESPACE_ID::compiler::CodeGenerator {
class PROTOC_EXPORT Generator : public CodeGenerator {
virtual bool Generate(
const FileDescriptor* file,
const string& parameter,
@ -55,12 +54,9 @@ class PROTOC_EXPORT Generator
// To skip reserved keywords in php, some generated classname are prefixed.
// Other code generators may need following API to figure out the actual
// classname.
PROTOC_EXPORT std::string GeneratedClassName(
const PROTOBUF_NAMESPACE_ID::Descriptor* desc);
PROTOC_EXPORT std::string GeneratedClassName(
const PROTOBUF_NAMESPACE_ID::EnumDescriptor* desc);
PROTOC_EXPORT std::string GeneratedClassName(
const PROTOBUF_NAMESPACE_ID::ServiceDescriptor* desc);
PROTOC_EXPORT std::string GeneratedClassName(const Descriptor* desc);
PROTOC_EXPORT std::string GeneratedClassName(const EnumDescriptor* desc);
PROTOC_EXPORT std::string GeneratedClassName(const ServiceDescriptor* desc);
inline bool IsWrapperType(const FieldDescriptor* descriptor) {
return descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&

@ -46,25 +46,19 @@ namespace compiler {
namespace ruby {
// Forward decls.
template<class numeric_type> std::string NumberToString(numeric_type value);
template <class numeric_type>
std::string NumberToString(numeric_type value);
std::string GetRequireName(const std::string& proto_file);
std::string LabelForField(google::protobuf::FieldDescriptor* field);
std::string TypeName(google::protobuf::FieldDescriptor* field);
bool GenerateMessage(const google::protobuf::Descriptor* message,
google::protobuf::io::Printer* printer,
std::string* error);
void GenerateEnum(const google::protobuf::EnumDescriptor* en,
google::protobuf::io::Printer* printer);
void GenerateMessageAssignment(
const std::string& prefix,
const google::protobuf::Descriptor* message,
google::protobuf::io::Printer* printer);
void GenerateEnumAssignment(
const std::string& prefix,
const google::protobuf::EnumDescriptor* en,
google::protobuf::io::Printer* printer);
std::string DefaultValueForField(
const google::protobuf::FieldDescriptor* field);
std::string LabelForField(FieldDescriptor* field);
std::string TypeName(FieldDescriptor* field);
bool GenerateMessage(const Descriptor* message, io::Printer* printer,
std::string* error);
void GenerateEnum(const EnumDescriptor* en, io::Printer* printer);
void GenerateMessageAssignment(const std::string& prefix,
const Descriptor* message, io::Printer* printer);
void GenerateEnumAssignment(const std::string& prefix, const EnumDescriptor* en,
io::Printer* printer);
std::string DefaultValueForField(const FieldDescriptor* field);
template<class numeric_type>
std::string NumberToString(numeric_type value) {
@ -82,7 +76,7 @@ std::string GetOutputFilename(const std::string& proto_file) {
return GetRequireName(proto_file) + ".rb";
}
std::string LabelForField(const google::protobuf::FieldDescriptor* field) {
std::string LabelForField(const FieldDescriptor* field) {
switch (field->label()) {
case FieldDescriptor::LABEL_OPTIONAL: return "optional";
case FieldDescriptor::LABEL_REQUIRED: return "required";
@ -91,7 +85,7 @@ std::string LabelForField(const google::protobuf::FieldDescriptor* field) {
}
}
std::string TypeName(const google::protobuf::FieldDescriptor* field) {
std::string TypeName(const FieldDescriptor* field) {
switch (field->type()) {
case FieldDescriptor::TYPE_INT32: return "int32";
case FieldDescriptor::TYPE_INT64: return "int64";
@ -124,12 +118,12 @@ string StringifySyntax(FileDescriptor::Syntax syntax) {
case FileDescriptor::SYNTAX_UNKNOWN:
default:
GOOGLE_LOG(FATAL) << "Unsupported syntax; this generator only supports "
"proto2 and proto3 syntax.";
"proto2 and proto3 syntax.";
return "";
}
}
std::string DefaultValueForField(const google::protobuf::FieldDescriptor* field) {
std::string DefaultValueForField(const FieldDescriptor* field) {
switch(field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
return NumberToString(field->default_value_int32());
@ -160,7 +154,7 @@ std::string DefaultValueForField(const google::protobuf::FieldDescriptor* field)
for (int i = 0; i < default_str.length(); ++i) {
// Write the hex form of each byte.
os << "\\x" << std::hex << std::setw(2)
<< ((uint16) ((unsigned char) default_str.at(i)));
<< ((uint16)((unsigned char)default_str.at(i)));
}
os << "\".force_encoding(\"ASCII-8BIT\")";
}
@ -171,9 +165,7 @@ std::string DefaultValueForField(const google::protobuf::FieldDescriptor* field)
}
}
void GenerateField(const google::protobuf::FieldDescriptor* field,
google::protobuf::io::Printer* printer) {
void GenerateField(const FieldDescriptor* field, io::Printer* printer) {
if (field->is_map()) {
const FieldDescriptor* key_field =
field->message_type()->FindFieldByNumber(1);
@ -220,17 +212,15 @@ void GenerateField(const google::protobuf::FieldDescriptor* field,
}
if (field->has_default_value()) {
printer->Print(
", default: $default$",
"default", DefaultValueForField(field));
printer->Print(", default: $default$", "default",
DefaultValueForField(field));
}
printer->Print("\n");
}
}
void GenerateOneof(const google::protobuf::OneofDescriptor* oneof,
google::protobuf::io::Printer* printer) {
void GenerateOneof(const OneofDescriptor* oneof, io::Printer* printer) {
printer->Print(
"oneof :$name$ do\n",
"name", oneof->name());
@ -245,9 +235,8 @@ void GenerateOneof(const google::protobuf::OneofDescriptor* oneof,
printer->Print("end\n");
}
bool GenerateMessage(const google::protobuf::Descriptor* message,
google::protobuf::io::Printer* printer,
std::string* error) {
bool GenerateMessage(const Descriptor* message, io::Printer* printer,
std::string* error) {
if (message->extension_range_count() > 0 || message->extension_count() > 0) {
*error = "Extensions are not yet supported for proto2 .proto files.";
return false;
@ -291,8 +280,7 @@ bool GenerateMessage(const google::protobuf::Descriptor* message,
return true;
}
void GenerateEnum(const google::protobuf::EnumDescriptor* en,
google::protobuf::io::Printer* printer) {
void GenerateEnum(const EnumDescriptor* en, io::Printer* printer) {
printer->Print(
"add_enum \"$name$\" do\n",
"name", en->full_name());
@ -318,7 +306,7 @@ bool IsUpper(char ch) { return ch >= 'A' && ch <= 'Z'; }
bool IsAlpha(char ch) { return IsLower(ch) || IsUpper(ch); }
char ToUpper(char ch) { return IsLower(ch) ? (ch - 'a' + 'A') : ch; }
char UpperChar(char ch) { return IsLower(ch) ? (ch - 'a' + 'A') : ch; }
// Package names in protobuf are snake_case by convention, but Ruby module
@ -335,7 +323,7 @@ std::string PackageToModule(const std::string& name) {
next_upper = true;
} else {
if (next_upper) {
result.push_back(ToUpper(name[i]));
result.push_back(UpperChar(name[i]));
} else {
result.push_back(name[i]);
}
@ -355,7 +343,7 @@ std::string RubifyConstant(const std::string& name) {
if (!ret.empty()) {
if (IsLower(ret[0])) {
// If it starts with a lowercase letter, capitalize it.
ret[0] = ToUpper(ret[0]);
ret[0] = UpperChar(ret[0]);
} else if (!IsAlpha(ret[0])) {
// Otherwise (e.g. if it begins with an underscore), we need to come up
// with some prefix that starts with a capital letter. We could be smarter
@ -369,11 +357,9 @@ std::string RubifyConstant(const std::string& name) {
return ret;
}
void GenerateMessageAssignment(
const std::string& prefix,
const google::protobuf::Descriptor* message,
google::protobuf::io::Printer* printer) {
void GenerateMessageAssignment(const std::string& prefix,
const Descriptor* message,
io::Printer* printer) {
// Don't generate MapEntry messages -- we use the Ruby extension's native
// support for map fields instead.
if (message->options().map_entry()) {
@ -398,10 +384,8 @@ void GenerateMessageAssignment(
}
}
void GenerateEnumAssignment(
const std::string& prefix,
const google::protobuf::EnumDescriptor* en,
google::protobuf::io::Printer* printer) {
void GenerateEnumAssignment(const std::string& prefix, const EnumDescriptor* en,
io::Printer* printer) {
printer->Print(
"$prefix$$name$ = ",
"prefix", prefix,
@ -412,9 +396,7 @@ void GenerateEnumAssignment(
"full_name", en->full_name());
}
int GeneratePackageModules(
const FileDescriptor* file,
google::protobuf::io::Printer* printer) {
int GeneratePackageModules(const FileDescriptor* file, io::Printer* printer) {
int levels = 0;
bool need_change_to_module = true;
std::string package_name;
@ -466,9 +448,7 @@ int GeneratePackageModules(
return levels;
}
void EndPackageModules(
int levels,
google::protobuf::io::Printer* printer) {
void EndPackageModules(int levels, io::Printer* printer) {
while (levels > 0) {
levels--;
printer->Outdent();

@ -48,8 +48,7 @@ namespace ruby {
// If you create your own protocol compiler binary and you want it to support
// Ruby output, you can do so by registering an instance of this
// CodeGenerator with the CommandLineInterface in your main() function.
class PROTOC_EXPORT Generator
: public PROTOBUF_NAMESPACE_ID::compiler::CodeGenerator {
class PROTOC_EXPORT Generator : public CodeGenerator {
virtual bool Generate(
const FileDescriptor* file,
const string& parameter,

Loading…
Cancel
Save