Pārlūkot izejas kodu

Merge pull request #330 from anandolee/csharp

Remove ClsCompliant declarations from C# code (fix #318)
Jie Luo 10 gadi atpakaļ
vecāks
revīzija
e0afc0028f

+ 0 - 8
src/google/protobuf/compiler/csharp/csharp_extension.cc

@@ -63,11 +63,6 @@ ExtensionGenerator::~ExtensionGenerator() {
 }
 
 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$;",
                     GetFieldConstantName(descriptor_),
                     SimpleItoa(descriptor_->number()));
@@ -80,7 +75,6 @@ void ExtensionGenerator::Generate(Writer* writer) {
     //        "option message_set_wire_format = true; is not supported in Lite runtime extensions.");
     //}
 
-    AddClsComplianceCheck(writer);
     writer->Write("$0$ ", class_access_level());
     writer->WriteLine(
         "static pb::$3$<$0$, $1$> $2$;",
@@ -90,12 +84,10 @@ void ExtensionGenerator::Generate(Writer* writer) {
         descriptor_->is_repeated() ?
             "GeneratedRepeatExtensionLite" : "GeneratedExtensionLite");
   } else if (descriptor_->is_repeated()) {
-    AddClsComplianceCheck(writer);
     writer->WriteLine(
         "$0$ static pb::GeneratedExtensionBase<scg::IList<$1$>> $2$;",
         class_access_level(), type_name(), property_name());
   } else {
-    AddClsComplianceCheck(writer);
     writer->WriteLine("$0$ static pb::GeneratedExtensionBase<$1$> $2$;",
                       class_access_level(), type_name(), property_name());
   }

+ 0 - 13
src/google/protobuf/compiler/csharp/csharp_field_base.cc

@@ -79,13 +79,6 @@ void FieldGeneratorBase::AddNullCheck(Writer* writer, const std::string& name) {
 
 void FieldGeneratorBase::AddPublicMemberAttributes(Writer* 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() {
@@ -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) {
   // NaN is never equal to anything, even itself.
   return value != value;

+ 0 - 2
src/google/protobuf/compiler/csharp/csharp_field_base.h

@@ -70,14 +70,12 @@ class FieldGeneratorBase : public SourceGeneratorBase {
   void AddNullCheck(Writer* writer, const std::string& name);
 
   void AddPublicMemberAttributes(Writer* writer);
-  void AddClsComplianceCheck(Writer* writer);
 
   std::string property_name();
   std::string name();
   std::string type_name();
   bool has_default_value();
   bool is_nullable_type();
-  bool is_cls_compliant();
   std::string default_value();
   std::string number();
   std::string message_or_group();

+ 1 - 4
src/google/protobuf/compiler/csharp/csharp_generator.cc

@@ -71,10 +71,7 @@ bool Generator::Generate(
 
   std::string file_extension = ".cs";
   for (int i = 0; i < options.size(); i++) {
-    if (options[i].first == "no_cls_compliance") {
-      *error = "Turning off CLS compliance is not implemented yet.";
-      return false;
-    } else if (options[i].first == "file_extension") {
+    if (options[i].first == "file_extension") {
       file_extension = options[i].second;
     } else {
       *error = "Unknown generator option: " + options[i].first;

+ 0 - 5
src/google/protobuf/compiler/csharp/csharp_message.cc

@@ -262,11 +262,6 @@ void MessageGenerator::Generate(Writer* writer) {
 
   for (int i = 0; i < descriptor_->field_count(); 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 :(
     writer->WriteLine("public const int $0$ = $1$;",

+ 0 - 5
src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc

@@ -69,11 +69,6 @@ std::string SourceGeneratorBase::class_access_level() {
   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 compiler
 }  // namespace protobuf

+ 0 - 1
src/google/protobuf/compiler/csharp/csharp_source_generator_base.h

@@ -48,7 +48,6 @@ class SourceGeneratorBase {
   virtual ~SourceGeneratorBase();
 
   std::string class_access_level();
-  bool cls_compliance();
 
   bool optimize_size() {
     return optimizeSize_;