Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

THRIFT-5444 #2424

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
302 changes: 136 additions & 166 deletions compiler/cpp/src/thrift/generate/t_netstd_generator.cc

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions compiler/cpp/src/thrift/generate/t_netstd_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ using std::vector;
static const string endl = "\n"; // avoid ostream << std::endl flushes

static const string DEEP_COPY_METHOD_NAME = "DeepCopy";
static const string CANCELLATION_TOKEN_NAME = "cancellationToken";

class t_netstd_generator : public t_oop_generator
{
Expand Down Expand Up @@ -135,7 +136,7 @@ class t_netstd_generator : public t_oop_generator
static const int MODE_NO_RETURN = 0x01;
static const int MODE_NO_ARGS = 0x02;

string type_name(t_type* ttype);
string type_name(t_type* ttype, bool with_namespace = true);
string base_type_name(t_base_type* tbase);
string declare_field(t_field* tfield, bool init = false, string prefix = "");
string function_signature_async(t_function* tfunction, string prefix = "", int mode = MODE_FULL_DECL);
Expand Down Expand Up @@ -167,7 +168,7 @@ class t_netstd_generator : public t_oop_generator
map<string, t_type*> checked_extension_types;

void init_keywords();
string normalize_name(string name);
string normalize_name(string name, bool is_arg_name = false);
string make_valid_csharp_identifier(string const& fromName);
string make_csharp_string_literal( string const& value);
void prepare_member_name_mapping(t_service* tservice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<!-- Generate the thrift test files -->
<Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial -r ./CassandraTest.thrift" />
<Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial -r ./optional_required_default.thrift" />
<Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial -r ./name_conflicts.thrift" />
<Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial -r ./../../../../test/ThriftTest.thrift" />
<Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial -r ./../../../../contrib/fb303/if/fb303.thrift" />
<Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial -r ./Thrift5253.thrift" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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.

// Testcases for
// - THRIFT-5091 Netstd generator produces uncompileable code for struct names ending with "_result" or "_args"
// - THRIFT-5444 netstd generator produces uncompileable code for enums ending with "_result" or "_args"

namespace * name_conflicts_enum

enum some_result {
foo,
bar,
baz
}

enum some_args {
foo,
bar,
baz
}


// EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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.

// Testcases for
// - THRIFT-5445 "cancellationToken" cannot be used as argument name
// - THRIFT-5091 Netstd generator produces uncompileable code for struct names ending with "_result" or "_args"
// - THRIFT-5444 netstd generator produces uncompileable code for enums ending with "_result" or "_args"

namespace * name_conflicts

include "name_conflicts.enum.thrift"

struct some_struct_args {
1: name_conflicts.enum.some_args some_args
2: name_conflicts.enum.some_result some_result
}

exception some_error_result {
1: name_conflicts.enum.some_args some_args
2: name_conflicts.enum.some_result some_result
}

service some_service {

name_conflicts.enum.some_result some_method(
1: i32 cancellationToken
2: name_conflicts.enum.some_args some_args
3: some_struct_args more_args
) throws (
1: some_error_result some_error_result
)

}

// EOF
3 changes: 3 additions & 0 deletions test/netstd/Client/TestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.

#pragma warning disable IDE0066 // switch expression
#pragma warning disable IDE0057 // substring

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down