diff options
author | vmordovin <vmordovin@yandex-team.ru> | 2022-02-10 16:48:14 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:14 +0300 |
commit | 7c7f9bbcf57e15838d15afa94b31d8254b5d7776 (patch) | |
tree | 17073f853e6b3a1a95708e8aa0ea12fa42a717e7 | |
parent | 466f96709329ff77ded50177df94d1893a226c00 (diff) | |
download | ydb-7c7f9bbcf57e15838d15afa94b31d8254b5d7776.tar.gz |
Restoring authorship annotation for <vmordovin@yandex-team.ru>. Commit 1 of 2.
34 files changed, 652 insertions, 652 deletions
diff --git a/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp b/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp index cd96aa0565..cb88b3f37e 100644 --- a/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp +++ b/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp @@ -6,20 +6,20 @@ #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/strutil.h> - -#include "cpp_styleguide.h" + +#include "cpp_styleguide.h" #include <util/stream/output.h> - -namespace NProtobuf { -namespace NCompiler { -namespace NPlugins { - - using namespace google::protobuf; - using namespace google::protobuf::compiler; - using namespace google::protobuf::compiler::cpp; - + +namespace NProtobuf { +namespace NCompiler { +namespace NPlugins { + + using namespace google::protobuf; + using namespace google::protobuf::compiler; + using namespace google::protobuf::compiler::cpp; + typedef std::map<TProtoStringType, TProtoStringType> TVariables; - + bool GenerateYaStyle(const FileDescriptor* fileDescriptor) { const auto& extension = fileDescriptor->FindExtensionByName("GenerateYaStyle"); return extension; @@ -31,25 +31,25 @@ namespace NPlugins { } - void SetCommonFieldVariables(const FieldDescriptor* descriptor, TVariables* variables) { + void SetCommonFieldVariables(const FieldDescriptor* descriptor, TVariables* variables) { const auto& name = descriptor->name(); if (GenerateYaStyle(descriptor)) (*variables)["rname"] = UnderscoresToCamelCase(name, true); else (*variables)["rname"] = name; - (*variables)["name"] = FieldName(descriptor); - } - - TProtoStringType HeaderFileName(const FileDescriptor* file) { + (*variables)["name"] = FieldName(descriptor); + } + + TProtoStringType HeaderFileName(const FileDescriptor* file) { TProtoStringType basename = compiler::StripProto(file->name()); - return basename.append(".pb.h"); - } - - TProtoStringType SourceFileName(const FileDescriptor* file) { + return basename.append(".pb.h"); + } + + TProtoStringType SourceFileName(const FileDescriptor* file) { TProtoStringType basename = compiler::StripProto(file->name()); - return basename.append(".pb.cc"); - } - + return basename.append(".pb.cc"); + } + bool IsLiteRuntimeMessage(const Descriptor* desc) { return desc->file() != NULL && desc->file()->options().optimize_for() == google::protobuf::FileOptions::LITE_RUNTIME; } @@ -58,21 +58,21 @@ namespace NPlugins { return desc->options().map_entry(); } - class TFieldExtGenerator { - public: - TFieldExtGenerator(const FieldDescriptor* field) - : Field_(field) - { - SetCommonFieldVariables(Field_, &Variables_); - } - + class TFieldExtGenerator { + public: + TFieldExtGenerator(const FieldDescriptor* field) + : Field_(field) + { + SetCommonFieldVariables(Field_, &Variables_); + } + virtual ~TFieldExtGenerator() { - } - - virtual void GenerateAccessorDeclarations(io::Printer* printer) = 0; + } + + virtual void GenerateAccessorDeclarations(io::Printer* printer) = 0; virtual void GenerateJSONPrinting(io::Printer* printer) = 0; - - protected: + + protected: void GenerateRepeatedJSONPrinting(io::Printer* printer, const char* itemPrinter) { printer->Print("out << '[';\n"); printer->Print("{\n"); @@ -92,35 +92,35 @@ namespace NPlugins { } protected: - const FieldDescriptor* Field_; - TVariables Variables_; - }; - - - class TMessageFieldExtGenerator: public TFieldExtGenerator { - public: - TMessageFieldExtGenerator(const FieldDescriptor* field) - : TFieldExtGenerator(field) - { - } - - void GenerateAccessorDeclarations(io::Printer* printer) { + const FieldDescriptor* Field_; + TVariables Variables_; + }; + + + class TMessageFieldExtGenerator: public TFieldExtGenerator { + public: + TMessageFieldExtGenerator(const FieldDescriptor* field) + : TFieldExtGenerator(field) + { + } + + void GenerateAccessorDeclarations(io::Printer* printer) { Variables_["type"] = QualifiedClassName(Field_->message_type()); - - printer->Print(Variables_, + + printer->Print(Variables_, "inline const $type$& Get$rname$() const { return $name$(); }\n" "inline $type$* Mutable$rname$() { return mutable_$name$(); }\n"); if (Variables_.end() != Variables_.find("RName")) printer->Print(Variables_, "inline const $type$& Get$RName$() const { return $name$(); }\n" "inline $type$* Mutable$RName$() { return mutable_$name$(); }\n"); - } + } void GenerateJSONPrinting(io::Printer* printer) override { printer->Print(Variables_, "Get$rname$().PrintJSON(out);\n"); } - }; - + }; + class TMapFieldExtGenerator: public TFieldExtGenerator { public: TMapFieldExtGenerator(const FieldDescriptor* field) @@ -197,17 +197,17 @@ namespace NPlugins { const FieldDescriptor* Val_; }; - class TRepeatedMessageFieldExtGenerator: public TFieldExtGenerator { - public: - TRepeatedMessageFieldExtGenerator(const FieldDescriptor* field) - : TFieldExtGenerator(field) - { - } - - void GenerateAccessorDeclarations(io::Printer* printer) { + class TRepeatedMessageFieldExtGenerator: public TFieldExtGenerator { + public: + TRepeatedMessageFieldExtGenerator(const FieldDescriptor* field) + : TFieldExtGenerator(field) + { + } + + void GenerateAccessorDeclarations(io::Printer* printer) { Variables_["type"] = QualifiedClassName(Field_->message_type()); - - printer->Print(Variables_, + + printer->Print(Variables_, "inline const $type$& Get$rname$(size_t _index) const {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return $name$(int(_index)); }\n" "inline $type$* Mutable$rname$(size_t _index) {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return mutable_$name$(int(_index)); }\n" "inline $type$* Add$rname$() { return add_$name$(); }\n" @@ -229,39 +229,39 @@ namespace NPlugins { "inline ::google::protobuf::RepeatedPtrField< $type$ >*\n" " Mutable$RName$() { return mutable_$name$(); }\n" ); - } + } void GenerateJSONPrinting(io::Printer* printer) override { GenerateRepeatedJSONPrinting(printer, "Get$rname$(_index).PrintJSON(out)"); } - }; - - class TStringFieldExtGenerator: public TFieldExtGenerator { - public: - TStringFieldExtGenerator(const FieldDescriptor* field) - : TFieldExtGenerator(field) - { - } - - void GenerateAccessorDeclarations(io::Printer* printer) { - Variables_["pointer_type"] = Field_->type() == FieldDescriptor::TYPE_BYTES ? "void" : "char"; - - if (Field_->options().ctype() != FieldOptions::STRING) { - printer->Outdent(); - printer->Print( - " private:\n" - " // Hidden due to unknown ctype option.\n"); - printer->Indent(); - } - - printer->Print(Variables_, + }; + + class TStringFieldExtGenerator: public TFieldExtGenerator { + public: + TStringFieldExtGenerator(const FieldDescriptor* field) + : TFieldExtGenerator(field) + { + } + + void GenerateAccessorDeclarations(io::Printer* printer) { + Variables_["pointer_type"] = Field_->type() == FieldDescriptor::TYPE_BYTES ? "void" : "char"; + + if (Field_->options().ctype() != FieldOptions::STRING) { + printer->Outdent(); + printer->Print( + " private:\n" + " // Hidden due to unknown ctype option.\n"); + printer->Indent(); + } + + printer->Print(Variables_, "inline const TProtoStringType& Get$rname$() const { return $name$(); }\n" "inline void Set$rname$(const TProtoStringType& value) { set_$name$(value); }\n" "inline void Set$rname$(TProtoStringType&& value) { set_$name$(std::move(value)); }\n" "inline void Set$rname$(const char* value) { set_$name$(value); }\n" "inline void Set$rname$(const $pointer_type$* value, size_t size) { set_$name$(value, size); }\n" "inline TProtoStringType* Mutable$rname$() { return mutable_$name$(); }\n"); - + if (Variables_.end() != Variables_.find("RName")) printer->Print(Variables_, "inline const TProtoStringType& Get$RName$() const { return $name$(); }\n" @@ -272,38 +272,38 @@ namespace NPlugins { "inline TProtoStringType* Mutable$RName$() { return mutable_$name$(); }\n" ); - if (Field_->options().ctype() != FieldOptions::STRING) { - printer->Outdent(); - printer->Print(" public:\n"); - printer->Indent(); - } - - } + if (Field_->options().ctype() != FieldOptions::STRING) { + printer->Outdent(); + printer->Print(" public:\n"); + printer->Indent(); + } + + } void GenerateJSONPrinting(io::Printer* printer) override { printer->Print(Variables_, "::google::protobuf::io::PrintJSONString(out, Get$rname$());\n"); } - }; - - class TRepeatedStringFieldExtGenerator: public TFieldExtGenerator { - public: - TRepeatedStringFieldExtGenerator(const FieldDescriptor* field) - : TFieldExtGenerator(field) - { - } - - void GenerateAccessorDeclarations(io::Printer* printer) { - Variables_["pointer_type"] = Field_->type() == FieldDescriptor::TYPE_BYTES ? "void" : "char"; - - if (Field_->options().ctype() != FieldOptions::STRING) { - printer->Outdent(); - printer->Print( - " private:\n" - " // Hidden due to unknown ctype option.\n"); - printer->Indent(); - } - - printer->Print(Variables_, + }; + + class TRepeatedStringFieldExtGenerator: public TFieldExtGenerator { + public: + TRepeatedStringFieldExtGenerator(const FieldDescriptor* field) + : TFieldExtGenerator(field) + { + } + + void GenerateAccessorDeclarations(io::Printer* printer) { + Variables_["pointer_type"] = Field_->type() == FieldDescriptor::TYPE_BYTES ? "void" : "char"; + + if (Field_->options().ctype() != FieldOptions::STRING) { + printer->Outdent(); + printer->Print( + " private:\n" + " // Hidden due to unknown ctype option.\n"); + printer->Indent(); + } + + printer->Print(Variables_, "inline const TProtoStringType& Get$rname$(size_t _index) const {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return $name$(_index); }\n" "inline TProtoStringType* Mutable$rname$(size_t _index) {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return mutable_$name$(_index); }\n" "inline void Set$rname$(size_t _index, const TProtoStringType& value) {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); set_$name$(_index, value); }\n" @@ -319,10 +319,10 @@ namespace NPlugins { "inline const ::google::protobuf::RepeatedPtrField<TProtoStringType>& get_arr_$name$() const" "{ return $name$(); }\n" "inline const ::google::protobuf::RepeatedPtrField<TProtoStringType>& Get$rname$() const" - "{ return $name$(); }\n" + "{ return $name$(); }\n" "inline ::google::protobuf::RepeatedPtrField<TProtoStringType>* Mutable$rname$()" - "{ return mutable_$name$(); }\n"); - + "{ return mutable_$name$(); }\n"); + if (Variables_.end() != Variables_.find("RName")) printer->Print(Variables_, "inline const TProtoStringType& Get$RName$(size_t _index) const {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return $name$(_index); }\n" @@ -342,12 +342,12 @@ namespace NPlugins { "{ return mutable_$name$(); }\n" ); - if (Field_->options().ctype() != FieldOptions::STRING) { - printer->Outdent(); - printer->Print(" public:\n"); - printer->Indent(); - } - } + if (Field_->options().ctype() != FieldOptions::STRING) { + printer->Outdent(); + printer->Print(" public:\n"); + printer->Indent(); + } + } void GenerateJSONPrinting(io::Printer* printer) override { GenerateRepeatedJSONPrinting( @@ -355,45 +355,45 @@ namespace NPlugins { "::google::protobuf::io::PrintJSONString(out, Get$rname$(_index))" ); } - }; - - class TEnumFieldExtGenerator: public TFieldExtGenerator { - public: - TEnumFieldExtGenerator(const FieldDescriptor* field) - : TFieldExtGenerator(field) - { - } - - void GenerateAccessorDeclarations(io::Printer* printer) { - Variables_["type"] = ClassName(Field_->enum_type(), true); - - printer->Print(Variables_, + }; + + class TEnumFieldExtGenerator: public TFieldExtGenerator { + public: + TEnumFieldExtGenerator(const FieldDescriptor* field) + : TFieldExtGenerator(field) + { + } + + void GenerateAccessorDeclarations(io::Printer* printer) { + Variables_["type"] = ClassName(Field_->enum_type(), true); + + printer->Print(Variables_, "inline $type$ Get$rname$() const { return $name$(); }\n" "inline void Set$rname$($type$ value) { set_$name$(value); }\n"); - + if (Variables_.end() != Variables_.find("RName")) printer->Print(Variables_, "inline $type$ Get$RName$() const { return $name$(); } \n" "inline void Set$RName$($type$ value) { set_$name$(value); }\n" ); - } + } void GenerateJSONPrinting(io::Printer* printer) override { printer->Print(Variables_, "out << (int)Get$rname$();\n"); } - }; - - class TRepeatedEnumFieldExtGenerator: public TFieldExtGenerator { - public: - TRepeatedEnumFieldExtGenerator(const FieldDescriptor* field) - : TFieldExtGenerator(field) - { - } - - void GenerateAccessorDeclarations(io::Printer* printer) { - Variables_["type"] = ClassName(Field_->enum_type(), true); - - printer->Print(Variables_, + }; + + class TRepeatedEnumFieldExtGenerator: public TFieldExtGenerator { + public: + TRepeatedEnumFieldExtGenerator(const FieldDescriptor* field) + : TFieldExtGenerator(field) + { + } + + void GenerateAccessorDeclarations(io::Printer* printer) { + Variables_["type"] = ClassName(Field_->enum_type(), true); + + printer->Print(Variables_, "inline $type$ Get$rname$(size_t _index) const {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return $name$(_index); }\n" "inline void Set$rname$(size_t _index, $type$ value) {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); set_$name$(_index, value); }\n" "inline void Add$rname$($type$ value) { add_$name$(value); }\n" @@ -409,24 +409,24 @@ namespace NPlugins { "inline const ::google::protobuf::RepeatedField<int>& Get$RName$() const { return $name$(); }\n" "inline ::google::protobuf::RepeatedField<int>* Mutable$RName$() { return mutable_$name$(); }\n" ); - } + } void GenerateJSONPrinting(io::Printer* printer) override { GenerateRepeatedJSONPrinting(printer, "out << (int)Get$rname$(_index)"); } - }; - - class TPrimitiveFieldExtGenerator: public TFieldExtGenerator { - public: - TPrimitiveFieldExtGenerator(const FieldDescriptor* field) - : TFieldExtGenerator(field) - { - } - - void GenerateAccessorDeclarations(io::Printer* printer) { - Variables_["type"] = PrimitiveTypeName(Field_->cpp_type()); - - printer->Print(Variables_, + }; + + class TPrimitiveFieldExtGenerator: public TFieldExtGenerator { + public: + TPrimitiveFieldExtGenerator(const FieldDescriptor* field) + : TFieldExtGenerator(field) + { + } + + void GenerateAccessorDeclarations(io::Printer* printer) { + Variables_["type"] = PrimitiveTypeName(Field_->cpp_type()); + + printer->Print(Variables_, "inline $type$ Get$rname$() const { return $name$();}\n" "inline void Set$rname$($type$ value) { set_$name$(value); }\n"); if (Variables_.end() != Variables_.find("RName")) @@ -434,24 +434,24 @@ namespace NPlugins { "inline $type$ Get$RName$() const { return $name$();}\n" "inline void Set$RName$($type$ value) { set_$name$(value); }\n" ); - } + } void GenerateJSONPrinting(io::Printer* printer) override { printer->Print(Variables_, "out << Get$rname$();\n"); } - }; - - class TRepeatedPrimitiveFieldExtGenerator: public TFieldExtGenerator { - public: - TRepeatedPrimitiveFieldExtGenerator(const FieldDescriptor* field) - : TFieldExtGenerator(field) - { - } - - void GenerateAccessorDeclarations(io::Printer* printer) { - Variables_["type"] = PrimitiveTypeName(Field_->cpp_type()); - - printer->Print(Variables_, + }; + + class TRepeatedPrimitiveFieldExtGenerator: public TFieldExtGenerator { + public: + TRepeatedPrimitiveFieldExtGenerator(const FieldDescriptor* field) + : TFieldExtGenerator(field) + { + } + + void GenerateAccessorDeclarations(io::Printer* printer) { + Variables_["type"] = PrimitiveTypeName(Field_->cpp_type()); + + printer->Print(Variables_, "inline $type$ Get$rname$(size_t _index) const {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return $name$(_index); }\n" "inline void Set$rname$(size_t _index, $type$ value) {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); set_$name$(_index, value); }\n" "inline void Add$rname$($type$ value) { add_$name$(value); }\n" @@ -472,13 +472,13 @@ namespace NPlugins { "inline ::google::protobuf::RepeatedField< $type$ >*\n" " Mutable$RName$() { return mutable_$name$(); }\n" ); - } + } void GenerateJSONPrinting(io::Printer* printer) override { GenerateRepeatedJSONPrinting(printer, "out << Get$rname$(_index)"); } - }; - + }; + class TBoolFieldExtGenerator: public TPrimitiveFieldExtGenerator { public: TBoolFieldExtGenerator(const FieldDescriptor* field) @@ -608,68 +608,68 @@ namespace NPlugins { TVariables Variables_; }; - TFieldExtGenerator* MakeGenerator(const FieldDescriptor* field) { - if (field->is_repeated()) { - switch (field->cpp_type()) { - case FieldDescriptor::CPPTYPE_MESSAGE: + TFieldExtGenerator* MakeGenerator(const FieldDescriptor* field) { + if (field->is_repeated()) { + switch (field->cpp_type()) { + case FieldDescriptor::CPPTYPE_MESSAGE: if (field->is_map()) { return new TMapFieldExtGenerator(field); } - return new TRepeatedMessageFieldExtGenerator(field); + return new TRepeatedMessageFieldExtGenerator(field); case FieldDescriptor::CPPTYPE_BOOL: return new TRepeatedBoolFieldExtGenerator(field); case FieldDescriptor::CPPTYPE_FLOAT: return new TRepeatedFloatFieldExtGenerator(field); - case FieldDescriptor::CPPTYPE_STRING: - switch (field->options().ctype()) { - default: // RepeatedStringFieldExtGenerator handles unknown ctypes. - case FieldOptions::STRING: - return new TRepeatedStringFieldExtGenerator(field); - } - case FieldDescriptor::CPPTYPE_ENUM: - return new TRepeatedEnumFieldExtGenerator(field); - default: - return new TRepeatedPrimitiveFieldExtGenerator(field); - } - } else { - switch (field->cpp_type()) { - case FieldDescriptor::CPPTYPE_MESSAGE: - return new TMessageFieldExtGenerator(field); + case FieldDescriptor::CPPTYPE_STRING: + switch (field->options().ctype()) { + default: // RepeatedStringFieldExtGenerator handles unknown ctypes. + case FieldOptions::STRING: + return new TRepeatedStringFieldExtGenerator(field); + } + case FieldDescriptor::CPPTYPE_ENUM: + return new TRepeatedEnumFieldExtGenerator(field); + default: + return new TRepeatedPrimitiveFieldExtGenerator(field); + } + } else { + switch (field->cpp_type()) { + case FieldDescriptor::CPPTYPE_MESSAGE: + return new TMessageFieldExtGenerator(field); case FieldDescriptor::CPPTYPE_BOOL: return new TBoolFieldExtGenerator(field); case FieldDescriptor::CPPTYPE_FLOAT: return new TFloatFieldExtGenerator(field); - case FieldDescriptor::CPPTYPE_STRING: - switch (field->options().ctype()) { - default: // StringFieldGenerator handles unknown ctypes. - case FieldOptions::STRING: - return new TStringFieldExtGenerator(field); - } - case FieldDescriptor::CPPTYPE_ENUM: - return new TEnumFieldExtGenerator(field); - default: - return new TPrimitiveFieldExtGenerator(field); - } - } - } - - class TMessageExtGenerator { - public: - TMessageExtGenerator(const Descriptor* descriptor, OutputDirectory* outputDirectory) - : Descriptor_(descriptor) - , Classname_(ClassName(descriptor, false)) - , OutputDirectory_(outputDirectory) - { + case FieldDescriptor::CPPTYPE_STRING: + switch (field->options().ctype()) { + default: // StringFieldGenerator handles unknown ctypes. + case FieldOptions::STRING: + return new TStringFieldExtGenerator(field); + } + case FieldDescriptor::CPPTYPE_ENUM: + return new TEnumFieldExtGenerator(field); + default: + return new TPrimitiveFieldExtGenerator(field); + } + } + } + + class TMessageExtGenerator { + public: + TMessageExtGenerator(const Descriptor* descriptor, OutputDirectory* outputDirectory) + : Descriptor_(descriptor) + , Classname_(ClassName(descriptor, false)) + , OutputDirectory_(outputDirectory) + { for (int i = 0, idx = 0; i < descriptor->nested_type_count(); i++) { if (!IsAutogeneratedNestedType(descriptor->nested_type(i))) { NestedGenerators_.emplace_back(descriptor->nested_type(i), OutputDirectory_); } - } - + } + FieldGenerators_.reserve(descriptor->field_count()); - for (int i = 0; i < descriptor->field_count(); i++) { + for (int i = 0; i < descriptor->field_count(); i++) { FieldGenerators_.emplace_back(MakeGenerator(descriptor->field(i))); - } + } ExtensionGenerators_.reserve(descriptor->extension_count()); for (int i = 0; i < descriptor->extension_count(); i++) { @@ -680,17 +680,17 @@ namespace NPlugins { for (int i = 0; i < descriptor->real_oneof_decl_count(); i++) { OneofGenerators_.emplace_back(descriptor->oneof_decl(i)); } - } - - void GenerateClassDefinitionExtension() { + } + + void GenerateClassDefinitionExtension() { GenerateSaveLoadImplementation(); GenerateJSONImplementation(); - + for (auto& nestedGenerator: NestedGenerators_) { nestedGenerator.GenerateClassDefinitionExtension(); - } - } - + } + } + void GenerateDebugOutputExtension() { GenerateDebugOutput(); @@ -708,13 +708,13 @@ namespace NPlugins { } - void GenerateClassExtension() { + void GenerateClassExtension() { GenerateDebugStringImplementation(); for (auto& nestedGenerator: NestedGenerators_) { nestedGenerator.GenerateClassExtension(); } - } - + } + void GenerateDeclarations() { GenerateFieldAccessorDeclarations(); @@ -729,46 +729,46 @@ namespace NPlugins { GenerateClassDefinitionExtension(); } - private: - void GenerateFieldAccessorDeclarations() { - TProtoStringType fileName = HeaderFileName(Descriptor_->file()); - TProtoStringType scope = "class_scope:" + Descriptor_->full_name(); + private: + void GenerateFieldAccessorDeclarations() { + TProtoStringType fileName = HeaderFileName(Descriptor_->file()); + TProtoStringType scope = "class_scope:" + Descriptor_->full_name(); std::unique_ptr<io::ZeroCopyOutputStream> output( - OutputDirectory_->OpenForInsert(fileName, scope)); - io::Printer printer(output.get(), '$'); - + OutputDirectory_->OpenForInsert(fileName, scope)); + io::Printer printer(output.get(), '$'); + printer.Print("// Yandex cpp-styleguide extension\n"); - for (int i = 0; i < Descriptor_->field_count(); i++) { - const FieldDescriptor* field = Descriptor_->field(i); - - TVariables vars; - SetCommonFieldVariables(field, &vars); - + for (int i = 0; i < Descriptor_->field_count(); i++) { + const FieldDescriptor* field = Descriptor_->field(i); + + TVariables vars; + SetCommonFieldVariables(field, &vars); + const bool hasRName = (vars.end() != vars.find("RName")); - if (field->is_repeated()) { - printer.Print(vars, + if (field->is_repeated()) { + printer.Print(vars, "inline size_t $rname$Size() const { return (size_t)$name$_size(); }\n"); if (hasRName) printer.Print(vars, "inline size_t $RName$Size() const { return (size_t)$name$_size(); }\n"); } else if (field->has_presence()) { - printer.Print(vars, + printer.Print(vars, "inline bool Has$rname$() const { return has_$name$(); }\n"); if (hasRName) printer.Print(vars, "inline bool Has$RName$() const { return has_$name$(); }\n"); - } - + } + printer.Print(vars, "inline void Clear$rname$() { clear_$name$(); }\n"); if (hasRName) printer.Print(vars, "inline void Clear$RName$() { clear_$name$(); }\n"); - - // Generate type-specific accessor declarations. - FieldGenerators_[i]->GenerateAccessorDeclarations(&printer); - - printer.Print("\n"); - } + + // Generate type-specific accessor declarations. + FieldGenerators_[i]->GenerateAccessorDeclarations(&printer); + + printer.Print("\n"); + } for (auto& extensionGenerator: ExtensionGenerators_) { extensionGenerator.GenerateDeclaration(&printer); } @@ -828,8 +828,8 @@ namespace NPlugins { printer.Print("}\n"); printer.Print("// End of Yandex-specific extension\n"); } - } - + } + void GenerateJSONImplementation() { if (IsLiteRuntimeMessage(Descriptor_)) { return; @@ -924,46 +924,46 @@ namespace NPlugins { } - private: - const Descriptor* Descriptor_; + private: + const Descriptor* Descriptor_; TProtoStringType Classname_; - OutputDirectory* OutputDirectory_; + OutputDirectory* OutputDirectory_; std::vector<std::unique_ptr<TFieldExtGenerator>> FieldGenerators_; std::vector<TMessageExtGenerator> NestedGenerators_; std::vector<TExtensionGenerator> ExtensionGenerators_; std::vector<TOneofGenerator> OneofGenerators_; - }; - - class TFileExtGenerator { - public: - TFileExtGenerator(const FileDescriptor* file, OutputDirectory* output_directory) + }; + + class TFileExtGenerator { + public: + TFileExtGenerator(const FileDescriptor* file, OutputDirectory* output_directory) : File_(file) , OutputDirectory_(output_directory) - { + { MessageGenerators_.reserve(file->message_type_count()); for (size_t i = 0; i < file->message_type_count(); i++) { MessageGenerators_.emplace_back(file->message_type(i), OutputDirectory_); - } - } - - void GenerateHeaderExtensions() { + } + } + + void GenerateHeaderExtensions() { GenerateHeaderIncludeExtensions(); for (auto& messageGenerator: MessageGenerators_) { messageGenerator.GenerateTypedefOutputExtension(false); messageGenerator.GenerateDeclarations(); - } - } - - void GenerateSourceExtensions() { + } + } + + void GenerateSourceExtensions() { GenerateSourceIncludeExtensions(); for (auto& messageGenerator: MessageGenerators_) { messageGenerator.GenerateDefinitions(); - } - } - - private: + } + } + + private: void GenerateSourceIncludeExtensions() { TProtoStringType fileName = SourceFileName(File_); TProtoStringType scope = "includes"; @@ -984,38 +984,38 @@ namespace NPlugins { private: const FileDescriptor* File_; - OutputDirectory* OutputDirectory_; - size_t MessageTypeCount_; + OutputDirectory* OutputDirectory_; + size_t MessageTypeCount_; std::vector<TMessageExtGenerator> MessageGenerators_; - }; - - bool TCppStyleGuideExtensionGenerator::Generate(const FileDescriptor* file, + }; + + bool TCppStyleGuideExtensionGenerator::Generate(const FileDescriptor* file, const TProtoStringType&, - OutputDirectory* outputDirectory, + OutputDirectory* outputDirectory, TProtoStringType*) const { - - TFileExtGenerator fileGenerator(file, outputDirectory); - - // Generate header. - fileGenerator.GenerateHeaderExtensions(); - - // Generate cc file. + + TFileExtGenerator fileGenerator(file, outputDirectory); + + // Generate header. + fileGenerator.GenerateHeaderExtensions(); + + // Generate cc file. fileGenerator.GenerateSourceExtensions(); - - return true; - } - -} -} -} - -int main(int argc, char* argv[]) { + + return true; + } + +} +} +} + +int main(int argc, char* argv[]) { #ifdef _MSC_VER - // Don't print a silly message or stick a modal dialog box in my face, - // please. - _set_abort_behavior(0, ~0); -#endif // !_MSC_VER - - NProtobuf::NCompiler::NPlugins::TCppStyleGuideExtensionGenerator generator; - return google::protobuf::compiler::PluginMain(argc, argv, &generator); -} + // Don't print a silly message or stick a modal dialog box in my face, + // please. + _set_abort_behavior(0, ~0); +#endif // !_MSC_VER + + NProtobuf::NCompiler::NPlugins::TCppStyleGuideExtensionGenerator generator; + return google::protobuf::compiler::PluginMain(argc, argv, &generator); +} diff --git a/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.h b/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.h index b428730edb..3ac6650851 100644 --- a/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.h +++ b/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.h @@ -1,20 +1,20 @@ #include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/compiler/plugin.h> #include <google/protobuf/stubs/common.h> - + namespace NProtobuf::NCompiler::NPlugins { - -class TCppStyleGuideExtensionGenerator : public google::protobuf::compiler::CodeGenerator { + +class TCppStyleGuideExtensionGenerator : public google::protobuf::compiler::CodeGenerator { public: bool Generate(const google::protobuf::FileDescriptor* file, const TProtoStringType& parameter, google::protobuf::compiler::OutputDirectory* output_directory, TProtoStringType* error ) const override; - + uint64_t GetSupportedFeatures() const override { return FEATURE_PROTO3_OPTIONAL; } -}; - +}; + } // namespace NProtobuf::NCompiler::NPlugins diff --git a/library/cpp/charset/codepage.cpp b/library/cpp/charset/codepage.cpp index 0431bef31b..c42fc3160b 100644 --- a/library/cpp/charset/codepage.cpp +++ b/library/cpp/charset/codepage.cpp @@ -180,7 +180,7 @@ public: } } - inline ECharset CharsetByName(TStringBuf name) { + inline ECharset CharsetByName(TStringBuf name) { if (!name) return CODES_UNKNOWN; @@ -192,11 +192,11 @@ public: } }; -ECharset CharsetByName(TStringBuf name) { +ECharset CharsetByName(TStringBuf name) { return Singleton<TCodePageHash>()->CharsetByName(name); } -ECharset CharsetByNameOrDie(TStringBuf name) { +ECharset CharsetByNameOrDie(TStringBuf name) { ECharset result = CharsetByName(name); if (result == CODES_UNKNOWN) ythrow yexception() << "CharsetByNameOrDie: unknown charset '" << name << "'"; diff --git a/library/cpp/charset/codepage.h b/library/cpp/charset/codepage.h index 30a02a4610..f6fc72e29c 100644 --- a/library/cpp/charset/codepage.h +++ b/library/cpp/charset/codepage.h @@ -153,10 +153,10 @@ inline const CodePage* CodePageByCharset(ECharset e) { return ::NCodepagePrivate::TCodepagesMap::Instance().Get(e); } -ECharset CharsetByName(TStringBuf name); +ECharset CharsetByName(TStringBuf name); // Same as CharsetByName, but throws yexception() if name is invalid -ECharset CharsetByNameOrDie(TStringBuf name); +ECharset CharsetByNameOrDie(TStringBuf name); inline ECharset CharsetByCodePage(const CodePage* CP) { return CP->CPEnum; diff --git a/library/cpp/dns/cache.cpp b/library/cpp/dns/cache.cpp index 05c14e82fc..08ac929a9f 100644 --- a/library/cpp/dns/cache.cpp +++ b/library/cpp/dns/cache.cpp @@ -98,14 +98,14 @@ namespace { //3. replace host to alias, if exist if (A_.size()) { TReadGuard guard(LA_); - TStringBuf names[] = {"*", host}; + TStringBuf names[] = {"*", host}; for (const auto& name : names) { - TAliases::const_iterator it = A_.find(name); + TAliases::const_iterator it = A_.find(name); - if (it != A_.end()) { - host = it->second; - } + if (it != A_.end()) { + host = it->second; + } } } diff --git a/library/cpp/dns/thread.cpp b/library/cpp/dns/thread.cpp index 8b27d2d527..fbe33d5c84 100644 --- a/library/cpp/dns/thread.cpp +++ b/library/cpp/dns/thread.cpp @@ -52,7 +52,7 @@ namespace { TString Host; ui16 Port; - TManualEvent E; + TManualEvent E; TNetworkAddressPtr Result; IErrorRef Error; }; diff --git a/library/cpp/dns/ut/dns_ut.cpp b/library/cpp/dns/ut/dns_ut.cpp index aae05a742c..fc5a356b57 100644 --- a/library/cpp/dns/ut/dns_ut.cpp +++ b/library/cpp/dns/ut/dns_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/dns/cache.h> -#include <util/network/address.h> +#include <util/network/address.h> Y_UNIT_TEST_SUITE(TestDNS) { using namespace NDns; @@ -8,18 +8,18 @@ Y_UNIT_TEST_SUITE(TestDNS) { Y_UNIT_TEST(TestMagic) { UNIT_ASSERT_EXCEPTION(CachedThrResolve(TResolveInfo("?", 80)), yexception); } - + Y_UNIT_TEST(TestAsteriskAlias) { - AddHostAlias("*", "localhost"); - const TResolvedHost* rh = CachedThrResolve(TResolveInfo("yandex.ru", 80)); - UNIT_ASSERT(rh != nullptr); - + AddHostAlias("*", "localhost"); + const TResolvedHost* rh = CachedThrResolve(TResolveInfo("yandex.ru", 80)); + UNIT_ASSERT(rh != nullptr); + const TNetworkAddress& addr = rh->Addr; - for (TNetworkAddress::TIterator ai = addr.Begin(); ai != addr.End(); ai++) { - if (ai->ai_family == AF_INET || ai->ai_family == AF_INET6) { - NAddr::TAddrInfo info(&*ai); - UNIT_ASSERT(IsLoopback(info)); - } - } - } + for (TNetworkAddress::TIterator ai = addr.Begin(); ai != addr.End(); ai++) { + if (ai->ai_family == AF_INET || ai->ai_family == AF_INET6) { + NAddr::TAddrInfo info(&*ai); + UNIT_ASSERT(IsLoopback(info)); + } + } + } } diff --git a/library/cpp/enumbitset/enumbitset.h b/library/cpp/enumbitset/enumbitset.h index 41864c3a04..7857af1438 100644 --- a/library/cpp/enumbitset/enumbitset.h +++ b/library/cpp/enumbitset/enumbitset.h @@ -305,7 +305,7 @@ public: return ret; } - void FromString(TStringBuf s) { + void FromString(TStringBuf s) { static const size_t chunkSize = sizeof(typename TParent::TChunk) * 8; static const size_t numDig = chunkSize / 4; static const size_t highChunkBits = (BitsetSize + chunkSize - 1) % chunkSize + 1; @@ -326,7 +326,7 @@ public: } // TODO: Get rid of exceptions at all - bool TryFromString(TStringBuf s) { + bool TryFromString(TStringBuf s) { try { FromString(s); } catch (...) { diff --git a/library/cpp/http/io/headers.h b/library/cpp/http/io/headers.h index a71793d1c6..1ce789faf9 100644 --- a/library/cpp/http/io/headers.h +++ b/library/cpp/http/io/headers.h @@ -112,7 +112,7 @@ public: /// Записывает все заголовки контейнера в поток. /// @details Каждый заголовк записывается в виде "имя параметра: значение\r\n". void OutTo(IOutputStream* stream) const; - + /// Обменивает наборы заголовков двух контейнеров. void Swap(THttpHeaders& headers) noexcept { Headers_.swap(headers.Headers_); diff --git a/library/cpp/http/io/stream.cpp b/library/cpp/http/io/stream.cpp index 6689be684f..2e4c6b3f2e 100644 --- a/library/cpp/http/io/stream.cpp +++ b/library/cpp/http/io/stream.cpp @@ -200,10 +200,10 @@ public: return ContentEncoded_; } - inline bool HasContent() const noexcept { - return HasContentLength_ || ChunkedInput_; - } - + inline bool HasContent() const noexcept { + return HasContentLength_ || ChunkedInput_; + } + inline bool HasExpect100Continue() const noexcept { return Expect100Continue_; } @@ -273,15 +273,15 @@ private: } } - inline bool IsRequest() const { + inline bool IsRequest() const { return strnicmp(FirstLine().data(), "get", 3) == 0 || strnicmp(FirstLine().data(), "post", 4) == 0 || strnicmp(FirstLine().data(), "put", 3) == 0 || strnicmp(FirstLine().data(), "patch", 5) == 0 || strnicmp(FirstLine().data(), "head", 4) == 0 || strnicmp(FirstLine().data(), "delete", 6) == 0; - } - + } + inline void BuildInputChain() { TParsedHeaders p; @@ -344,7 +344,7 @@ private: Buffered_.Reset(&Cnull); Input_ = Streams_.Add(new TMultiInput(&Buffered_, Slave_)); - if (IsRequest() || HasContentLength_) { + if (IsRequest() || HasContentLength_) { /* * TODO - we have other cases */ @@ -448,10 +448,10 @@ bool THttpInput::ContentEncoded() const noexcept { return Impl_->ContentEncoded(); } -bool THttpInput::HasContent() const noexcept { - return Impl_->HasContent(); -} - +bool THttpInput::HasContent() const noexcept { + return Impl_->HasContent(); +} + bool THttpInput::HasExpect100Continue() const noexcept { return Impl_->HasExpect100Continue(); } @@ -663,7 +663,7 @@ private: static inline size_t ParseHttpVersion(const TString& s) { if (s.empty()) { ythrow THttpParseException() << "malformed http stream"; - } + } size_t parsed_version = 0; @@ -804,7 +804,7 @@ private: return ret; } - + inline void RebuildStream() { bool keepAlive = false; const TCompressionCodecFactory::TEncoderConstructor* encoder = nullptr; diff --git a/library/cpp/http/io/stream.h b/library/cpp/http/io/stream.h index 78ca4fc814..a552b36218 100644 --- a/library/cpp/http/io/stream.h +++ b/library/cpp/http/io/stream.h @@ -81,9 +81,9 @@ public: /// показывает объём запакованных данных, а из THttpInput мы будем вычитывать уже распакованные. bool ContentEncoded() const noexcept; - /// Returns true if Content-Length or Transfer-Encoding header received - bool HasContent() const noexcept; - + /// Returns true if Content-Length or Transfer-Encoding header received + bool HasContent() const noexcept; + bool HasExpect100Continue() const noexcept; private: diff --git a/library/cpp/http/io/stream_ut.cpp b/library/cpp/http/io/stream_ut.cpp index 1ea35df675..9737467bfc 100644 --- a/library/cpp/http/io/stream_ut.cpp +++ b/library/cpp/http/io/stream_ut.cpp @@ -1,5 +1,5 @@ #include "stream.h" -#include "chunk.h" +#include "chunk.h" #include <library/cpp/http/server/http_ex.h> @@ -331,23 +331,23 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { httpOut.Flush(); UNIT_ASSERT_VALUES_EQUAL(checkStr.size(), str.size()); } - + TString MakeHttpOutputBody(const char* body, bool encodingEnabled) { TString str; TStringOutput strOut(str); { TBufferedOutput bufOut(&strOut, 8192); THttpOutput httpOut(&bufOut); - + httpOut.EnableKeepAlive(true); httpOut.EnableCompression(true); httpOut.EnableBodyEncoding(encodingEnabled); - + httpOut << "POST / HTTP/1.1\r\n"; httpOut << "Host: yandex.ru\r\n"; httpOut << "Content-Encoding: gzip\r\n"; httpOut << "\r\n"; - + UNIT_ASSERT_VALUES_EQUAL(str.size(), 0u); httpOut << body; } @@ -376,29 +376,29 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { TString str; TStringOutput strOut(str); TBufferedOutput bufOut(&strOut, 8192); - THttpOutput httpOut(&bufOut); - - httpOut.EnableKeepAlive(true); - httpOut.EnableCompression(true); - + THttpOutput httpOut(&bufOut); + + httpOut.EnableKeepAlive(true); + httpOut.EnableCompression(true); + const char* header = "GET / HTTP/1.1\r\nHost: yandex.ru\r\n\r\n"; httpOut << header; - + unsigned curLen = str.size(); const char* body = "<html>Hello</html>"; - httpOut << body; + httpOut << body; UNIT_ASSERT_VALUES_EQUAL(curLen, str.size()); httpOut.Finish(); UNIT_ASSERT_VALUES_EQUAL(curLen + strlen(body), str.size()); - } - + } + Y_UNIT_TEST(TestMultilineHeaders) { const char* headerLine0 = "HTTP/1.1 200 OK"; const char* headerLine1 = "Content-Language: en"; const char* headerLine2 = "Vary: Accept-Encoding, "; const char* headerLine3 = "\tAccept-Language"; const char* headerLine4 = "Content-Length: 18"; - + TString endLine("\r\n"); TString r; r += headerLine0 + endLine; @@ -564,53 +564,53 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "GGLOL"); } } - + Y_UNIT_TEST(TestInputHasContent) { - { - TStringStream request; + { + TStringStream request; request << "POST / HTTP/1.1\r\n" "Host: yandex.ru\r\n" "\r\n"; - request << "HTTPDATA"; - - TStringInput input(request.Str()); - THttpInput httpInput(&input); - - UNIT_ASSERT(!httpInput.HasContent()); - UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), ""); - } - - { - TStringStream request; + request << "HTTPDATA"; + + TStringInput input(request.Str()); + THttpInput httpInput(&input); + + UNIT_ASSERT(!httpInput.HasContent()); + UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), ""); + } + + { + TStringStream request; request << "POST / HTTP/1.1\r\n" "Host: yandex.ru\r\n" "Content-Length: 8" "\r\n\r\n"; - request << "HTTPDATA"; - - TStringInput input(request.Str()); - THttpInput httpInput(&input); - - UNIT_ASSERT(httpInput.HasContent()); - UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "HTTPDATA"); - } - - { - TStringStream request; + request << "HTTPDATA"; + + TStringInput input(request.Str()); + THttpInput httpInput(&input); + + UNIT_ASSERT(httpInput.HasContent()); + UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "HTTPDATA"); + } + + { + TStringStream request; request << "POST / HTTP/1.1\r\n" "Host: yandex.ru\r\n" "Transfer-Encoding: chunked" "\r\n\r\n"; - request << "8\r\nHTTPDATA\r\n0\r\n"; - - TStringInput input(request.Str()); - THttpInput httpInput(&input); - - UNIT_ASSERT(httpInput.HasContent()); - UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "HTTPDATA"); - } - } - + request << "8\r\nHTTPDATA\r\n0\r\n"; + + TStringInput input(request.Str()); + THttpInput httpInput(&input); + + UNIT_ASSERT(httpInput.HasContent()); + UNIT_ASSERT_VALUES_EQUAL(httpInput.ReadAll(), "HTTPDATA"); + } + } + Y_UNIT_TEST(TestHttpInputHeadRequest) { class THeadOnlyInput: public IInputStream { public: diff --git a/library/cpp/http/misc/httpreqdata.cpp b/library/cpp/http/misc/httpreqdata.cpp index f6951f68cd..216afec6ff 100644 --- a/library/cpp/http/misc/httpreqdata.cpp +++ b/library/cpp/http/misc/httpreqdata.cpp @@ -2,7 +2,7 @@ #include <util/stream/mem.h> -TBaseServerRequestData::TBaseServerRequestData(SOCKET s) +TBaseServerRequestData::TBaseServerRequestData(SOCKET s) : Addr(nullptr) , Host() , Port() @@ -14,7 +14,7 @@ TBaseServerRequestData::TBaseServerRequestData(SOCKET s) { } -TBaseServerRequestData::TBaseServerRequestData(const char* qs, SOCKET s) +TBaseServerRequestData::TBaseServerRequestData(const char* qs, SOCKET s) : Addr(nullptr) , Host() , Port() @@ -27,21 +27,21 @@ TBaseServerRequestData::TBaseServerRequestData(const char* qs, SOCKET s) { } -void TBaseServerRequestData::AppendQueryString(const char* str, size_t length) { +void TBaseServerRequestData::AppendQueryString(const char* str, size_t length) { if (Y_UNLIKELY(Search)) { Y_ASSERT(strlen(Search) == SearchLength); - ModifiedQueryString.Reserve(SearchLength + length + 2); - ModifiedQueryString.Assign(Search, SearchLength); + ModifiedQueryString.Reserve(SearchLength + length + 2); + ModifiedQueryString.Assign(Search, SearchLength); if (SearchLength > 0 && Search[SearchLength - 1] != '&' && length > 0 && str[0] != '&') { - ModifiedQueryString.Append('&'); + ModifiedQueryString.Append('&'); } - ModifiedQueryString.Append(str, length); + ModifiedQueryString.Append(str, length); } else { - ModifiedQueryString.Reserve(length + 1); - ModifiedQueryString.Assign(str, length); + ModifiedQueryString.Reserve(length + 1); + ModifiedQueryString.Assign(str, length); } - ModifiedQueryString.Append('\0'); + ModifiedQueryString.Append('\0'); Search = ModifiedQueryString.data(); SearchLength = ModifiedQueryString.size() - 1; // ignore terminator } @@ -54,7 +54,7 @@ void TBaseServerRequestData::SetRemoteAddr(TStringBuf addr) { Addr = AddrData; } -const char* TBaseServerRequestData::RemoteAddr() const { +const char* TBaseServerRequestData::RemoteAddr() const { if (!Addr) { *AddrData = 0; GetRemoteAddr(Socket, AddrData, sizeof(AddrData)); @@ -89,7 +89,7 @@ TString TBaseServerRequestData::HeaderByIndex(size_t n) const noexcept { return TString(i->first) + TStringBuf(": ") + i->second; } -const char* TBaseServerRequestData::Environment(const char* key) const { +const char* TBaseServerRequestData::Environment(const char* key) const { if (stricmp(key, "REMOTE_ADDR") == 0) { const char* ip = HeaderIn("X-Real-IP"); if (ip) @@ -107,7 +107,7 @@ const char* TBaseServerRequestData::Environment(const char* key) const { return nullptr; } -void TBaseServerRequestData::Clear() { +void TBaseServerRequestData::Clear() { HeadersIn_.clear(); Addr = Path = Search = nullptr; OrigSearch = {}; @@ -115,11 +115,11 @@ void TBaseServerRequestData::Clear() { Host.clear(); Port.clear(); CurPage.remove(); - ParseBuf.Clear(); + ParseBuf.Clear(); BeginTime = MicroSeconds(); } -const char* TBaseServerRequestData::GetCurPage() const { +const char* TBaseServerRequestData::GetCurPage() const { if (!CurPage && Host) { CurPage = "http://"; CurPage += Host; @@ -136,10 +136,10 @@ const char* TBaseServerRequestData::GetCurPage() const { return CurPage.data(); } -bool TBaseServerRequestData::Parse(const char* origReq) { +bool TBaseServerRequestData::Parse(const char* origReq) { size_t origReqLength = strlen(origReq); - ParseBuf.Assign(origReq, origReqLength + 1); - char* req = ParseBuf.Data(); + ParseBuf.Assign(origReq, origReqLength + 1); + char* req = ParseBuf.Data(); while (*req == ' ' || *req == '\t') req++; diff --git a/library/cpp/http/misc/httpreqdata.h b/library/cpp/http/misc/httpreqdata.h index 16e59c4d78..d4a12cf8cf 100644 --- a/library/cpp/http/misc/httpreqdata.h +++ b/library/cpp/http/misc/httpreqdata.h @@ -13,19 +13,19 @@ #include <util/system/yassert.h> #include <util/generic/string.h> #include <util/datetime/base.h> -#include <util/generic/buffer.h> +#include <util/generic/buffer.h> using THttpHeadersContainer = THashMap<TString, TString, TCIOps, TCIOps>; -class TBaseServerRequestData { +class TBaseServerRequestData { public: - TBaseServerRequestData(SOCKET s = INVALID_SOCKET); - TBaseServerRequestData(const char* qs, SOCKET s = INVALID_SOCKET); + TBaseServerRequestData(SOCKET s = INVALID_SOCKET); + TBaseServerRequestData(const char* qs, SOCKET s = INVALID_SOCKET); void SetHost(const TString& host, ui16 port) { - Host = host; - Port = ToString(port); - } + Host = host; + Port = ToString(port); + } const TString& ServerName() const { return Host; @@ -100,26 +100,26 @@ private: SOCKET Socket; ui64 BeginTime; mutable TString CurPage; - TBuffer ParseBuf; - TBuffer ModifiedQueryString; -}; + TBuffer ParseBuf; + TBuffer ModifiedQueryString; +}; class TServerRequestData: public TBaseServerRequestData { public: - TServerRequestData(SOCKET s = INVALID_SOCKET) - : TBaseServerRequestData(s) - { - } - TServerRequestData(const char* qs, SOCKET s = INVALID_SOCKET) - : TBaseServerRequestData(qs, s) - { - Scan(); - } - - void Scan() { - CgiParam.Scan(QueryStringBuf()); - } - -public: + TServerRequestData(SOCKET s = INVALID_SOCKET) + : TBaseServerRequestData(s) + { + } + TServerRequestData(const char* qs, SOCKET s = INVALID_SOCKET) + : TBaseServerRequestData(qs, s) + { + Scan(); + } + + void Scan() { + CgiParam.Scan(QueryStringBuf()); + } + +public: TCgiParameters CgiParam; }; diff --git a/library/cpp/http/server/http_ex.cpp b/library/cpp/http/server/http_ex.cpp index e07db22bfc..d90049387a 100644 --- a/library/cpp/http/server/http_ex.cpp +++ b/library/cpp/http/server/http_ex.cpp @@ -4,10 +4,10 @@ #include <util/generic/cast.h> #include <util/stream/null.h> -bool THttpClientRequestExtension::Parse(char* req, TBaseServerRequestData& rd) { - rd.SetSocket(Socket()); +bool THttpClientRequestExtension::Parse(char* req, TBaseServerRequestData& rd) { + rd.SetSocket(Socket()); - if (!rd.Parse(req)) { + if (!rd.Parse(req)) { Output() << "HTTP/1.1 403 Forbidden\r\n" "Content-Type: text/plain\r\n" "Content-Length: 39\r\n" @@ -20,7 +20,7 @@ bool THttpClientRequestExtension::Parse(char* req, TBaseServerRequestData& rd) { return true; } -bool THttpClientRequestExtension::ProcessHeaders(TBaseServerRequestData& rd, TBlob& postData) { +bool THttpClientRequestExtension::ProcessHeaders(TBaseServerRequestData& rd, TBlob& postData) { for (const auto& header : ParsedHeaders) { rd.AddHeader(header.first, header.second); } diff --git a/library/cpp/http/server/http_ex.h b/library/cpp/http/server/http_ex.h index 1ef43ea4fd..ba982796d3 100644 --- a/library/cpp/http/server/http_ex.h +++ b/library/cpp/http/server/http_ex.h @@ -5,24 +5,24 @@ #include <library/cpp/http/misc/httpreqdata.h> class THttpClientRequestExtension: public TClientRequest { -public: - bool Parse(char* req, TBaseServerRequestData& rd); - bool ProcessHeaders(TBaseServerRequestData& rd, TBlob& postData); -}; +public: + bool Parse(char* req, TBaseServerRequestData& rd); + bool ProcessHeaders(TBaseServerRequestData& rd, TBlob& postData); +}; -template <class TRequestData> +template <class TRequestData> class THttpClientRequestExtImpl: public THttpClientRequestExtension { protected: - bool Parse(char* req) { - return THttpClientRequestExtension::Parse(req, RD); - } - bool ProcessHeaders() { - return THttpClientRequestExtension::ProcessHeaders(RD, Buf); - } + bool Parse(char* req) { + return THttpClientRequestExtension::Parse(req, RD); + } + bool ProcessHeaders() { + return THttpClientRequestExtension::ProcessHeaders(RD, Buf); + } -protected: - TRequestData RD; +protected: + TRequestData RD; TBlob Buf; }; - -using THttpClientRequestEx = THttpClientRequestExtImpl<TServerRequestData>; + +using THttpClientRequestEx = THttpClientRequestExtImpl<TServerRequestData>; diff --git a/library/cpp/streams/bzip2/bzip2.cpp b/library/cpp/streams/bzip2/bzip2.cpp index bccc5c6807..d2c02e3bae 100644 --- a/library/cpp/streams/bzip2/bzip2.cpp +++ b/library/cpp/streams/bzip2/bzip2.cpp @@ -182,23 +182,23 @@ TBZipCompress::~TBZipCompress() { } void TBZipCompress::DoWrite(const void* buf, size_t size) { - if (!Impl_) { + if (!Impl_) { ythrow TBZipCompressError() << "can not write to finished bzip stream"; - } - + } + Impl_->Write(buf, size); } void TBZipCompress::DoFlush() { if (Impl_) { - Impl_->Flush(); - } + Impl_->Flush(); + } } void TBZipCompress::DoFinish() { - THolder<TImpl> impl(Impl_.Release()); - + THolder<TImpl> impl(Impl_.Release()); + if (impl) { - impl->Finish(); - } + impl->Finish(); + } } diff --git a/library/cpp/streams/lz/lz.cpp b/library/cpp/streams/lz/lz.cpp index b65bb3ed96..e743797968 100644 --- a/library/cpp/streams/lz/lz.cpp +++ b/library/cpp/streams/lz/lz.cpp @@ -41,12 +41,12 @@ public: */ static_assert(sizeof(TCompressor::signature) - 1 == SIGNATURE_SIZE, "expect sizeof(TCompressor::signature) - 1 == SIGNATURE_SIZE"); Slave_->Write(TCompressor::signature, sizeof(TCompressor::signature) - 1); - + /* * save version */ this->Save((ui32)1); - + /* * save block size */ diff --git a/library/cpp/streams/lzma/lzma.cpp b/library/cpp/streams/lzma/lzma.cpp index f1942fa546..011b450436 100644 --- a/library/cpp/streams/lzma/lzma.cpp +++ b/library/cpp/streams/lzma/lzma.cpp @@ -495,10 +495,10 @@ void TLzmaCompress::DoWrite(const void* buf, size_t len) { } void TLzmaCompress::DoFinish() { - THolder<TImpl> impl(Impl_.Release()); - + THolder<TImpl> impl(Impl_.Release()); + if (impl) { - impl->Finish(); + impl->Finish(); } } diff --git a/library/cpp/threading/atomic/bool.cpp b/library/cpp/threading/atomic/bool.cpp index 37917e01f1..9dd6d2cc7e 100644 --- a/library/cpp/threading/atomic/bool.cpp +++ b/library/cpp/threading/atomic/bool.cpp @@ -1 +1 @@ -#include "bool.h" +#include "bool.h" diff --git a/library/cpp/threading/atomic/bool.h b/library/cpp/threading/atomic/bool.h index d52544e762..13b5e5356a 100644 --- a/library/cpp/threading/atomic/bool.h +++ b/library/cpp/threading/atomic/bool.h @@ -1,36 +1,36 @@ #pragma once -#include <util/system/atomic.h> - -namespace NAtomic { - class TBool { - public: - TBool() noexcept = default; - - TBool(bool val) noexcept - : Val_(val) - { - } - +#include <util/system/atomic.h> + +namespace NAtomic { + class TBool { + public: + TBool() noexcept = default; + + TBool(bool val) noexcept + : Val_(val) + { + } + TBool(const TBool& src) noexcept { AtomicSet(Val_, AtomicGet(src.Val_)); } - operator bool() const noexcept { - return AtomicGet(Val_); - } - + operator bool() const noexcept { + return AtomicGet(Val_); + } + const TBool& operator=(bool val) noexcept { - AtomicSet(Val_, val); - return *this; - } - + AtomicSet(Val_, val); + return *this; + } + const TBool& operator=(const TBool& src) noexcept { - AtomicSet(Val_, AtomicGet(src.Val_)); - return *this; - } - - private: - TAtomic Val_ = 0; - }; + AtomicSet(Val_, AtomicGet(src.Val_)); + return *this; + } + + private: + TAtomic Val_ = 0; + }; } diff --git a/library/cpp/threading/atomic/bool_ut.cpp b/library/cpp/threading/atomic/bool_ut.cpp index 9481f41d8d..4f417e090f 100644 --- a/library/cpp/threading/atomic/bool_ut.cpp +++ b/library/cpp/threading/atomic/bool_ut.cpp @@ -1,31 +1,31 @@ -#include "bool.h" - +#include "bool.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(AtomicBool) { Y_UNIT_TEST(ReadWrite) { - NAtomic::TBool v; - - UNIT_ASSERT_VALUES_EQUAL((bool)v, false); - - v = true; - - UNIT_ASSERT_VALUES_EQUAL((bool)v, true); - - v = false; - - UNIT_ASSERT_VALUES_EQUAL((bool)v, false); - - NAtomic::TBool v2; - - UNIT_ASSERT(v == v2); - - v2 = true; - - UNIT_ASSERT(v != v2); - - v = v2; - - UNIT_ASSERT(v == v2); - } -} + NAtomic::TBool v; + + UNIT_ASSERT_VALUES_EQUAL((bool)v, false); + + v = true; + + UNIT_ASSERT_VALUES_EQUAL((bool)v, true); + + v = false; + + UNIT_ASSERT_VALUES_EQUAL((bool)v, false); + + NAtomic::TBool v2; + + UNIT_ASSERT(v == v2); + + v2 = true; + + UNIT_ASSERT(v != v2); + + v = v2; + + UNIT_ASSERT(v == v2); + } +} diff --git a/library/cpp/threading/atomic/ut/ya.make b/library/cpp/threading/atomic/ut/ya.make index 3c555685df..2cdf002704 100644 --- a/library/cpp/threading/atomic/ut/ya.make +++ b/library/cpp/threading/atomic/ut/ya.make @@ -1,9 +1,9 @@ UNITTEST_FOR(library/cpp/threading/atomic) - -OWNER(vmordovin) - -SRCS( - bool_ut.cpp -) - -END() + +OWNER(vmordovin) + +SRCS( + bool_ut.cpp +) + +END() diff --git a/library/cpp/threading/atomic/ya.make b/library/cpp/threading/atomic/ya.make index c3a3ef8a76..6d7989bff0 100644 --- a/library/cpp/threading/atomic/ya.make +++ b/library/cpp/threading/atomic/ya.make @@ -1,9 +1,9 @@ -LIBRARY() - -OWNER(vmordovin) - -SRCS( - bool.cpp -) - -END() +LIBRARY() + +OWNER(vmordovin) + +SRCS( + bool.cpp +) + +END() diff --git a/library/cpp/threading/task_scheduler/task_scheduler_ut.cpp b/library/cpp/threading/task_scheduler/task_scheduler_ut.cpp index 3b5203194a..d94e4bfeab 100644 --- a/library/cpp/threading/task_scheduler/task_scheduler_ut.cpp +++ b/library/cpp/threading/task_scheduler/task_scheduler_ut.cpp @@ -1,86 +1,86 @@ -#include <algorithm> +#include <algorithm> #include <library/cpp/testing/unittest/registar.h> - + #include <util/stream/output.h> #include <util/system/atomic.h> #include <util/generic/vector.h> - + #include "task_scheduler.h" - -class TTaskSchedulerTest: public TTestBase { - UNIT_TEST_SUITE(TTaskSchedulerTest); - UNIT_TEST(Test); - UNIT_TEST_SUITE_END(); - + +class TTaskSchedulerTest: public TTestBase { + UNIT_TEST_SUITE(TTaskSchedulerTest); + UNIT_TEST(Test); + UNIT_TEST_SUITE_END(); + class TCheckTask: public TTaskScheduler::IRepeatedTask { - public: + public: TCheckTask(const TDuration& delay) : Start_(Now()) , Delay_(delay) - { + { AtomicIncrement(ScheduledTaskCounter_); - } - + } + ~TCheckTask() override { - } - + } + bool Process() override { const TDuration delay = Now() - Start_; - + if (delay < Delay_) { AtomicIncrement(BadTimeoutCounter_); - } - + } + AtomicIncrement(ExecutedTaskCounter_); return false; - } - - static bool AllTaskExecuted() { + } + + static bool AllTaskExecuted() { return AtomicGet(ScheduledTaskCounter_) == AtomicGet(ExecutedTaskCounter_); - } - - static size_t BadTimeoutCount() { + } + + static size_t BadTimeoutCount() { return AtomicGet(BadTimeoutCounter_); - } - - private: + } + + private: TInstant Start_; TDuration Delay_; static TAtomic BadTimeoutCounter_; static TAtomic ScheduledTaskCounter_; static TAtomic ExecutedTaskCounter_; - }; - - public: - inline void Test() { - ScheduleCheckTask(200); - ScheduleCheckTask(100); - ScheduleCheckTask(1000); - ScheduleCheckTask(10000); - ScheduleCheckTask(5000); - + }; + + public: + inline void Test() { + ScheduleCheckTask(200); + ScheduleCheckTask(100); + ScheduleCheckTask(1000); + ScheduleCheckTask(10000); + ScheduleCheckTask(5000); + Scheduler_.Start(); - - usleep(1000000); - - UNIT_ASSERT_EQUAL(TCheckTask::BadTimeoutCount(), 0); - UNIT_ASSERT(TCheckTask::AllTaskExecuted()); - } - - private: - void ScheduleCheckTask(size_t delay) { + + usleep(1000000); + + UNIT_ASSERT_EQUAL(TCheckTask::BadTimeoutCount(), 0); + UNIT_ASSERT(TCheckTask::AllTaskExecuted()); + } + + private: + void ScheduleCheckTask(size_t delay) { TDuration d = TDuration::MicroSeconds(delay); Scheduler_.Add(new TCheckTask(d), d); - } - - private: + } + + private: TTaskScheduler Scheduler_; -}; - +}; + TAtomic TTaskSchedulerTest::TCheckTask::BadTimeoutCounter_ = 0; TAtomic TTaskSchedulerTest::TCheckTask::ScheduledTaskCounter_ = 0; TAtomic TTaskSchedulerTest::TCheckTask::ExecutedTaskCounter_ = 0; - -UNIT_TEST_SUITE_REGISTRATION(TTaskSchedulerTest); + +UNIT_TEST_SUITE_REGISTRATION(TTaskSchedulerTest); diff --git a/library/cpp/ya.make b/library/cpp/ya.make index 8c1193b007..8a338d3b9a 100644 --- a/library/cpp/ya.make +++ b/library/cpp/ya.make @@ -398,7 +398,7 @@ RECURSE( vowpalwabbit/tools vowpalwabbit/ut watchdog - watchdog/timeout/ut + watchdog/timeout/ut wordlistreader xml xmlrpc diff --git a/util/memory/pool.h b/util/memory/pool.h index 13c8b6b9ed..dc4a4fdc02 100644 --- a/util/memory/pool.h +++ b/util/memory/pool.h @@ -307,8 +307,8 @@ private: }; template <typename TPool> -struct TPoolableBase { - inline void* operator new(size_t bytes, TPool& pool) { +struct TPoolableBase { + inline void* operator new(size_t bytes, TPool& pool) { return pool.Allocate(bytes); } @@ -326,9 +326,9 @@ private: inline void* operator new(size_t); // disallow default allocation }; -struct TPoolable: public TPoolableBase<TMemoryPool> { -}; - +struct TPoolable: public TPoolableBase<TMemoryPool> { +}; + class TMemoryPoolAllocator: public IAllocator { public: inline TMemoryPoolAllocator(TMemoryPool* pool) @@ -350,8 +350,8 @@ private: TMemoryPool* Pool_; }; -template <class T, class TPool> -class TPoolAllocBase { +template <class T, class TPool> +class TPoolAllocBase { public: using pointer = T*; using const_pointer = const T*; @@ -415,8 +415,8 @@ private: }; template <class T> -using TPoolAlloc = TPoolAllocBase<T, TMemoryPool>; - +using TPoolAlloc = TPoolAllocBase<T, TMemoryPool>; + // Any type since it is supposed to be rebound anyway. using TPoolAllocator = TPoolAlloc<int>; diff --git a/util/network/socket.cpp b/util/network/socket.cpp index 4f6e804346..8e8cbf6b5d 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -283,7 +283,7 @@ void SetSocketTimeout(SOCKET s, long sec, long msec) { #endif } -void SetLinger(SOCKET s, bool on, unsigned len) { +void SetLinger(SOCKET s, bool on, unsigned len) { #ifdef SO_LINGER struct linger l = {on, (u_short)len}; @@ -1162,10 +1162,10 @@ static inline void SetNonBlockSocket(SOCKET fd, int value) { unsigned long outbuf = 0; DWORD written = 0; - if (!inbuf) { + if (!inbuf) { WSAEventSelect(fd, nullptr, 0); - } - + } + if (WSAIoctl(fd, FIONBIO, &inbuf, sizeof(inbuf), &outbuf, sizeof(outbuf), &written, 0, 0) == SOCKET_ERROR) { ythrow TSystemError() << "can not set non block socket state"; } diff --git a/util/stream/buffered.cpp b/util/stream/buffered.cpp index a00e592e1c..2356522efd 100644 --- a/util/stream/buffered.cpp +++ b/util/stream/buffered.cpp @@ -250,15 +250,15 @@ public: try { Flush(); } catch (...) { - try { + try { DoFinish(); - } catch (...) { + } catch (...) { // ¯\_(ツ)_/¯ - } - + } + throw; - } - + } + DoFinish(); } diff --git a/util/stream/file.cpp b/util/stream/file.cpp index dc5d2f6311..73c709f0f9 100644 --- a/util/stream/file.cpp +++ b/util/stream/file.cpp @@ -67,7 +67,7 @@ void TUnbufferedFileOutput::DoWrite(const void* buf, size_t len) { void TUnbufferedFileOutput::DoFlush() { if (File_.IsOpen()) { File_.Flush(); - } + } } class TMappedFileInput::TImpl: public TBlob { diff --git a/util/stream/zlib.cpp b/util/stream/zlib.cpp index 60f4e9439f..6f6322c123 100644 --- a/util/stream/zlib.cpp +++ b/util/stream/zlib.cpp @@ -356,25 +356,25 @@ TZLibCompress::~TZLibCompress() { } void TZLibCompress::DoWrite(const void* buf, size_t size) { - if (!Impl_) { + if (!Impl_) { ythrow TZLibCompressorError() << "can not write to finished zlib stream"; - } - + } + Impl_->Write(buf, size); } void TZLibCompress::DoFlush() { if (Impl_) { - Impl_->Flush(); - } + Impl_->Flush(); + } } void TZLibCompress::DoFinish() { - THolder<TImpl> impl(Impl_.Release()); - + THolder<TImpl> impl(Impl_.Release()); + if (impl) { - impl->Finish(); - } + impl->Finish(); + } } TBufferedZLibDecompress::~TBufferedZLibDecompress() = default; diff --git a/util/system/hp_timer.cpp b/util/system/hp_timer.cpp index e4c3f21e6b..42fc4d0c29 100644 --- a/util/system/hp_timer.cpp +++ b/util/system/hp_timer.cpp @@ -16,7 +16,7 @@ namespace { } static inline const TFreq& Instance() { - return *SingletonWithPriority<TFreq, 1>(); + return *SingletonWithPriority<TFreq, 1>(); } static double EstimateCPUClock() { diff --git a/util/thread/pool.cpp b/util/thread/pool.cpp index 05fad02e9b..d734c98a5d 100644 --- a/util/thread/pool.cpp +++ b/util/thread/pool.cpp @@ -501,7 +501,7 @@ private: AllDone_ = true; - while (AtomicGet(ThrCount_)) { + while (AtomicGet(ThrCount_)) { Mutex_.Release(); CondReady_.Signal(); Mutex_.Acquire(); diff --git a/util/ysaveload.h b/util/ysaveload.h index 02efb4049b..1ea12687c5 100644 --- a/util/ysaveload.h +++ b/util/ysaveload.h @@ -23,8 +23,8 @@ public: enum { IsSerializablePod = TTypeTraits<T>::IsPod && !std::is_pointer<T>::value }; -}; - +}; + struct TSerializeException: public yexception { }; |