Skip to content

Commit

Permalink
Compiler changes (initialized extension)
Browse files Browse the repository at this point in the history
  • Loading branch information
ObsidianMinor committed Sep 8, 2018
1 parent 45a998b commit dc7fee4
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 67 deletions.
5 changes: 0 additions & 5 deletions src/google/protobuf/compiler/csharp/csharp_field_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ FieldGeneratorBase::FieldGeneratorBase(const FieldDescriptor* descriptor,
FieldGeneratorBase::~FieldGeneratorBase() {
}

void FieldGeneratorBase::GenerateIsInitialized(io::Printer* printer) {
// No-op: only message fields and primitives need this
// default to not generating any code.
}

void FieldGeneratorBase::GenerateFreezingCode(io::Printer* printer) {
// No-op: only message fields and repeated fields need
// special handling for freezing, so default to not generating any code.
Expand Down
1 change: 0 additions & 1 deletion src/google/protobuf/compiler/csharp/csharp_field_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class FieldGeneratorBase : public SourceGeneratorBase {
virtual void WriteEquals(io::Printer* printer) = 0;
// Currently unused, as we use reflection to generate JSON
virtual void WriteToString(io::Printer* printer) = 0;
virtual void GenerateIsInitialized(io::Printer* printer);

protected:
const FieldDescriptor* descriptor_;
Expand Down
7 changes: 0 additions & 7 deletions src/google/protobuf/compiler/csharp/csharp_map_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,6 @@ void MapFieldGenerator::GenerateCloningCode(io::Printer* printer) {
"$name$_ = other.$name$_.Clone();\n");
}

void MapFieldGenerator::GenerateIsInitialized(io::Printer* printer) {
printer->Print(variables_,
"if (!$name$_.IsInitialized()) {\n"
" return false;\n"
"}\n");
}

void MapFieldGenerator::GenerateFreezingCode(io::Printer* printer) {
}

Expand Down
1 change: 0 additions & 1 deletion src/google/protobuf/compiler/csharp/csharp_map_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class MapFieldGenerator : public FieldGeneratorBase {
virtual void GenerateParsingCode(io::Printer* printer);
virtual void GenerateSerializationCode(io::Printer* printer);
virtual void GenerateSerializedSizeCode(io::Printer* printer);
virtual void GenerateIsInitialized(io::Printer* printer);

virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer);
Expand Down
14 changes: 1 addition & 13 deletions src/google/protobuf/compiler/csharp/csharp_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void MessageGenerator::Generate(io::Printer* printer) {

printer->Print(
vars,
"$access_level$ sealed partial class $class_name$ : pb::IMessage<$class_name$>, pb::IMessage2 {\n");
"$access_level$ sealed partial class $class_name$ : pb::IMessage<$class_name$> {\n");
printer->Indent();

// All static fields and properties
Expand Down Expand Up @@ -573,18 +573,6 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) {
printer->Print("}\n"); // while
printer->Outdent();
printer->Print("}\n\n"); // method

WriteGeneratedCodeAttributes(printer);
printer->Print("public bool IsInitialized() {\n");
printer->Indent();
for (int i = 0; i < fields_by_number().size(); i++) {
std::unique_ptr<FieldGeneratorBase> generator(
CreateFieldGeneratorInternal(fields_by_number()[i]));
generator->GenerateIsInitialized(printer);
}
printer->Print("return true;\n");
printer->Outdent();
printer->Print("}\n");
}

// it's a waste of space to track presence for all values, so we only track them if they're not nullable
Expand Down
19 changes: 0 additions & 19 deletions src/google/protobuf/compiler/csharp/csharp_message_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,6 @@ void MessageFieldGenerator::WriteToString(io::Printer* printer) {
variables_,
"PrintField(\"$field_name$\", has$property_name$, $name$_, writer);\n");
}
void MessageFieldGenerator::GenerateIsInitialized(io::Printer* printer) {
if (IsProto2(descriptor_->file())) {
printer->Print(
variables_,
"if ($has_property_check$) {\n"
" if (!$property_name$.IsInitialized()) {\n"
" return false;\n"
" }\n"
"}\n");
if (descriptor_->is_required()) {
printer->Print(
variables_,
"else {\n"
" return false;\n"
"}\n");
}
}
}

void MessageFieldGenerator::GenerateCloningCode(io::Printer* printer) {
printer->Print(variables_,
"$name$_ = other.$has_property_check$ ? other.$name$_.Clone() : null;\n");
Expand Down
1 change: 0 additions & 1 deletion src/google/protobuf/compiler/csharp/csharp_message_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class MessageFieldGenerator : public FieldGeneratorBase {
virtual void GenerateParsingCode(io::Printer* printer);
virtual void GenerateSerializationCode(io::Printer* printer);
virtual void GenerateSerializedSizeCode(io::Printer* printer);
virtual void GenerateIsInitialized(io::Printer* printer);

virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer);
Expand Down
10 changes: 0 additions & 10 deletions src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,6 @@ void PrimitiveFieldGenerator::GenerateCodecCode(io::Printer* printer) {
"pb::FieldCodec.For$capitalized_type_name$($tag$)");
}

void PrimitiveFieldGenerator::GenerateIsInitialized(io::Printer* printer) {
if (descriptor_->is_required()) {
printer->Print(
variables_,
"if (!$has_not_property_check$) {\n"
" return false;\n"
"}\n");
}
}

PrimitiveOneofFieldGenerator::PrimitiveOneofFieldGenerator(
const FieldDescriptor* descriptor, int presenceIndex, const Options *options)
: PrimitiveFieldGenerator(descriptor, presenceIndex, options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase {
virtual void GenerateParsingCode(io::Printer* printer);
virtual void GenerateSerializationCode(io::Printer* printer);
virtual void GenerateSerializedSizeCode(io::Printer* printer);
virtual void GenerateIsInitialized(io::Printer* printer);

virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,6 @@ void RepeatedMessageFieldGenerator::GenerateCloningCode(io::Printer* printer) {
void RepeatedMessageFieldGenerator::GenerateFreezingCode(io::Printer* printer) {
}

void RepeatedMessageFieldGenerator::GenerateIsInitialized(io::Printer* printer) {
printer->Print(
variables_,
"if (!$name$_.IsInitialized()) {\n"
" return false;\n"
"}\n");
}

} // namespace csharp
} // namespace compiler
} // namespace protobuf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class RepeatedMessageFieldGenerator : public FieldGeneratorBase {
virtual void GenerateParsingCode(io::Printer* printer);
virtual void GenerateSerializationCode(io::Printer* printer);
virtual void GenerateSerializedSizeCode(io::Printer* printer);
virtual void GenerateIsInitialized(io::Printer* printer);

virtual void WriteHash(io::Printer* printer);
virtual void WriteEquals(io::Printer* printer);
Expand Down

0 comments on commit dc7fee4

Please sign in to comment.