Unverified Commit e2dd7403 authored by Joshua Haberman's avatar Joshua Haberman Committed by GitHub

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.
parent e41e2dde
...@@ -69,10 +69,6 @@ static const char kAnyMessageName[] = "Any"; ...@@ -69,10 +69,6 @@ static const char kAnyMessageName[] = "Any";
static const char kAnyProtoFile[] = "google/protobuf/any.proto"; static const char kAnyProtoFile[] = "google/protobuf/any.proto";
static const char kGoogleProtobufPrefix[] = "google/protobuf/"; static const char kGoogleProtobufPrefix[] = "google/protobuf/";
std::string DotsToUnderscores(const std::string& name) {
return StringReplace(name, ".", "_", true);
}
std::string DotsToColons(const std::string& name) { std::string DotsToColons(const std::string& name) {
return StringReplace(name, ".", "::", true); return StringReplace(name, ".", "::", true);
} }
......
...@@ -56,7 +56,8 @@ void WriteDocCommentBodyImpl(io::Printer* printer, SourceLocation location) { ...@@ -56,7 +56,8 @@ void WriteDocCommentBodyImpl(io::Printer* printer, SourceLocation location) {
// node of a summary element, not part of an attribute. // node of a summary element, not part of an attribute.
comments = StringReplace(comments, "&", "&", true); comments = StringReplace(comments, "&", "&", true);
comments = StringReplace(comments, "<", "&lt;", 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... // 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. // but that needs to be part of a bigger effort to understand the markdown better anyway.
printer->Print("/// <summary>\n"); printer->Print("/// <summary>\n");
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -48,12 +48,13 @@ class EnumGenerator : public SourceGeneratorBase { ...@@ -48,12 +48,13 @@ class EnumGenerator : public SourceGeneratorBase {
EnumGenerator(const EnumDescriptor* descriptor, const Options* options); EnumGenerator(const EnumDescriptor* descriptor, const Options* options);
~EnumGenerator(); ~EnumGenerator();
EnumGenerator(const EnumGenerator&) = delete;
EnumGenerator& operator=(const EnumGenerator&) = delete;
void Generate(io::Printer* printer); void Generate(io::Printer* printer);
private: private:
const EnumDescriptor* descriptor_; const EnumDescriptor* descriptor_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -48,13 +48,13 @@ class EnumFieldGenerator : public PrimitiveFieldGenerator { ...@@ -48,13 +48,13 @@ class EnumFieldGenerator : public PrimitiveFieldGenerator {
const Options *options); const Options *options);
~EnumFieldGenerator(); ~EnumFieldGenerator();
EnumFieldGenerator(const EnumFieldGenerator&) = delete;
EnumFieldGenerator& operator=(const EnumFieldGenerator&) = delete;
virtual void GenerateCodecCode(io::Printer* printer); virtual void GenerateCodecCode(io::Printer* printer);
virtual void GenerateParsingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer);
virtual void GenerateSerializationCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer);
virtual void GenerateSerializedSizeCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator);
}; };
class EnumOneofFieldGenerator : public PrimitiveOneofFieldGenerator { class EnumOneofFieldGenerator : public PrimitiveOneofFieldGenerator {
...@@ -64,13 +64,13 @@ class EnumOneofFieldGenerator : public PrimitiveOneofFieldGenerator { ...@@ -64,13 +64,13 @@ class EnumOneofFieldGenerator : public PrimitiveOneofFieldGenerator {
const Options *options); const Options *options);
~EnumOneofFieldGenerator(); ~EnumOneofFieldGenerator();
EnumOneofFieldGenerator(const EnumOneofFieldGenerator&) = delete;
EnumOneofFieldGenerator& operator=(const EnumOneofFieldGenerator&) = delete;
virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer);
virtual void GenerateParsingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer);
virtual void GenerateSerializationCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer);
virtual void GenerateSerializedSizeCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumOneofFieldGenerator);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -28,17 +28,16 @@ ...@@ -28,17 +28,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cmath>
#include <limits> #include <limits>
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/coded_stream.h> #include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/stubs/mathlimits.h>
#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/wire_format.h> #include <google/protobuf/wire_format.h>
...@@ -323,7 +322,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) ...@@ -323,7 +322,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
return "double.PositiveInfinity"; return "double.PositiveInfinity";
} else if (value == -std::numeric_limits<double>::infinity()) { } else if (value == -std::numeric_limits<double>::infinity()) {
return "double.NegativeInfinity"; return "double.NegativeInfinity";
} else if (MathLimits<double>::IsNaN(value)) { } else if (std::isnan(value)) {
return "double.NaN"; return "double.NaN";
} }
return SimpleDtoa(value) + "D"; return SimpleDtoa(value) + "D";
...@@ -334,7 +333,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) ...@@ -334,7 +333,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
return "float.PositiveInfinity"; return "float.PositiveInfinity";
} else if (value == -std::numeric_limits<float>::infinity()) { } else if (value == -std::numeric_limits<float>::infinity()) {
return "float.NegativeInfinity"; return "float.NegativeInfinity";
} else if (MathLimits<float>::IsNaN(value)) { } else if (std::isnan(value)) {
return "float.NaN"; return "float.NaN";
} }
return SimpleFtoa(value) + "F"; return SimpleFtoa(value) + "F";
......
...@@ -51,6 +51,9 @@ class FieldGeneratorBase : public SourceGeneratorBase { ...@@ -51,6 +51,9 @@ class FieldGeneratorBase : public SourceGeneratorBase {
const Options* options); const Options* options);
~FieldGeneratorBase(); ~FieldGeneratorBase();
FieldGeneratorBase(const FieldGeneratorBase&) = delete;
FieldGeneratorBase& operator=(const FieldGeneratorBase&) = delete;
virtual void GenerateCloningCode(io::Printer* printer) = 0; virtual void GenerateCloningCode(io::Printer* printer) = 0;
virtual void GenerateFreezingCode(io::Printer* printer); virtual void GenerateFreezingCode(io::Printer* printer);
virtual void GenerateCodecCode(io::Printer* printer); virtual void GenerateCodecCode(io::Printer* printer);
...@@ -93,8 +96,6 @@ class FieldGeneratorBase : public SourceGeneratorBase { ...@@ -93,8 +96,6 @@ class FieldGeneratorBase : public SourceGeneratorBase {
void SetCommonFieldVariables(std::map<string, string>* variables); void SetCommonFieldVariables(std::map<string, string>* variables);
std::string GetStringDefaultValueInternal(const FieldDescriptor* descriptor); std::string GetStringDefaultValueInternal(const FieldDescriptor* descriptor);
std::string GetBytesDefaultValueInternal(const FieldDescriptor* descriptor); std::string GetBytesDefaultValueInternal(const FieldDescriptor* descriptor);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorBase);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
...@@ -49,8 +48,7 @@ namespace protobuf { ...@@ -49,8 +48,7 @@ namespace protobuf {
namespace compiler { namespace compiler {
namespace csharp { namespace csharp {
void GenerateFile(const google::protobuf::FileDescriptor* file, void GenerateFile(const FileDescriptor* file, io::Printer* printer,
io::Printer* printer,
const Options* options) { const Options* options) {
ReflectionClassGenerator reflectionClassGenerator(file, options); ReflectionClassGenerator reflectionClassGenerator(file, options);
reflectionClassGenerator.Generate(printer); reflectionClassGenerator.Generate(printer);
......
...@@ -48,8 +48,7 @@ namespace csharp { ...@@ -48,8 +48,7 @@ namespace csharp {
// header. If you create your own protocol compiler binary and you want // 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 // it to support C# output, you can do so by registering an instance of this
// CodeGenerator with the CommandLineInterface in your main() function. // CodeGenerator with the CommandLineInterface in your main() function.
class PROTOC_EXPORT Generator class PROTOC_EXPORT Generator : public CodeGenerator {
: public PROTOBUF_NAMESPACE_ID::compiler::CodeGenerator {
public: public:
virtual bool Generate( virtual bool Generate(
const FileDescriptor* file, const FileDescriptor* file,
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
// Sanjay Ghemawat, Jeff Dean, and others. // Sanjay Ghemawat, Jeff Dean, and others.
#include <algorithm> #include <algorithm>
#include <google/protobuf/stubs/hash.h>
#include <limits> #include <limits>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
...@@ -44,7 +43,6 @@ ...@@ -44,7 +43,6 @@
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h> #include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.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_field_base.h>
#include <google/protobuf/compiler/csharp/csharp_enum_field.h> #include <google/protobuf/compiler/csharp/csharp_enum_field.h>
...@@ -355,12 +353,10 @@ std::string GetPropertyName(const FieldDescriptor* descriptor) { ...@@ -355,12 +353,10 @@ std::string GetPropertyName(const FieldDescriptor* descriptor) {
return property_name; return property_name;
} }
std::string GetOutputFile( std::string GetOutputFile(const FileDescriptor* descriptor,
const google::protobuf::FileDescriptor* descriptor, const std::string file_extension,
const std::string file_extension, const bool generate_directories,
const bool generate_directories, const std::string base_namespace, string* error) {
const std::string base_namespace,
string* error) {
string relative_filename = GetFileNameBase(descriptor) + file_extension; string relative_filename = GetFileNameBase(descriptor) + file_extension;
if (!generate_directories) { if (!generate_directories) {
return relative_filename; return relative_filename;
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -48,6 +48,9 @@ class MapFieldGenerator : public FieldGeneratorBase { ...@@ -48,6 +48,9 @@ class MapFieldGenerator : public FieldGeneratorBase {
const Options* options); const Options* options);
~MapFieldGenerator(); ~MapFieldGenerator();
MapFieldGenerator(const MapFieldGenerator&) = delete;
MapFieldGenerator& operator=(const MapFieldGenerator&) = delete;
virtual void GenerateCloningCode(io::Printer* printer); virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateFreezingCode(io::Printer* printer); virtual void GenerateFreezingCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer);
...@@ -59,9 +62,6 @@ class MapFieldGenerator : public FieldGeneratorBase { ...@@ -59,9 +62,6 @@ class MapFieldGenerator : public FieldGeneratorBase {
virtual void WriteHash(io::Printer* printer); virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer); virtual void WriteEquals(io::Printer* printer);
virtual void WriteToString(io::Printer* printer); virtual void WriteToString(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldGenerator);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include <map> #include <map>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -50,6 +50,9 @@ class MessageGenerator : public SourceGeneratorBase { ...@@ -50,6 +50,9 @@ class MessageGenerator : public SourceGeneratorBase {
MessageGenerator(const Descriptor* descriptor, const Options* options); MessageGenerator(const Descriptor* descriptor, const Options* options);
~MessageGenerator(); ~MessageGenerator();
MessageGenerator(const MessageGenerator&) = delete;
MessageGenerator& operator=(const MessageGenerator&) = delete;
void GenerateCloningCode(io::Printer* printer); void GenerateCloningCode(io::Printer* printer);
void GenerateFreezingCode(io::Printer* printer); void GenerateFreezingCode(io::Printer* printer);
void GenerateFrameworkMethods(io::Printer* printer); void GenerateFrameworkMethods(io::Printer* printer);
...@@ -78,8 +81,6 @@ class MessageGenerator : public SourceGeneratorBase { ...@@ -78,8 +81,6 @@ class MessageGenerator : public SourceGeneratorBase {
// field descriptors sorted by number // field descriptors sorted by number
const std::vector<const FieldDescriptor*>& fields_by_number(); const std::vector<const FieldDescriptor*>& fields_by_number();
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -48,6 +48,9 @@ class MessageFieldGenerator : public FieldGeneratorBase { ...@@ -48,6 +48,9 @@ class MessageFieldGenerator : public FieldGeneratorBase {
const Options *options); const Options *options);
~MessageFieldGenerator(); ~MessageFieldGenerator();
MessageFieldGenerator(const MessageFieldGenerator&) = delete;
MessageFieldGenerator& operator=(const MessageFieldGenerator&) = delete;
virtual void GenerateCodecCode(io::Printer* printer); virtual void GenerateCodecCode(io::Printer* printer);
virtual void GenerateCloningCode(io::Printer* printer); virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateFreezingCode(io::Printer* printer); virtual void GenerateFreezingCode(io::Printer* printer);
...@@ -60,9 +63,6 @@ class MessageFieldGenerator : public FieldGeneratorBase { ...@@ -60,9 +63,6 @@ class MessageFieldGenerator : public FieldGeneratorBase {
virtual void WriteHash(io::Printer* printer); virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer); virtual void WriteEquals(io::Printer* printer);
virtual void WriteToString(io::Printer* printer); virtual void WriteToString(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator);
}; };
class MessageOneofFieldGenerator : public MessageFieldGenerator { class MessageOneofFieldGenerator : public MessageFieldGenerator {
...@@ -72,14 +72,15 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator { ...@@ -72,14 +72,15 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator {
const Options *options); const Options *options);
~MessageOneofFieldGenerator(); ~MessageOneofFieldGenerator();
MessageOneofFieldGenerator(const MessageOneofFieldGenerator&) = delete;
MessageOneofFieldGenerator& operator=(const MessageOneofFieldGenerator&) =
delete;
virtual void GenerateCloningCode(io::Printer* printer); virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer);
virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer);
virtual void WriteToString(io::Printer* printer); virtual void WriteToString(io::Printer* printer);
virtual void GenerateParsingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageOneofFieldGenerator);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -91,10 +91,10 @@ string PROTOC_EXPORT GetReflectionClassName(const FileDescriptor* descriptor); ...@@ -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 // 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 // of failure, this function will return empty string and error parameter
// will contain the error message. // will contain the error message.
string PROTOC_EXPORT string PROTOC_EXPORT GetOutputFile(const FileDescriptor* descriptor,
GetOutputFile(const google::protobuf::FileDescriptor* descriptor, const string file_extension,
const string file_extension, const bool generate_directories, const bool generate_directories,
const string base_namespace, string* error); const string base_namespace, string* error);
} // namespace csharp } // namespace csharp
} // namespace compiler } // namespace compiler
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include <string> #include <string>
#include <google/protobuf/stubs/common.h>
namespace google { namespace google {
namespace protobuf { namespace protobuf {
namespace compiler { namespace compiler {
...@@ -49,7 +48,7 @@ struct Options { ...@@ -49,7 +48,7 @@ struct Options {
serializable(false) { serializable(false) {
} }
// Extension of the generated file. Defaults to ".cs" // 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 "". // Base namespace to use to create directory hierarchy. Defaults to "".
// This option allows the simple creation of a conventional C# file layout, // This option allows the simple creation of a conventional C# file layout,
// where directories are created relative to a project-specific base // where directories are created relative to a project-specific base
...@@ -60,7 +59,7 @@ struct Options { ...@@ -60,7 +59,7 @@ struct Options {
// //
// If no base namespace is specified, all files are generated in the // If no base namespace is specified, all files are generated in the
// --csharp_out directory, with no subdirectories created automatically. // --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. // 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 // 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 // string, meaning "create a full directory hierarchy, starting from the first
...@@ -77,7 +76,6 @@ struct Options { ...@@ -77,7 +76,6 @@ struct Options {
} // namespace csharp } // namespace csharp
} // namespace compiler } // namespace compiler
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_OPTIONS_H__ #endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_OPTIONS_H__
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -50,6 +50,9 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase { ...@@ -50,6 +50,9 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase {
const Options *options); const Options *options);
~PrimitiveFieldGenerator(); ~PrimitiveFieldGenerator();
PrimitiveFieldGenerator(const PrimitiveFieldGenerator&) = delete;
PrimitiveFieldGenerator& operator=(const PrimitiveFieldGenerator&) = delete;
virtual void GenerateCodecCode(io::Printer* printer); virtual void GenerateCodecCode(io::Printer* printer);
virtual void GenerateCloningCode(io::Printer* printer); virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer);
...@@ -64,9 +67,6 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase { ...@@ -64,9 +67,6 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase {
protected: protected:
bool is_value_type; bool is_value_type;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator);
}; };
class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator { class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator {
...@@ -76,14 +76,15 @@ class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator { ...@@ -76,14 +76,15 @@ class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator {
const Options *options); const Options *options);
~PrimitiveOneofFieldGenerator(); ~PrimitiveOneofFieldGenerator();
PrimitiveOneofFieldGenerator(const PrimitiveOneofFieldGenerator&) = delete;
PrimitiveOneofFieldGenerator& operator=(const PrimitiveOneofFieldGenerator&) =
delete;
virtual void GenerateCloningCode(io::Printer* printer); virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer);
virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer);
virtual void WriteToString(io::Printer* printer); virtual void WriteToString(io::Printer* printer);
virtual void GenerateParsingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveOneofFieldGenerator);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -48,6 +48,9 @@ class ReflectionClassGenerator : public SourceGeneratorBase { ...@@ -48,6 +48,9 @@ class ReflectionClassGenerator : public SourceGeneratorBase {
ReflectionClassGenerator(const FileDescriptor* file, const Options* options); ReflectionClassGenerator(const FileDescriptor* file, const Options* options);
~ReflectionClassGenerator(); ~ReflectionClassGenerator();
ReflectionClassGenerator(const ReflectionClassGenerator&) = delete;
ReflectionClassGenerator& operator=(const ReflectionClassGenerator&) = delete;
void Generate(io::Printer* printer); void Generate(io::Printer* printer);
private: private:
...@@ -61,8 +64,6 @@ class ReflectionClassGenerator : public SourceGeneratorBase { ...@@ -61,8 +64,6 @@ class ReflectionClassGenerator : public SourceGeneratorBase {
void WriteGeneratedCodeInfo(const Descriptor* descriptor, void WriteGeneratedCodeInfo(const Descriptor* descriptor,
io::Printer* printer, io::Printer* printer,
bool last); bool last);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReflectionClassGenerator);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -41,8 +41,8 @@ namespace protobuf { ...@@ -41,8 +41,8 @@ namespace protobuf {
namespace compiler { namespace compiler {
namespace csharp { namespace csharp {
// TODO(jonskeet): Refactor repeated field support; all the implementations are *really* similar. We // TODO(jonskeet): Refactor repeated field support; all the implementations are
// should probably have a RepeatedFieldGeneratorBase. // *really* similar. We should probably have a RepeatedFieldGeneratorBase.
class RepeatedEnumFieldGenerator : public FieldGeneratorBase { class RepeatedEnumFieldGenerator : public FieldGeneratorBase {
public: public:
RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor, RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor,
...@@ -50,6 +50,10 @@ class RepeatedEnumFieldGenerator : public FieldGeneratorBase { ...@@ -50,6 +50,10 @@ class RepeatedEnumFieldGenerator : public FieldGeneratorBase {
const Options *options); const Options *options);
~RepeatedEnumFieldGenerator(); ~RepeatedEnumFieldGenerator();
RepeatedEnumFieldGenerator(const RepeatedEnumFieldGenerator&) = delete;
RepeatedEnumFieldGenerator& operator=(const RepeatedEnumFieldGenerator&) =
delete;
virtual void GenerateCloningCode(io::Printer* printer); virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateFreezingCode(io::Printer* printer); virtual void GenerateFreezingCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer);
...@@ -61,9 +65,6 @@ class RepeatedEnumFieldGenerator : public FieldGeneratorBase { ...@@ -61,9 +65,6 @@ class RepeatedEnumFieldGenerator : public FieldGeneratorBase {
virtual void WriteHash(io::Printer* printer); virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer); virtual void WriteEquals(io::Printer* printer);
virtual void WriteToString(io::Printer* printer); virtual void WriteToString(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -50,6 +50,10 @@ class RepeatedMessageFieldGenerator : public FieldGeneratorBase { ...@@ -50,6 +50,10 @@ class RepeatedMessageFieldGenerator : public FieldGeneratorBase {
const Options *options); const Options *options);
~RepeatedMessageFieldGenerator(); ~RepeatedMessageFieldGenerator();
RepeatedMessageFieldGenerator(const RepeatedMessageFieldGenerator&) = delete;
RepeatedMessageFieldGenerator& operator=(
const RepeatedMessageFieldGenerator&) = delete;
virtual void GenerateCloningCode(io::Printer* printer); virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateFreezingCode(io::Printer* printer); virtual void GenerateFreezingCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer);
...@@ -61,9 +65,6 @@ class RepeatedMessageFieldGenerator : public FieldGeneratorBase { ...@@ -61,9 +65,6 @@ class RepeatedMessageFieldGenerator : public FieldGeneratorBase {
virtual void WriteHash(io::Printer* printer); virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer); virtual void WriteEquals(io::Printer* printer);
virtual void WriteToString(io::Printer* printer); virtual void WriteToString(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -43,9 +43,13 @@ namespace csharp { ...@@ -43,9 +43,13 @@ namespace csharp {
class RepeatedPrimitiveFieldGenerator : public FieldGeneratorBase { class RepeatedPrimitiveFieldGenerator : public FieldGeneratorBase {
public: public:
RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, int presenceIndex, const Options *options); RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor,
int presenceIndex, const Options* options);
~RepeatedPrimitiveFieldGenerator(); ~RepeatedPrimitiveFieldGenerator();
RepeatedPrimitiveFieldGenerator(const RepeatedPrimitiveFieldGenerator&) = delete;
RepeatedPrimitiveFieldGenerator& operator=(const RepeatedPrimitiveFieldGenerator&) = delete;
virtual void GenerateCloningCode(io::Printer* printer); virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateFreezingCode(io::Printer* printer); virtual void GenerateFreezingCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer);
...@@ -57,9 +61,6 @@ class RepeatedPrimitiveFieldGenerator : public FieldGeneratorBase { ...@@ -57,9 +61,6 @@ class RepeatedPrimitiveFieldGenerator : public FieldGeneratorBase {
virtual void WriteHash(io::Printer* printer); virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer); virtual void WriteEquals(io::Printer* printer);
virtual void WriteToString(io::Printer* printer); virtual void WriteToString(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -48,6 +48,9 @@ class SourceGeneratorBase { ...@@ -48,6 +48,9 @@ class SourceGeneratorBase {
SourceGeneratorBase(const FileDescriptor* descriptor, const Options* options); SourceGeneratorBase(const FileDescriptor* descriptor, const Options* options);
virtual ~SourceGeneratorBase(); virtual ~SourceGeneratorBase();
SourceGeneratorBase(const SourceGeneratorBase&) = delete;
SourceGeneratorBase& operator=(const SourceGeneratorBase&) = delete;
std::string class_access_level(); std::string class_access_level();
const Options* options(); const Options* options();
...@@ -58,8 +61,6 @@ class SourceGeneratorBase { ...@@ -58,8 +61,6 @@ class SourceGeneratorBase {
private: private:
const FileDescriptor* descriptor_; const FileDescriptor* descriptor_;
const Options *options_; const Options *options_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceGeneratorBase);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <sstream> #include <sstream>
#include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
......
...@@ -50,6 +50,9 @@ class WrapperFieldGenerator : public FieldGeneratorBase { ...@@ -50,6 +50,9 @@ class WrapperFieldGenerator : public FieldGeneratorBase {
const Options *options); const Options *options);
~WrapperFieldGenerator(); ~WrapperFieldGenerator();
WrapperFieldGenerator(const WrapperFieldGenerator&) = delete;
WrapperFieldGenerator& operator=(const WrapperFieldGenerator&) = delete;
virtual void GenerateCodecCode(io::Printer* printer); virtual void GenerateCodecCode(io::Printer* printer);
virtual void GenerateCloningCode(io::Printer* printer); virtual void GenerateCloningCode(io::Printer* printer);
virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer);
...@@ -64,7 +67,6 @@ class WrapperFieldGenerator : public FieldGeneratorBase { ...@@ -64,7 +67,6 @@ class WrapperFieldGenerator : public FieldGeneratorBase {
private: private:
bool is_value_type; // True for int32 etc; false for bytes and string bool is_value_type; // True for int32 etc; false for bytes and string
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WrapperFieldGenerator);
}; };
class WrapperOneofFieldGenerator : public WrapperFieldGenerator { class WrapperOneofFieldGenerator : public WrapperFieldGenerator {
...@@ -74,14 +76,14 @@ class WrapperOneofFieldGenerator : public WrapperFieldGenerator { ...@@ -74,14 +76,14 @@ class WrapperOneofFieldGenerator : public WrapperFieldGenerator {
const Options *options); const Options *options);
~WrapperOneofFieldGenerator(); ~WrapperOneofFieldGenerator();
WrapperOneofFieldGenerator(const WrapperOneofFieldGenerator&) = delete;
WrapperOneofFieldGenerator& operator=(const WrapperOneofFieldGenerator&) = delete;
virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMembers(io::Printer* printer);
virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer);
virtual void GenerateParsingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer);
virtual void GenerateSerializationCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer);
virtual void GenerateSerializedSizeCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WrapperOneofFieldGenerator);
}; };
} // namespace csharp } // namespace csharp
......
...@@ -105,21 +105,6 @@ std::string FieldName(const FieldDescriptor* field) { ...@@ -105,21 +105,6 @@ std::string FieldName(const FieldDescriptor* field) {
return field_name; 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 } // namespace
void PrintGeneratedAnnotation(io::Printer* printer, char delimiter, void PrintGeneratedAnnotation(io::Printer* printer, char delimiter,
......
...@@ -43,8 +43,7 @@ namespace protobuf { ...@@ -43,8 +43,7 @@ namespace protobuf {
namespace compiler { namespace compiler {
namespace php { namespace php {
class PROTOC_EXPORT Generator class PROTOC_EXPORT Generator : public CodeGenerator {
: public PROTOBUF_NAMESPACE_ID::compiler::CodeGenerator {
virtual bool Generate( virtual bool Generate(
const FileDescriptor* file, const FileDescriptor* file,
const string& parameter, const string& parameter,
...@@ -55,12 +54,9 @@ class PROTOC_EXPORT Generator ...@@ -55,12 +54,9 @@ class PROTOC_EXPORT Generator
// To skip reserved keywords in php, some generated classname are prefixed. // To skip reserved keywords in php, some generated classname are prefixed.
// Other code generators may need following API to figure out the actual // Other code generators may need following API to figure out the actual
// classname. // classname.
PROTOC_EXPORT std::string GeneratedClassName( PROTOC_EXPORT std::string GeneratedClassName(const Descriptor* desc);
const PROTOBUF_NAMESPACE_ID::Descriptor* desc); PROTOC_EXPORT std::string GeneratedClassName(const EnumDescriptor* desc);
PROTOC_EXPORT std::string GeneratedClassName( PROTOC_EXPORT std::string GeneratedClassName(const ServiceDescriptor* desc);
const PROTOBUF_NAMESPACE_ID::EnumDescriptor* desc);
PROTOC_EXPORT std::string GeneratedClassName(
const PROTOBUF_NAMESPACE_ID::ServiceDescriptor* desc);
inline bool IsWrapperType(const FieldDescriptor* descriptor) { inline bool IsWrapperType(const FieldDescriptor* descriptor) {
return descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && return descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
......
...@@ -46,25 +46,19 @@ namespace compiler { ...@@ -46,25 +46,19 @@ namespace compiler {
namespace ruby { namespace ruby {
// Forward decls. // 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 GetRequireName(const std::string& proto_file);
std::string LabelForField(google::protobuf::FieldDescriptor* field); std::string LabelForField(FieldDescriptor* field);
std::string TypeName(google::protobuf::FieldDescriptor* field); std::string TypeName(FieldDescriptor* field);
bool GenerateMessage(const google::protobuf::Descriptor* message, bool GenerateMessage(const Descriptor* message, io::Printer* printer,
google::protobuf::io::Printer* printer, std::string* error);
std::string* error); void GenerateEnum(const EnumDescriptor* en, io::Printer* printer);
void GenerateEnum(const google::protobuf::EnumDescriptor* en, void GenerateMessageAssignment(const std::string& prefix,
google::protobuf::io::Printer* printer); const Descriptor* message, io::Printer* printer);
void GenerateMessageAssignment( void GenerateEnumAssignment(const std::string& prefix, const EnumDescriptor* en,
const std::string& prefix, io::Printer* printer);
const google::protobuf::Descriptor* message, std::string DefaultValueForField(const FieldDescriptor* field);
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);
template<class numeric_type> template<class numeric_type>
std::string NumberToString(numeric_type value) { std::string NumberToString(numeric_type value) {
...@@ -82,7 +76,7 @@ std::string GetOutputFilename(const std::string& proto_file) { ...@@ -82,7 +76,7 @@ std::string GetOutputFilename(const std::string& proto_file) {
return GetRequireName(proto_file) + ".rb"; return GetRequireName(proto_file) + ".rb";
} }
std::string LabelForField(const google::protobuf::FieldDescriptor* field) { std::string LabelForField(const FieldDescriptor* field) {
switch (field->label()) { switch (field->label()) {
case FieldDescriptor::LABEL_OPTIONAL: return "optional"; case FieldDescriptor::LABEL_OPTIONAL: return "optional";
case FieldDescriptor::LABEL_REQUIRED: return "required"; case FieldDescriptor::LABEL_REQUIRED: return "required";
...@@ -91,7 +85,7 @@ std::string LabelForField(const google::protobuf::FieldDescriptor* field) { ...@@ -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()) { switch (field->type()) {
case FieldDescriptor::TYPE_INT32: return "int32"; case FieldDescriptor::TYPE_INT32: return "int32";
case FieldDescriptor::TYPE_INT64: return "int64"; case FieldDescriptor::TYPE_INT64: return "int64";
...@@ -124,12 +118,12 @@ string StringifySyntax(FileDescriptor::Syntax syntax) { ...@@ -124,12 +118,12 @@ string StringifySyntax(FileDescriptor::Syntax syntax) {
case FileDescriptor::SYNTAX_UNKNOWN: case FileDescriptor::SYNTAX_UNKNOWN:
default: default:
GOOGLE_LOG(FATAL) << "Unsupported syntax; this generator only supports " GOOGLE_LOG(FATAL) << "Unsupported syntax; this generator only supports "
"proto2 and proto3 syntax."; "proto2 and proto3 syntax.";
return ""; return "";
} }
} }
std::string DefaultValueForField(const google::protobuf::FieldDescriptor* field) { std::string DefaultValueForField(const FieldDescriptor* field) {
switch(field->cpp_type()) { switch(field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: case FieldDescriptor::CPPTYPE_INT32:
return NumberToString(field->default_value_int32()); return NumberToString(field->default_value_int32());
...@@ -160,7 +154,7 @@ std::string DefaultValueForField(const google::protobuf::FieldDescriptor* field) ...@@ -160,7 +154,7 @@ std::string DefaultValueForField(const google::protobuf::FieldDescriptor* field)
for (int i = 0; i < default_str.length(); ++i) { for (int i = 0; i < default_str.length(); ++i) {
// Write the hex form of each byte. // Write the hex form of each byte.
os << "\\x" << std::hex << std::setw(2) 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\")"; os << "\".force_encoding(\"ASCII-8BIT\")";
} }
...@@ -171,9 +165,7 @@ std::string DefaultValueForField(const google::protobuf::FieldDescriptor* field) ...@@ -171,9 +165,7 @@ std::string DefaultValueForField(const google::protobuf::FieldDescriptor* field)
} }
} }
void GenerateField(const google::protobuf::FieldDescriptor* field, void GenerateField(const FieldDescriptor* field, io::Printer* printer) {
google::protobuf::io::Printer* printer) {
if (field->is_map()) { if (field->is_map()) {
const FieldDescriptor* key_field = const FieldDescriptor* key_field =
field->message_type()->FindFieldByNumber(1); field->message_type()->FindFieldByNumber(1);
...@@ -220,17 +212,15 @@ void GenerateField(const google::protobuf::FieldDescriptor* field, ...@@ -220,17 +212,15 @@ void GenerateField(const google::protobuf::FieldDescriptor* field,
} }
if (field->has_default_value()) { if (field->has_default_value()) {
printer->Print( printer->Print(", default: $default$", "default",
", default: $default$", DefaultValueForField(field));
"default", DefaultValueForField(field));
} }
printer->Print("\n"); printer->Print("\n");
} }
} }
void GenerateOneof(const google::protobuf::OneofDescriptor* oneof, void GenerateOneof(const OneofDescriptor* oneof, io::Printer* printer) {
google::protobuf::io::Printer* printer) {
printer->Print( printer->Print(
"oneof :$name$ do\n", "oneof :$name$ do\n",
"name", oneof->name()); "name", oneof->name());
...@@ -245,9 +235,8 @@ void GenerateOneof(const google::protobuf::OneofDescriptor* oneof, ...@@ -245,9 +235,8 @@ void GenerateOneof(const google::protobuf::OneofDescriptor* oneof,
printer->Print("end\n"); printer->Print("end\n");
} }
bool GenerateMessage(const google::protobuf::Descriptor* message, bool GenerateMessage(const Descriptor* message, io::Printer* printer,
google::protobuf::io::Printer* printer, std::string* error) {
std::string* error) {
if (message->extension_range_count() > 0 || message->extension_count() > 0) { if (message->extension_range_count() > 0 || message->extension_count() > 0) {
*error = "Extensions are not yet supported for proto2 .proto files."; *error = "Extensions are not yet supported for proto2 .proto files.";
return false; return false;
...@@ -291,8 +280,7 @@ bool GenerateMessage(const google::protobuf::Descriptor* message, ...@@ -291,8 +280,7 @@ bool GenerateMessage(const google::protobuf::Descriptor* message,
return true; return true;
} }
void GenerateEnum(const google::protobuf::EnumDescriptor* en, void GenerateEnum(const EnumDescriptor* en, io::Printer* printer) {
google::protobuf::io::Printer* printer) {
printer->Print( printer->Print(
"add_enum \"$name$\" do\n", "add_enum \"$name$\" do\n",
"name", en->full_name()); "name", en->full_name());
...@@ -318,7 +306,7 @@ bool IsUpper(char ch) { return ch >= 'A' && ch <= 'Z'; } ...@@ -318,7 +306,7 @@ bool IsUpper(char ch) { return ch >= 'A' && ch <= 'Z'; }
bool IsAlpha(char ch) { return IsLower(ch) || IsUpper(ch); } 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 // Package names in protobuf are snake_case by convention, but Ruby module
...@@ -335,7 +323,7 @@ std::string PackageToModule(const std::string& name) { ...@@ -335,7 +323,7 @@ std::string PackageToModule(const std::string& name) {
next_upper = true; next_upper = true;
} else { } else {
if (next_upper) { if (next_upper) {
result.push_back(ToUpper(name[i])); result.push_back(UpperChar(name[i]));
} else { } else {
result.push_back(name[i]); result.push_back(name[i]);
} }
...@@ -355,7 +343,7 @@ std::string RubifyConstant(const std::string& name) { ...@@ -355,7 +343,7 @@ std::string RubifyConstant(const std::string& name) {
if (!ret.empty()) { if (!ret.empty()) {
if (IsLower(ret[0])) { if (IsLower(ret[0])) {
// If it starts with a lowercase letter, capitalize it. // If it starts with a lowercase letter, capitalize it.
ret[0] = ToUpper(ret[0]); ret[0] = UpperChar(ret[0]);
} else if (!IsAlpha(ret[0])) { } else if (!IsAlpha(ret[0])) {
// Otherwise (e.g. if it begins with an underscore), we need to come up // 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 // with some prefix that starts with a capital letter. We could be smarter
...@@ -369,11 +357,9 @@ std::string RubifyConstant(const std::string& name) { ...@@ -369,11 +357,9 @@ std::string RubifyConstant(const std::string& name) {
return ret; return ret;
} }
void GenerateMessageAssignment( void GenerateMessageAssignment(const std::string& prefix,
const std::string& prefix, const Descriptor* message,
const google::protobuf::Descriptor* message, io::Printer* printer) {
google::protobuf::io::Printer* printer) {
// Don't generate MapEntry messages -- we use the Ruby extension's native // Don't generate MapEntry messages -- we use the Ruby extension's native
// support for map fields instead. // support for map fields instead.
if (message->options().map_entry()) { if (message->options().map_entry()) {
...@@ -398,10 +384,8 @@ void GenerateMessageAssignment( ...@@ -398,10 +384,8 @@ void GenerateMessageAssignment(
} }
} }
void GenerateEnumAssignment( void GenerateEnumAssignment(const std::string& prefix, const EnumDescriptor* en,
const std::string& prefix, io::Printer* printer) {
const google::protobuf::EnumDescriptor* en,
google::protobuf::io::Printer* printer) {
printer->Print( printer->Print(
"$prefix$$name$ = ", "$prefix$$name$ = ",
"prefix", prefix, "prefix", prefix,
...@@ -412,9 +396,7 @@ void GenerateEnumAssignment( ...@@ -412,9 +396,7 @@ void GenerateEnumAssignment(
"full_name", en->full_name()); "full_name", en->full_name());
} }
int GeneratePackageModules( int GeneratePackageModules(const FileDescriptor* file, io::Printer* printer) {
const FileDescriptor* file,
google::protobuf::io::Printer* printer) {
int levels = 0; int levels = 0;
bool need_change_to_module = true; bool need_change_to_module = true;
std::string package_name; std::string package_name;
...@@ -466,9 +448,7 @@ int GeneratePackageModules( ...@@ -466,9 +448,7 @@ int GeneratePackageModules(
return levels; return levels;
} }
void EndPackageModules( void EndPackageModules(int levels, io::Printer* printer) {
int levels,
google::protobuf::io::Printer* printer) {
while (levels > 0) { while (levels > 0) {
levels--; levels--;
printer->Outdent(); printer->Outdent();
......
...@@ -48,8 +48,7 @@ namespace ruby { ...@@ -48,8 +48,7 @@ namespace ruby {
// If you create your own protocol compiler binary and you want it to support // 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 // Ruby output, you can do so by registering an instance of this
// CodeGenerator with the CommandLineInterface in your main() function. // CodeGenerator with the CommandLineInterface in your main() function.
class PROTOC_EXPORT Generator class PROTOC_EXPORT Generator : public CodeGenerator {
: public PROTOBUF_NAMESPACE_ID::compiler::CodeGenerator {
virtual bool Generate( virtual bool Generate(
const FileDescriptor* file, const FileDescriptor* file,
const string& parameter, const string& parameter,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment