aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/csharp/csharp_generator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/csharp/csharp_generator.cc')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_generator.cc72
1 files changed, 24 insertions, 48 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_generator.cc b/src/google/protobuf/compiler/csharp/csharp_generator.cc
index 95ff48ae..d74e8c88 100644
--- a/src/google/protobuf/compiler/csharp/csharp_generator.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_generator.cc
@@ -41,7 +41,8 @@
#include <google/protobuf/compiler/csharp/csharp_generator.h>
#include <google/protobuf/compiler/csharp/csharp_helpers.h>
#include <google/protobuf/compiler/csharp/csharp_names.h>
-#include <google/protobuf/compiler/csharp/csharp_umbrella_class.h>
+#include <google/protobuf/compiler/csharp/csharp_options.h>
+#include <google/protobuf/compiler/csharp/csharp_reflection_class.h>
using google::protobuf::internal::scoped_ptr;
@@ -50,45 +51,11 @@ namespace protobuf {
namespace compiler {
namespace csharp {
-std::string GetOutputFile(
- const google::protobuf::FileDescriptor* file,
- const std::string file_extension,
- const bool generate_directories,
- const std::string base_namespace,
- string* error) {
- string relative_filename = GetUmbrellaClassUnqualifiedName(file) + file_extension;
- if (!generate_directories) {
- return relative_filename;
- }
- string ns = GetFileNamespace(file);
- string namespace_suffix = ns;
- if (!base_namespace.empty()) {
- // Check that the base_namespace is either equal to or a leading part of
- // the file namespace. This isn't just a simple prefix; "Foo.B" shouldn't
- // be regarded as a prefix of "Foo.Bar". The simplest option is to add "."
- // to both.
- string extended_ns = ns + ".";
- if (extended_ns.find(base_namespace + ".") != 0) {
- *error = "Namespace " + ns + " is not a prefix namespace of base namespace " + base_namespace;
- return ""; // This will be ignored, because we've set an error.
- }
- namespace_suffix = ns.substr(base_namespace.length());
- if (namespace_suffix.find(".") == 0) {
- namespace_suffix = namespace_suffix.substr(1);
- }
- }
-
- string namespace_dir = StringReplace(namespace_suffix, ".", "/", true);
- if (!namespace_dir.empty()) {
- namespace_dir += "/";
- }
- return namespace_dir + relative_filename;
-}
-
void GenerateFile(const google::protobuf::FileDescriptor* file,
- io::Printer* printer) {
- UmbrellaClassGenerator umbrellaGenerator(file);
- umbrellaGenerator.Generate(printer);
+ io::Printer* printer,
+ const Options* options) {
+ ReflectionClassGenerator reflectionClassGenerator(file, options);
+ reflectionClassGenerator.Generate(printer);
}
bool Generator::Generate(
@@ -106,15 +73,19 @@ bool Generator::Generate(
return false;
}
- std::string file_extension = ".cs";
- std::string base_namespace = "";
- bool generate_directories = false;
+ struct Options cli_options;
+
for (int i = 0; i < options.size(); i++) {
if (options[i].first == "file_extension") {
- file_extension = options[i].second;
+ cli_options.file_extension = options[i].second;
} else if (options[i].first == "base_namespace") {
- base_namespace = options[i].second;
- generate_directories = true;
+ cli_options.base_namespace = options[i].second;
+ cli_options.base_namespace_specified = true;
+ } else if (options[i].first == "internal_access") {
+ cli_options.internal_access = true;
+ } else if (options[i].first == "legacy_enum_values") {
+ // TODO: Remove this before final release
+ cli_options.legacy_enum_values = true;
} else {
*error = "Unknown generator option: " + options[i].first;
return false;
@@ -122,8 +93,13 @@ bool Generator::Generate(
}
string filename_error = "";
- std::string filename = GetOutputFile(file, file_extension, generate_directories, base_namespace, &filename_error);
- if (!filename_error.empty()) {
+ std::string filename = GetOutputFile(file,
+ cli_options.file_extension,
+ cli_options.base_namespace_specified,
+ cli_options.base_namespace,
+ &filename_error);
+
+ if (filename.empty()) {
*error = filename_error;
return false;
}
@@ -131,7 +107,7 @@ bool Generator::Generate(
generator_context->Open(filename));
io::Printer printer(output.get(), '$');
- GenerateFile(file, &printer);
+ GenerateFile(file, &printer, &cli_options);
return true;
}