[GitHub] thrift issue #1084: THRIFT-3773 Swift 3 Native Library

2016-10-26 Thread ChristopherRogers
Github user ChristopherRogers commented on the issue:

https://github.com/apache/thrift/pull/1084
  
I have not. 👍


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library

2016-09-24 Thread ChristopherRogers
Github user ChristopherRogers commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1084#discussion_r80357625
  
--- Diff: lib/swift/Sources/TMultiplexedProtocol.swift ---
@@ -0,0 +1,47 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+public class TMultiplexedProtocol: 
TWrappedProtocol {
+  public let separator = ":"
+
+  public var serviceName = ""
+  
+  public convenience init(on transport: TTransport, serviceName: String) {
+self.init(on: transport)
+self.serviceName = serviceName
+  }
+
+  override public func writeMessageBegin(name: String,
+ type messageType: TMessageType,
+ sequenceID: Int32) throws {
+switch messageType {
+case .call, .oneway:
+  var serviceFunction = serviceName
+  serviceFunction += serviceName == "" ? "" : separator
+  serviceFunction += name
+  return try super.writeMessageBegin(name: serviceFunction,
+ type: messageType,
+ sequenceID: sequenceID)
+default:
--- End diff --

I would omit `default` and instead explicitly list the remaining cases for 
switch statements like this where the compiler can prove that all cases were 
exhausted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library

2016-09-24 Thread ChristopherRogers
Github user ChristopherRogers commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1084#discussion_r80357489
  
--- Diff: lib/swift/Sources/TProtocol.swift ---
@@ -0,0 +1,182 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+import Foundation
+//
+
+public enum TMessageType: Int32 {
+  case call = 1
+  case reply = 2
+  case exception = 3
+  case oneway = 4
+}
+
+public enum TType: Int32 {
+  case stop = 0
+  case void = 1
+  case bool = 2
+  case byte = 3
--- End diff --

'byte' is deprecated in the IDL, so I would go with 'i8' instead. 
Relatedly, the read/write methods need to use `Int8` instead of `UInt8`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library

2016-09-24 Thread ChristopherRogers
Github user ChristopherRogers commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1084#discussion_r80355496
  
--- Diff: compiler/cpp/src/generate/t_swift_3_generator.cc ---
@@ -0,0 +1,2458 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include "t_oop_generator.h"
+#include "platform.h"
+
+using std::map;
+using std::ostream;
+using std::ofstream;
+using std::ostringstream;
+using std::set;
+using std::string;
+using std::stringstream;
+using std::vector;
+
+static const string endl = "\n"; // avoid ostream << std::endl flushes
+
+/**
+ * Swift 3 code generator.
+ *
+ * Designed from the Swift/Cocoa code generator(s)
+ */
+class t_swift_3_generator : public t_oop_generator {
+public:
+  t_swift_3_generator(t_program* program,
+const map<string, string>& parsed_options,
+const string& option_string)
+: t_oop_generator(program) {
+(void)option_string;
+map<string, string>::const_iterator iter;
+
+log_unexpected_ = false;
+async_clients_ = false;
+debug_descriptions_ = false;
+no_strict_ = false;
+
+for( iter = parsed_options.begin(); iter != parsed_options.end(); 
++iter) {
+  if( iter->first.compare("log_unexpected") == 0) {
+log_unexpected_ = true;
+  } else if( iter->first.compare("async_clients") == 0) {
+async_clients_ = true;
+  } else if( iter->first.compare("no_strict") == 0) {
+no_strict_ = true;
+  } else if( iter->first.compare("debug_descriptions") == 0) {
+debug_descriptions_ = true;
+  } else {
+throw "unknown option swift:" + iter->first;
+  }
+}
+
+out_dir_base_ = "gen-swift";
+  }
+
+  /**
+   * Init and close methods
+   */
+
+  void init_generator();
+  void close_generator();
+
+  void generate_consts(vector<t_const*> consts);
+
+  /**
+   * Program-level generation functions
+   */
+
+  void generate_typedef(t_typedef* ttypedef);
+  void generate_enum(t_enum* tenum);
+  void generate_struct(t_struct* tstruct);
+  void generate_xception(t_struct* txception);
+  void generate_service(t_service* tservice);
+
+  void print_const_value(ostream& out,
+ string name,
+ t_type* type,
+ t_const_value* value,
+ bool defval = false,
+ bool is_property = false);
+  void render_const_value(ostream& out,
+  t_type* type,
+  t_const_value* value);
+
+  void generate_swift_struct(ofstream& out,
+ t_struct* tstruct,
+ bool is_private,
+ bool is_result);
+  void generate_swift_struct_init(ofstream& out,
+  t_struct* tstruct,
+  bool all,
+  bool is_private);
+
+  void generate_swift_struct_implementation(ofstream& out,
+t_struct* tstruct,
+bool is_result,
+bool is_private);
+  void generate_swift_struct_hashable_extension(ofstream& out,
+t_struct* tstruct,
+bool is_private);
+  void generate_swift_struct_equatable_

[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library

2016-09-24 Thread ChristopherRogers
Github user ChristopherRogers commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1084#discussion_r80357106
  
--- Diff: compiler/cpp/src/generate/t_swift_3_generator.cc ---
@@ -0,0 +1,2458 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include "t_oop_generator.h"
+#include "platform.h"
+
+using std::map;
+using std::ostream;
+using std::ofstream;
+using std::ostringstream;
+using std::set;
+using std::string;
+using std::stringstream;
+using std::vector;
+
+static const string endl = "\n"; // avoid ostream << std::endl flushes
+
+/**
+ * Swift 3 code generator.
+ *
+ * Designed from the Swift/Cocoa code generator(s)
+ */
+class t_swift_3_generator : public t_oop_generator {
+public:
+  t_swift_3_generator(t_program* program,
+const map<string, string>& parsed_options,
+const string& option_string)
+: t_oop_generator(program) {
+(void)option_string;
+map<string, string>::const_iterator iter;
+
+log_unexpected_ = false;
+async_clients_ = false;
+debug_descriptions_ = false;
+no_strict_ = false;
+
+for( iter = parsed_options.begin(); iter != parsed_options.end(); 
++iter) {
+  if( iter->first.compare("log_unexpected") == 0) {
+log_unexpected_ = true;
+  } else if( iter->first.compare("async_clients") == 0) {
+async_clients_ = true;
+  } else if( iter->first.compare("no_strict") == 0) {
+no_strict_ = true;
+  } else if( iter->first.compare("debug_descriptions") == 0) {
+debug_descriptions_ = true;
+  } else {
+throw "unknown option swift:" + iter->first;
+  }
+}
+
+out_dir_base_ = "gen-swift";
+  }
+
+  /**
+   * Init and close methods
+   */
+
+  void init_generator();
+  void close_generator();
+
+  void generate_consts(vector<t_const*> consts);
+
+  /**
+   * Program-level generation functions
+   */
+
+  void generate_typedef(t_typedef* ttypedef);
+  void generate_enum(t_enum* tenum);
+  void generate_struct(t_struct* tstruct);
+  void generate_xception(t_struct* txception);
+  void generate_service(t_service* tservice);
+
+  void print_const_value(ostream& out,
+ string name,
+ t_type* type,
+ t_const_value* value,
+ bool defval = false,
+ bool is_property = false);
+  void render_const_value(ostream& out,
+  t_type* type,
+  t_const_value* value);
+
+  void generate_swift_struct(ofstream& out,
+ t_struct* tstruct,
+ bool is_private,
+ bool is_result);
+  void generate_swift_struct_init(ofstream& out,
+  t_struct* tstruct,
+  bool all,
+  bool is_private);
+
+  void generate_swift_struct_implementation(ofstream& out,
+t_struct* tstruct,
+bool is_result,
+bool is_private);
+  void generate_swift_struct_hashable_extension(ofstream& out,
+t_struct* tstruct,
+bool is_private);
+  void generate_swift_struct_equatable_

[GitHub] thrift pull request #1084: THRIFT-3773 Swift 3 Native Library

2016-09-24 Thread ChristopherRogers
Github user ChristopherRogers commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1084#discussion_r80355989
  
--- Diff: compiler/cpp/src/generate/t_swift_3_generator.cc ---
@@ -0,0 +1,2458 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include "t_oop_generator.h"
+#include "platform.h"
+
+using std::map;
+using std::ostream;
+using std::ofstream;
+using std::ostringstream;
+using std::set;
+using std::string;
+using std::stringstream;
+using std::vector;
+
+static const string endl = "\n"; // avoid ostream << std::endl flushes
+
+/**
+ * Swift 3 code generator.
+ *
+ * Designed from the Swift/Cocoa code generator(s)
+ */
+class t_swift_3_generator : public t_oop_generator {
+public:
+  t_swift_3_generator(t_program* program,
+const map<string, string>& parsed_options,
+const string& option_string)
+: t_oop_generator(program) {
+(void)option_string;
+map<string, string>::const_iterator iter;
+
+log_unexpected_ = false;
+async_clients_ = false;
+debug_descriptions_ = false;
+no_strict_ = false;
+
+for( iter = parsed_options.begin(); iter != parsed_options.end(); 
++iter) {
+  if( iter->first.compare("log_unexpected") == 0) {
+log_unexpected_ = true;
+  } else if( iter->first.compare("async_clients") == 0) {
+async_clients_ = true;
+  } else if( iter->first.compare("no_strict") == 0) {
+no_strict_ = true;
+  } else if( iter->first.compare("debug_descriptions") == 0) {
+debug_descriptions_ = true;
+  } else {
+throw "unknown option swift:" + iter->first;
+  }
+}
+
+out_dir_base_ = "gen-swift";
+  }
+
+  /**
+   * Init and close methods
+   */
+
+  void init_generator();
+  void close_generator();
+
+  void generate_consts(vector<t_const*> consts);
+
+  /**
+   * Program-level generation functions
+   */
+
+  void generate_typedef(t_typedef* ttypedef);
+  void generate_enum(t_enum* tenum);
+  void generate_struct(t_struct* tstruct);
+  void generate_xception(t_struct* txception);
+  void generate_service(t_service* tservice);
+
+  void print_const_value(ostream& out,
+ string name,
+ t_type* type,
+ t_const_value* value,
+ bool defval = false,
+ bool is_property = false);
+  void render_const_value(ostream& out,
+  t_type* type,
+  t_const_value* value);
+
+  void generate_swift_struct(ofstream& out,
+ t_struct* tstruct,
+ bool is_private,
+ bool is_result);
+  void generate_swift_struct_init(ofstream& out,
+  t_struct* tstruct,
+  bool all,
+  bool is_private);
+
+  void generate_swift_struct_implementation(ofstream& out,
+t_struct* tstruct,
+bool is_result,
+bool is_private);
+  void generate_swift_struct_hashable_extension(ofstream& out,
+t_struct* tstruct,
+bool is_private);
+  void generate_swift_struct_equatable_

[GitHub] thrift issue #1084: THRIFT-3773 Swift 3 Native Library

2016-09-11 Thread ChristopherRogers
Github user ChristopherRogers commented on the issue:

https://github.com/apache/thrift/pull/1084
  
I noticed you haven't special cased unions (they'll just be generated as 
structs.) Have you looked into adding support for this? I'd love to be able to 
use Swift's enums with Thrift's union types.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] thrift pull request: THRIFT-3545 Cocoa: Container type literals do...

2016-01-18 Thread ChristopherRogers
Github user ChristopherRogers commented on the pull request:

https://github.com/apache/thrift/pull/790#issuecomment-172571012
  
Ah, my apologies for the extra semicolons. It was missing semicolons in the 
default init methods where a collection type had a default value.

I believe this semicolon problem is due to discrepancies in how the caller 
of this method assumes code will be generated--with semicolons and line breaks 
or not. I think if the call sites were to be cleaned up the ugliness would go 
away. I believe I checked them but I might've overlooked them. I'll give it 
another look again later too.

The NSSet change should've been in another PR, I admit, but it was for 
performance reasons (since one of Thrift's main goals is performance). I 
believe that optimized ARC code cannot cancel out the autorelease that 
setWithArray makes because Foundation isn't using ARC itself (I think, but it's 
worth testing.) Even if it could I think it's still faster to not have to have 
it back out of autoreleasing. I considered changing it to the initWithObjects 
variant but it seemed a little too drastic and needs performance testing. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] thrift pull request: THRIFT-3545 Cocoa: Container type literals do...

2016-01-18 Thread ChristopherRogers
Github user ChristopherRogers commented on the pull request:

https://github.com/apache/thrift/pull/790#issuecomment-172575020
  
Also, I just remembered from an old version of Xcode that even the @[]/@{} 
syntax used autorelease (probably to easily codegen in both ARC and MRC) but 
that might've changed since then, and I might've been looking at a 
non-optimized build.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] thrift pull request: THRIFT-3545 Cocoa: Container type literals do...

2016-01-12 Thread ChristopherRogers
GitHub user ChristopherRogers opened a pull request:

https://github.com/apache/thrift/pull/790

THRIFT-3545 Cocoa: Container type literals do not compile



You can merge this pull request into a Git repository by running:

$ git pull https://github.com/ChristopherRogers/thrift THRIFT-3545

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/thrift/pull/790.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #790


commit 1600191b1847ed06e77ab7ca501ce3747ae66212
Author: Christopher Rogers <christopher.rog...@linecorp.com>
Date:   2016-01-13T03:52:41Z

THRIFT-3545 Cocoa: Container type literals do not compile




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---