Skip to content

Commit

Permalink
Xcode defaut indents
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyxo committed Mar 6, 2017
1 parent 6802155 commit 6571f61
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 135 deletions.
12 changes: 6 additions & 6 deletions plugin/PBCompiler/PBCompiler.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,23 @@
3F6112541D85AB9500DE3C9D /* main.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cc; sourceTree = "<group>"; };
3F6112551D85AB9500DE3C9D /* Makefile.am */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Makefile.am; sourceTree = "<group>"; };
3F6112561D85AB9500DE3C9D /* RESERVEDWORDS */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RESERVEDWORDS; sourceTree = "<group>"; };
3F6112571D85AB9500DE3C9D /* swift_enum.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = swift_enum.cc; sourceTree = "<group>"; };
3F6112571D85AB9500DE3C9D /* swift_enum.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = swift_enum.cc; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
3F6112581D85AB9500DE3C9D /* swift_enum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = swift_enum.h; sourceTree = "<group>"; };
3F6112591D85AB9500DE3C9D /* swift_enum_field.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = swift_enum_field.cc; sourceTree = "<group>"; };
3F6112591D85AB9500DE3C9D /* swift_enum_field.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = swift_enum_field.cc; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
3F61125A1D85AB9500DE3C9D /* swift_enum_field.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = swift_enum_field.h; sourceTree = "<group>"; };
3F61125B1D85AB9500DE3C9D /* swift_extension.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = swift_extension.cc; sourceTree = "<group>"; };
3F61125C1D85AB9500DE3C9D /* swift_extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = swift_extension.h; sourceTree = "<group>"; };
3F61125D1D85AB9500DE3C9D /* swift_field.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = swift_field.cc; sourceTree = "<group>"; };
3F61125E1D85AB9500DE3C9D /* swift_field.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = swift_field.h; sourceTree = "<group>"; };
3F61125F1D85AB9500DE3C9D /* swift_file.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = swift_file.cc; sourceTree = "<group>"; };
3F61125F1D85AB9500DE3C9D /* swift_file.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = swift_file.cc; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
3F6112601D85AB9500DE3C9D /* swift_file.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = swift_file.h; sourceTree = "<group>"; };
3F6112611D85AB9500DE3C9D /* swift_generator.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = swift_generator.cc; sourceTree = "<group>"; };
3F6112621D85AB9500DE3C9D /* swift_generator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = swift_generator.h; sourceTree = "<group>"; };
3F6112631D85AB9500DE3C9D /* swift_helpers.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = swift_helpers.cc; sourceTree = "<group>"; };
3F6112631D85AB9500DE3C9D /* swift_helpers.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = swift_helpers.cc; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
3F6112641D85AB9500DE3C9D /* swift_helpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = swift_helpers.h; sourceTree = "<group>"; };
3F6112651D85AB9500DE3C9D /* swift_map_field.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = swift_map_field.cc; sourceTree = "<group>"; };
3F6112651D85AB9500DE3C9D /* swift_map_field.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = swift_map_field.cc; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
3F6112661D85AB9500DE3C9D /* swift_map_field.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = swift_map_field.h; sourceTree = "<group>"; };
3F6112671D85AB9500DE3C9D /* swift_message.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = swift_message.cc; sourceTree = "<group>"; };
3F6112671D85AB9500DE3C9D /* swift_message.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = swift_message.cc; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
3F6112681D85AB9500DE3C9D /* swift_message.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = swift_message.h; sourceTree = "<group>"; };
3F6112691D85AB9500DE3C9D /* swift_message_field.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = swift_message_field.cc; sourceTree = "<group>"; };
3F61126A1D85AB9500DE3C9D /* swift_message_field.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = swift_message_field.h; sourceTree = "<group>"; };
Expand Down
2 changes: 1 addition & 1 deletion plugin/ProtocolBuffers/ProtocolBuffers/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.0.12</string>
<string>3.0.13</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
45 changes: 31 additions & 14 deletions plugin/compiler/swift_enum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ namespace google { namespace protobuf { namespace compiler { namespace swift {
}

if (HasOptionForGenerateErrors(descriptor_)) {
printer->Print("$acontrol$ enum $classname$:Error, RawRepresentable, CustomDebugStringConvertible, CustomStringConvertible {\n",
printer->Print("$acontrol$ enum $classname$:Error, RawRepresentable, CustomDebugStringConvertible, CustomStringConvertible, Hashable {\n",
"classname",ClassName(descriptor_),
"acontrol", GetAccessControlType(descriptor_->file()));
printer->Indent();
XCodeStandartIndent(printer);
printer->Print("$acontrol$ typealias RawValue = Int32\n\n", "acontrol", GetAccessControlType(descriptor_->file()));
printer->Outdent();
XCodeStandartOutdent(printer);


} else {
printer->Print("$acontrol$ enum $classname$:Int32, CustomDebugStringConvertible, CustomStringConvertible {\n",
printer->Print("$acontrol$ enum $classname$:Int32, CustomDebugStringConvertible, CustomStringConvertible, Hashable {\n",
"classname",ClassName(descriptor_),
"acontrol", GetAccessControlType(descriptor_->file()));

}


printer->Indent();
XCodeStandartIndent(printer);
GenerateCaseFields(printer);

if (HasOptionForGenerateErrors(descriptor_)) {
Expand Down Expand Up @@ -124,7 +124,8 @@ namespace google { namespace protobuf { namespace compiler { namespace swift {


GenerateDescription(printer);
printer->Outdent();
GenerateHash(printer);
XCodeStandartOutdent(printer);
printer->Print(
"}\n"
"\n");
Expand Down Expand Up @@ -158,16 +159,16 @@ namespace google { namespace protobuf { namespace compiler { namespace swift {
void EnumGenerator::GenerateMethodThrow(io::Printer* printer) {

printer->Print("$acontrol$ func throwException() throws {\n","acontrol", GetAccessControlType(descriptor_->file()));
printer->Indent();
XCodeStandartIndent(printer);
printer->Print("throw self\n");
printer->Outdent();
XCodeStandartOutdent(printer);
printer->Print("}\n");
}

void EnumGenerator::GenerateInit(io::Printer* printer) {

printer->Print("$acontrol$ init?(rawValue: RawValue) {\n","acontrol", GetAccessControlType(descriptor_->file()));
printer->Indent();
XCodeStandartIndent(printer);
printer->Print("switch rawValue {\n");
for (int i = 0; i < canonical_values_.size(); i++) {
printer->Print("case $value$: self = .$name$\n",
Expand All @@ -177,14 +178,14 @@ namespace google { namespace protobuf { namespace compiler { namespace swift {
}
printer->Print("default: return nil\n");
printer->Print("}\n");
printer->Outdent();
XCodeStandartOutdent(printer);
printer->Print("}\n");
}

void EnumGenerator::GenerateRawRepresentable(io::Printer* printer) {

printer->Print("$acontrol$ var rawValue: RawValue {\n","acontrol", GetAccessControlType(descriptor_->file()));
printer->Indent();
XCodeStandartIndent(printer);
printer->Print("switch self {\n");
for (int i = 0; i < canonical_values_.size(); i++) {
printer->Print("case .$name$: return $value$\n",
Expand All @@ -193,7 +194,7 @@ namespace google { namespace protobuf { namespace compiler { namespace swift {

}
printer->Print("}\n");
printer->Outdent();
XCodeStandartOutdent(printer);
printer->Print("}\n");
}

Expand All @@ -206,18 +207,34 @@ namespace google { namespace protobuf { namespace compiler { namespace swift {
"acontrol", GetAccessControlType(descriptor_->file()));

printer->Print("private func getDescription() -> String { \n");
printer->Indent();
XCodeStandartIndent(printer);
printer->Print("switch self {\n");
for (int i = 0; i < canonical_values_.size(); i++) {
printer->Print("case .$name$: return \".$name$\"\n",
"name", EnumValueName(canonical_values_[i])
);
}
printer->Print("}\n");
printer->Outdent();
XCodeStandartOutdent(printer);
printer->Print("}\n");

}

void EnumGenerator::GenerateHash(io::Printer* printer) {
printer->Print("$acontrol$ var hashValue:Int {\n","acontrol", GetAccessControlType(descriptor_->file()));
XCodeStandartIndent(printer);
printer->Print("return self.rawValue.hashValue\n");
XCodeStandartOutdent(printer);
printer->Print("}\n");

printer->Print("$acontrol$ static func ==(lhs:$className$, rhs:$className$) -> Bool {\n",
"acontrol", GetAccessControlType(descriptor_->file()),
"className", ClassName(descriptor_));
XCodeStandartIndent(printer);
printer->Print("return lhs.hashValue == rhs.hashValue\n");
XCodeStandartOutdent(printer);
printer->Print("}\n");
}
} // namespace swift
} // namespace compiler
} // namespace protobuf
Expand Down
1 change: 1 addition & 0 deletions plugin/compiler/swift_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace google {
void GenerateRawRepresentable(io::Printer* printer);
void GenerateInit(io::Printer* printer);
void GenerateMethodThrow(io::Printer* printer);
void GenerateHash(io::Printer* printer);
vector<const EnumValueDescriptor*> canonical_values_;

struct Alias {
Expand Down
20 changes: 10 additions & 10 deletions plugin/compiler/swift_enum_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ namespace google { namespace protobuf { namespace compiler { namespace swift {
void EnumFieldGenerator::GenerateSetSubscript(io::Printer* printer) const {

printer->Print(variables_,"case \"$name_reserved$\":\n");
printer->Indent();
XCodeStandartIndent(printer);
printer->Print(variables_,"guard let newSubscriptValue = newSubscriptValue as? $type$ else {\n");
printer->Indent();
XCodeStandartIndent(printer);
printer->Print(variables_,"return\n");
printer->Outdent();
XCodeStandartOutdent(printer);
printer->Print(variables_,"}\n");
printer->Print(variables_,"self.$name_reserved$ = newSubscriptValue\n");
printer->Outdent();
XCodeStandartOutdent(printer);

}

Expand Down Expand Up @@ -255,7 +255,7 @@ namespace google { namespace protobuf { namespace compiler { namespace swift {
void EnumFieldGenerator::GenerateHashCodeSource(io::Printer* printer) const {
printer->Print(variables_,
"if has$capitalized_name$ {\n"
" hashCode = (hashCode &* 31) &+ Int($name_reserved$.rawValue)\n"
" hashCode = (hashCode &* 31) &+ $name_reserved$.hashValue\n"
"}\n");
}

Expand Down Expand Up @@ -295,14 +295,14 @@ namespace google { namespace protobuf { namespace compiler { namespace swift {
}
void RepeatedEnumFieldGenerator::GenerateSetSubscript(io::Printer* printer) const {
printer->Print(variables_,"case \"$name_reserved$\":\n");
printer->Indent();
XCodeStandartIndent(printer);
printer->Print(variables_,"guard let newSubscriptValue = newSubscriptValue as? Array<$type$> else {\n");
printer->Indent();
XCodeStandartIndent(printer);
printer->Print(variables_,"return\n");
printer->Outdent();
XCodeStandartOutdent(printer);
printer->Print(variables_,"}\n");
printer->Print(variables_,"self.$name_reserved$ = newSubscriptValue\n");
printer->Outdent();
XCodeStandartOutdent(printer);
}

void RepeatedEnumFieldGenerator::GenerateInitializationSource(io::Printer* printer) const {
Expand Down Expand Up @@ -475,7 +475,7 @@ namespace google { namespace protobuf { namespace compiler { namespace swift {
void RepeatedEnumFieldGenerator::GenerateHashCodeSource(io::Printer* printer) const {
printer->Print(variables_,
"for oneValueOf$name$ in $name_reserved$ {\n"
" hashCode = (hashCode &* 31) &+ Int(oneValueOf$name$.rawValue)\n"
" hashCode = (hashCode &* 31) &+ oneValueOf$name$.hashValue\n"
"}\n");
}
} // namespace swift
Expand Down
28 changes: 10 additions & 18 deletions plugin/compiler/swift_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ namespace google { namespace protobuf { namespace compiler {namespace swift {
FileGenerator file_generator(file_);

vector<string> tokens = FullNameSplit(file_);


//for (int i = 0; i < file_->message_type_count(); i++) {
// MessageGenerator(file_->message_type(i)).GenerateMessageIsEqualSource(printer);
//}


//fields
for (int i = 0; i < file_->extension_count(); i++) {
ExtensionGenerator(ExtensionFileClassName(file_), file_->extension(i)).GenerateFieldsGetterSource(printer, FileClassName(file_));
Expand All @@ -70,15 +65,15 @@ namespace google { namespace protobuf { namespace compiler {namespace swift {
printer->Print("$acontrol$ extension $package$ {\n",
"acontrol", GetAccessControlType(file_),
"package", PackageExtensionName(tokens));
printer->Indent();
XCodeStandartIndent(printer);
}


printer->Print("$acontrol$ struct $classname$ {\n",
"classname", classname_,
"acontrol", GetAccessControlType(file_));

printer->Indent();
XCodeStandartIndent(printer);
printer->Print("$acontrol$ static let `default` = $classname$()\n",
"classname", classname_,
"acontrol", GetAccessControlType(file_));
Expand All @@ -92,14 +87,13 @@ namespace google { namespace protobuf { namespace compiler {namespace swift {
MessageGenerator(file_->message_type(i)).GenerateStaticVariablesSource(printer);
}

//TODO
printer->Print("$acontrol$ var extensionRegistry:ExtensionRegistry\n",
"acontrol", GetAccessControlType(file_));
printer->Print(
"\n"
"init() {\n");

printer->Indent();
XCodeStandartIndent(printer);


for (int i = 0; i < file_->extension_count(); i++) {
Expand All @@ -118,29 +112,29 @@ namespace google { namespace protobuf { namespace compiler {namespace swift {
"dependency", FileClassName(file_->dependency(i)));
}

printer->Outdent();
XCodeStandartOutdent(printer);
printer->Print("}\n");


printer->Print("$acontrol$ func registerAllExtensions(registry: ExtensionRegistry) {\n",
"acontrol", GetAccessControlType(file_));

printer->Indent();
XCodeStandartIndent(printer);
for (int i = 0; i < file_->extension_count(); i++) {
ExtensionGenerator(classname_, file_->extension(i)).GenerateRegistrationSource(printer);
}

for (int i = 0; i < file_->message_type_count(); i++) {
MessageGenerator(file_->message_type(i)).GenerateExtensionRegistrationSource(printer);
}
printer->Outdent();
XCodeStandartOutdent(printer);
printer->Print("}\n");

for (int i = 0; i < file_->extension_count(); i++) {
ExtensionGenerator(classname_, file_->extension(i)).GenerateMembersSourceExtensions(printer,classname_);
}

printer->Outdent();
XCodeStandartOutdent(printer);
printer->Print("}\n\n");

///
Expand All @@ -155,7 +149,7 @@ namespace google { namespace protobuf { namespace compiler {namespace swift {
}

if (tokens.size() > 0) {
printer->Outdent();
XCodeStandartOutdent(printer);
printer->Print("}\n");
}

Expand All @@ -164,9 +158,7 @@ namespace google { namespace protobuf { namespace compiler {namespace swift {
MessageGenerator(file_->message_type(i)).GenerateBuilderExtensions(printer);
}

printer->Print(
"\n"
"// @@protoc_insertion_point(global_scope)\n");
printer->Print("\n""// @@protoc_insertion_point(global_scope)\n");
}


Expand Down
10 changes: 8 additions & 2 deletions plugin/compiler/swift_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/common.h>

#include "swift_file.h"
#include "swift_helpers.h"
Expand Down Expand Up @@ -68,8 +69,13 @@ namespace google { namespace protobuf { namespace compiler { namespace swift {
io::Printer printer(output.get(), '$');


printer.Print("// Generated by the Protocol Buffers 3.2 compiler. DO NOT EDIT!\n"
"// Source file \"$filePath$\"\n","filePath", FileNameDescription(file));
printer.Print("// Generated by the Protocol Buffers $version$ compiler. DO NOT EDIT!\n"
"// Source file \"$filePath$\"\n",
"filePath", FileNameDescription(file),
"version",
internal::VersionString(GOOGLE_PROTOBUF_VERSION));
printer.Print("// Protobuf-swift version: $version$\n", "version", SWIFT_PROTOBUF_VERSION);

if (file->syntax() == FileDescriptor::SYNTAX_PROTO2) {
printer.Print("// Syntax \"Proto2\"\n\n");
} else {
Expand Down
Loading

0 comments on commit 6571f61

Please sign in to comment.