THRIFT-1040 Can't end typedef lines with a semicolon
Client: Compiler (General)
Patch: Konrad Grochowski
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index 3755d13..40e7a06 100644
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -545,8 +545,16 @@
}
}
+CommaOrSemicolonOptional:
+ ','
+ {}
+| ';'
+ {}
+|
+ {}
+
Typedef:
- tok_typedef FieldType tok_identifier TypeAnnotations
+ tok_typedef FieldType tok_identifier TypeAnnotations CommaOrSemicolonOptional
{
pdebug("TypeDef -> tok_typedef FieldType tok_identifier");
validate_simple_identifier( $3);
@@ -558,14 +566,6 @@
}
}
-CommaOrSemicolonOptional:
- ','
- {}
-| ';'
- {}
-|
- {}
-
Enum:
tok_enum tok_identifier '{' EnumDefList '}' TypeAnnotations
{
diff --git a/lib/cpp/test/Makefile.am b/lib/cpp/test/Makefile.am
index b3f66bd..9c9b8d8 100755
--- a/lib/cpp/test/Makefile.am
+++ b/lib/cpp/test/Makefile.am
@@ -20,16 +20,17 @@
noinst_LTLIBRARIES = libtestgencpp.la libprocessortest.la
nodist_libtestgencpp_la_SOURCES = \
gen-cpp/DebugProtoTest_types.cpp \
+ gen-cpp/DebugProtoTest_types.h \
gen-cpp/EnumTest_types.cpp \
gen-cpp/EnumTest_types.h \
gen-cpp/OptionalRequiredTest_types.cpp \
- gen-cpp/DebugProtoTest_types.cpp \
- gen-cpp/ThriftTest_types.cpp \
- gen-cpp/DebugProtoTest_types.h \
gen-cpp/OptionalRequiredTest_types.h \
gen-cpp/Recursive_types.cpp \
gen-cpp/Recursive_types.h \
+ gen-cpp/ThriftTest_types.cpp \
gen-cpp/ThriftTest_types.h \
+ gen-cpp/TypedefTest_types.cpp \
+ gen-cpp/TypedefTest_types.h \
ThriftTest_extras.cpp \
DebugProtoTest_extras.cpp
@@ -86,7 +87,8 @@
TMemoryBufferTest.cpp \
TBufferBaseTest.cpp \
Base64Test.cpp \
- ToStringTest.cpp
+ ToStringTest.cpp \
+ TypedefTest.cpp
if !WITH_BOOSTTHREADS
UnitTests_SOURCES += \
@@ -120,7 +122,7 @@
EnumTest_LDADD = \
libtestgencpp.la \
- -l:libboost_unit_test_framework.a
+ -l:libboost_unit_test_framework.a
TFileTransportTest_SOURCES = \
TFileTransportTest.cpp
@@ -246,6 +248,9 @@
gen-cpp/EnumTest_types.cpp gen-cpp/EnumTest_types.h: $(top_srcdir)/test/EnumTest.thrift
$(THRIFT) --gen cpp:pure_enums $<
+gen-cpp/TypedefTest_types.cpp gen-cpp/TypedefTest_types.h: $(top_srcdir)/test/TypedefTest.thrift
+ $(THRIFT) --gen cpp $<
+
gen-cpp/OptionalRequiredTest_types.cpp gen-cpp/OptionalRequiredTest_types.h: $(top_srcdir)/test/OptionalRequiredTest.thrift
$(THRIFT) --gen cpp:dense $<
diff --git a/lib/cpp/test/TypedefTest.cpp b/lib/cpp/test/TypedefTest.cpp
new file mode 100644
index 0000000..45eb1e7
--- /dev/null
+++ b/lib/cpp/test/TypedefTest.cpp
@@ -0,0 +1,27 @@
+/*
+ * 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 <boost/type_traits/is_same.hpp>
+#include <boost/static_assert.hpp>
+
+#include "gen-cpp/TypedefTest_types.h"
+
+BOOST_STATIC_ASSERT(boost::is_same<int32_t, thrift::test::MyInt32>::value);
+BOOST_STATIC_ASSERT(boost::is_same<std::string, thrift::test::MyString>::value);
+BOOST_STATIC_ASSERT(boost::is_same<thrift::test::TypedefTestStruct, thrift::test::MyStruct>::value);
diff --git a/test/TypedefTest.thrift b/test/TypedefTest.thrift
new file mode 100644
index 0000000..9437478
--- /dev/null
+++ b/test/TypedefTest.thrift
@@ -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.
+ *
+ * Contains some contributions under the Thrift Software License.
+ * Please see doc/old-thrift-license.txt in the Thrift distribution for
+ * details.
+ */
+
+namespace cpp thrift.test
+
+typedef i32 MyInt32
+typedef string MyString;
+
+struct TypedefTestStruct {
+ 1: MyInt32 field_MyInt32;
+ 2: MyString field_MyString;
+ 3: i32 field_Int32;
+ 4: string field_String;
+}
+
+typedef TypedefTestStruct MyStruct,
\ No newline at end of file