Commit e0afc002 authored by Jie Luo's avatar Jie Luo

Merge pull request #330 from anandolee/csharp

Remove ClsCompliant declarations from C# code (fix #318)
parents 447de3ad d9e3063e
...@@ -63,11 +63,6 @@ ExtensionGenerator::~ExtensionGenerator() { ...@@ -63,11 +63,6 @@ ExtensionGenerator::~ExtensionGenerator() {
} }
void ExtensionGenerator::Generate(Writer* writer) { void ExtensionGenerator::Generate(Writer* writer) {
if (cls_compliance()
&& (GetFieldConstantName(descriptor_).substr(0, 1) == "_")) {
writer->WriteLine("[global::System.CLSCompliant(false)]");
}
writer->WriteLine("public const int $0$ = $1$;", writer->WriteLine("public const int $0$ = $1$;",
GetFieldConstantName(descriptor_), GetFieldConstantName(descriptor_),
SimpleItoa(descriptor_->number())); SimpleItoa(descriptor_->number()));
...@@ -80,7 +75,6 @@ void ExtensionGenerator::Generate(Writer* writer) { ...@@ -80,7 +75,6 @@ void ExtensionGenerator::Generate(Writer* writer) {
// "option message_set_wire_format = true; is not supported in Lite runtime extensions."); // "option message_set_wire_format = true; is not supported in Lite runtime extensions.");
//} //}
AddClsComplianceCheck(writer);
writer->Write("$0$ ", class_access_level()); writer->Write("$0$ ", class_access_level());
writer->WriteLine( writer->WriteLine(
"static pb::$3$<$0$, $1$> $2$;", "static pb::$3$<$0$, $1$> $2$;",
...@@ -90,12 +84,10 @@ void ExtensionGenerator::Generate(Writer* writer) { ...@@ -90,12 +84,10 @@ void ExtensionGenerator::Generate(Writer* writer) {
descriptor_->is_repeated() ? descriptor_->is_repeated() ?
"GeneratedRepeatExtensionLite" : "GeneratedExtensionLite"); "GeneratedRepeatExtensionLite" : "GeneratedExtensionLite");
} else if (descriptor_->is_repeated()) { } else if (descriptor_->is_repeated()) {
AddClsComplianceCheck(writer);
writer->WriteLine( writer->WriteLine(
"$0$ static pb::GeneratedExtensionBase<scg::IList<$1$>> $2$;", "$0$ static pb::GeneratedExtensionBase<scg::IList<$1$>> $2$;",
class_access_level(), type_name(), property_name()); class_access_level(), type_name(), property_name());
} else { } else {
AddClsComplianceCheck(writer);
writer->WriteLine("$0$ static pb::GeneratedExtensionBase<$1$> $2$;", writer->WriteLine("$0$ static pb::GeneratedExtensionBase<$1$> $2$;",
class_access_level(), type_name(), property_name()); class_access_level(), type_name(), property_name());
} }
......
...@@ -79,13 +79,6 @@ void FieldGeneratorBase::AddNullCheck(Writer* writer, const std::string& name) { ...@@ -79,13 +79,6 @@ void FieldGeneratorBase::AddNullCheck(Writer* writer, const std::string& name) {
void FieldGeneratorBase::AddPublicMemberAttributes(Writer* writer) { void FieldGeneratorBase::AddPublicMemberAttributes(Writer* writer) {
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
AddClsComplianceCheck(writer);
}
void FieldGeneratorBase::AddClsComplianceCheck(Writer* writer) {
if (cls_compliance() && !is_cls_compliant()) {
writer->WriteLine("[global::System.CLSCompliant(false)]");
}
} }
std::string FieldGeneratorBase::property_name() { std::string FieldGeneratorBase::property_name() {
...@@ -211,12 +204,6 @@ bool FieldGeneratorBase::is_nullable_type() { ...@@ -211,12 +204,6 @@ bool FieldGeneratorBase::is_nullable_type() {
} }
} }
bool FieldGeneratorBase::is_cls_compliant() {
CSharpType type = GetCSharpType(descriptor_->type());
return (type != CSHARPTYPE_UINT32) && (type != CSHARPTYPE_UINT64)
&& (UnderscoresToPascalCase(name()).substr(0, 1) != "_");
}
inline bool IsNaN(double value) { inline bool IsNaN(double value) {
// NaN is never equal to anything, even itself. // NaN is never equal to anything, even itself.
return value != value; return value != value;
......
...@@ -70,14 +70,12 @@ class FieldGeneratorBase : public SourceGeneratorBase { ...@@ -70,14 +70,12 @@ class FieldGeneratorBase : public SourceGeneratorBase {
void AddNullCheck(Writer* writer, const std::string& name); void AddNullCheck(Writer* writer, const std::string& name);
void AddPublicMemberAttributes(Writer* writer); void AddPublicMemberAttributes(Writer* writer);
void AddClsComplianceCheck(Writer* writer);
std::string property_name(); std::string property_name();
std::string name(); std::string name();
std::string type_name(); std::string type_name();
bool has_default_value(); bool has_default_value();
bool is_nullable_type(); bool is_nullable_type();
bool is_cls_compliant();
std::string default_value(); std::string default_value();
std::string number(); std::string number();
std::string message_or_group(); std::string message_or_group();
......
...@@ -71,10 +71,7 @@ bool Generator::Generate( ...@@ -71,10 +71,7 @@ bool Generator::Generate(
std::string file_extension = ".cs"; std::string file_extension = ".cs";
for (int i = 0; i < options.size(); i++) { for (int i = 0; i < options.size(); i++) {
if (options[i].first == "no_cls_compliance") { if (options[i].first == "file_extension") {
*error = "Turning off CLS compliance is not implemented yet.";
return false;
} else if (options[i].first == "file_extension") {
file_extension = options[i].second; file_extension = options[i].second;
} else { } else {
*error = "Unknown generator option: " + options[i].first; *error = "Unknown generator option: " + options[i].first;
......
...@@ -262,11 +262,6 @@ void MessageGenerator::Generate(Writer* writer) { ...@@ -262,11 +262,6 @@ void MessageGenerator::Generate(Writer* writer) {
for (int i = 0; i < descriptor_->field_count(); i++) { for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* fieldDescriptor = descriptor_->field(i); const FieldDescriptor* fieldDescriptor = descriptor_->field(i);
// TODO(jtattermusch): same code for cls compliance is in csharp_extension
if (cls_compliance()
&& GetFieldConstantName(fieldDescriptor)[0] == '_') {
writer->WriteLine("[global::System.CLSCompliant(false)]");
}
// Rats: we lose the debug comment here :( // Rats: we lose the debug comment here :(
writer->WriteLine("public const int $0$ = $1$;", writer->WriteLine("public const int $0$ = $1$;",
......
...@@ -69,11 +69,6 @@ std::string SourceGeneratorBase::class_access_level() { ...@@ -69,11 +69,6 @@ std::string SourceGeneratorBase::class_access_level() {
return "public"; // public_classes is always on. return "public"; // public_classes is always on.
} }
bool SourceGeneratorBase::cls_compliance() {
// TODO(jtattermusch): implement this based on "cls_compliance" cmdline param.
return true;
}
} // namespace csharp } // namespace csharp
} // namespace compiler } // namespace compiler
} // namespace protobuf } // namespace protobuf
......
...@@ -48,7 +48,6 @@ class SourceGeneratorBase { ...@@ -48,7 +48,6 @@ class SourceGeneratorBase {
virtual ~SourceGeneratorBase(); virtual ~SourceGeneratorBase();
std::string class_access_level(); std::string class_access_level();
bool cls_compliance();
bool optimize_size() { bool optimize_size() {
return optimizeSize_; return optimizeSize_;
......
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