You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2016/03/07 00:19:57 UTC

thrift git commit: THRIFT-3709 Comment syntax can produce broken code Client: Compiler(general) Patch: Jens Geyer

Repository: thrift
Updated Branches:
  refs/heads/master af9d2ac69 -> 775671aea


THRIFT-3709 Comment syntax can produce broken code
Client: Compiler(general)
Patch: Jens Geyer


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/775671ae
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/775671ae
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/775671ae

Branch: refs/heads/master
Commit: 775671aea41ea55427dd78d7ce68e282cc9b8487
Parents: af9d2ac
Author: Jens Geyer <je...@apache.org>
Authored: Sun Mar 6 19:02:42 2016 +0100
Committer: Jens Geyer <je...@apache.org>
Committed: Mon Mar 7 00:19:21 2016 +0100

----------------------------------------------------------------------
 compiler/cpp/compiler.vcxproj         |  4 +-
 compiler/cpp/compiler.vcxproj.filters |  5 +-
 compiler/cpp/src/thriftl.ll           | 94 ++++++++++++++++++++++--------
 test/DocTest.thrift                   | 30 ++++++++++
 4 files changed, 106 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/775671ae/compiler/cpp/compiler.vcxproj
----------------------------------------------------------------------
diff --git a/compiler/cpp/compiler.vcxproj b/compiler/cpp/compiler.vcxproj
index 6f5396b..a2548d4 100644
--- a/compiler/cpp/compiler.vcxproj
+++ b/compiler/cpp/compiler.vcxproj
@@ -50,7 +50,7 @@
     <ClInclude Include="src\windows\version.h" />
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="src\audit\t_audit.cpp"/>
+    <ClCompile Include="src\audit\t_audit.cpp" />
     <ClCompile Include="src\generate\t_as3_generator.cc" />
     <ClCompile Include="src\generate\t_cocoa_generator.cc" />
     <ClCompile Include="src\generate\t_cpp_generator.cc" />
@@ -77,7 +77,7 @@
     <ClCompile Include="src\generate\t_py_generator.cc" />
     <ClCompile Include="src\generate\t_rb_generator.cc" />
     <ClCompile Include="src\generate\t_st_generator.cc" />
-	<ClCompile Include="src\generate\t_swift_generator.cc" />
+    <ClCompile Include="src\generate\t_swift_generator.cc" />
     <ClCompile Include="src\generate\t_xml_generator.cc" />
     <ClCompile Include="src\generate\t_xsd_generator.cc" />
     <ClCompile Include="src\main.cc" />

http://git-wip-us.apache.org/repos/asf/thrift/blob/775671ae/compiler/cpp/compiler.vcxproj.filters
----------------------------------------------------------------------
diff --git a/compiler/cpp/compiler.vcxproj.filters b/compiler/cpp/compiler.vcxproj.filters
index 6e41afb..9b14bbf 100644
--- a/compiler/cpp/compiler.vcxproj.filters
+++ b/compiler/cpp/compiler.vcxproj.filters
@@ -16,7 +16,6 @@
     </ClInclude>
     <ClInclude Include="src\globals.h" />
     <ClInclude Include="src\main.h" />
-    <ClInclude Include="src\md5.h" />
     <ClInclude Include="src\parse\t_base_type.h">
       <Filter>parse</Filter>
     </ClInclude>
@@ -171,8 +170,10 @@
     <ClCompile Include="src\generate\t_xsd_generator.cc">
       <Filter>generate</Filter>
     </ClCompile>
+    <ClCompile Include="src\generate\t_xml_generator.cc">
+      <Filter>generate</Filter>
+    </ClCompile>
     <ClCompile Include="src\main.cc" />
-    <ClCompile Include="src\md5.c" />
     <ClCompile Include="src\parse\parse.cc">
       <Filter>parse</Filter>
     </ClCompile>

http://git-wip-us.apache.org/repos/asf/thrift/blob/775671ae/compiler/cpp/src/thriftl.ll
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/thriftl.ll b/compiler/cpp/src/thriftl.ll
index 93ebc8e..5c3187d 100644
--- a/compiler/cpp/src/thriftl.ll
+++ b/compiler/cpp/src/thriftl.ll
@@ -111,8 +111,8 @@ dubconstant   ([+-]?[0-9]*(\.[0-9]+)?([eE][+-]?[0-9]+)?)
 identifier    ([a-zA-Z_](\.[a-zA-Z_0-9]|[a-zA-Z_0-9])*)
 whitespace    ([ \t\r\n]*)
 sillycomm     ("/*""*"*"*/")
-multicomm     ("/*"[^*]([^*]|"*"[^/])*"*/")
-doctext       ("/**"([^*]|"*"[^/])*"*/")
+multicm_begin ("/*")
+doctext_begin ("/**")
 comment       ("//"[^\n]*)
 unixcomment   ("#"[^\n]*)
 symbol        ([:;\,\{\}\(\)\=<>\[\]])
@@ -122,7 +122,75 @@ literal_begin (['\"])
 
 {whitespace}         { /* do nothing */                 }
 {sillycomm}          { /* do nothing */                 }
-{multicomm}          { /* do nothing */                 }
+
+{doctext_begin} {
+  std::string parsed("/**");
+  int state = 0;  // 0 = normal, 1 = "*" seen, "*/" seen
+  while(state < 2)
+  {
+    int ch = yyinput();
+    parsed.push_back(ch);
+    switch (ch) {
+      case EOF:
+        yyerror("Unexpected end of file in doc-comment at %d\n", yylineno);
+        exit(1);
+      case '*':
+        state = 1;
+        break;
+      case '/':
+        state = (state == 1) ? 2 : 0;
+        break;
+      default:
+        state = 0;
+        break;
+    }
+  }
+  pdebug("doctext = \"%s\"\n",parsed.c_str());
+
+ /* This does not show up in the parse tree. */
+ /* Rather, the parser will grab it out of the global. */
+  if (g_parse_mode == PROGRAM) {
+    clear_doctext();
+    g_doctext = strdup(parsed.c_str() + 3);
+    assert(strlen(g_doctext) >= 2);
+    g_doctext[strlen(g_doctext) - 2] = ' ';
+    g_doctext[strlen(g_doctext) - 1] = '\0';
+    g_doctext = clean_up_doctext(g_doctext);
+    g_doctext_lineno = yylineno;
+    if( (g_program_doctext_candidate == NULL) && (g_program_doctext_status == INVALID)){
+      g_program_doctext_candidate = strdup(g_doctext);
+      g_program_doctext_lineno = g_doctext_lineno;
+      g_program_doctext_status = STILL_CANDIDATE;
+      pdebug("%s","program doctext set to STILL_CANDIDATE");
+    }
+  }
+}
+
+{multicm_begin}  { /* parsed, but thrown away */
+  std::string parsed("/*");
+  int state = 0;  // 0 = normal, 1 = "*" seen, "*/" seen
+  while(state < 2)
+  {
+    int ch = yyinput();
+    parsed.push_back(ch);
+    switch (ch) {
+      case EOF:
+        yyerror("Unexpected end of file in multiline comment at %d\n", yylineno);
+        exit(1);
+      case '*':
+        state = 1;
+        break;
+      case '/':
+        state = (state == 1) ? 2 : 0;
+        break;
+      default:
+        state = 0;
+        break;
+    }
+  }
+  pdebug("multi_comm = \"%s\"\n",parsed.c_str());
+}
+
 {comment}            { /* do nothing */                 }
 {unixcomment}        { /* do nothing */                 }
 
@@ -384,26 +452,6 @@ literal_begin (['\"])
 }
 
 
-{doctext} {
- /* This does not show up in the parse tree. */
- /* Rather, the parser will grab it out of the global. */
-  if (g_parse_mode == PROGRAM) {
-    clear_doctext();
-    g_doctext = strdup(yytext + 3);
-    assert(strlen(g_doctext) >= 2);
-    g_doctext[strlen(g_doctext) - 2] = ' ';
-    g_doctext[strlen(g_doctext) - 1] = '\0';
-    g_doctext = clean_up_doctext(g_doctext);
-    g_doctext_lineno = yylineno;
-    if( (g_program_doctext_candidate == NULL) && (g_program_doctext_status == INVALID)){
-      g_program_doctext_candidate = strdup(g_doctext);
-      g_program_doctext_lineno = g_doctext_lineno;
-      g_program_doctext_status = STILL_CANDIDATE;
-      pdebug("%s","program doctext set to STILL_CANDIDATE");
-    }
-  }
-}
-
 . {
   unexpected_token(yytext);
 }

http://git-wip-us.apache.org/repos/asf/thrift/blob/775671ae/test/DocTest.thrift
----------------------------------------------------------------------
diff --git a/test/DocTest.thrift b/test/DocTest.thrift
index 5d205b7..70575c1 100644
--- a/test/DocTest.thrift
+++ b/test/DocTest.thrift
@@ -254,4 +254,34 @@ typedef i32 TestFor3501a
  */
 typedef i32 TestFor3501b
 
+
+/* Comment-end tokens can of course have more than one asterisk */
+struct TestFor3709_00 { /* ? */ 1: i32 foo }
+/* Comment-end tokens can of course have more than one asterisk **/
+struct TestFor3709_01 { /* ? */ 1: i32 foo }
+/* Comment-end tokens can of course have more than one asterisk ***/
+struct TestFor3709_02 { /* ? */ 1: i32 foo }
+/** Comment-end tokens can of course have more than one asterisk */
+struct TestFor3709_03 { /* ? */ 1: i32 foo }
+/** Comment-end tokens can of course have more than one asterisk **/
+struct TestFor3709_04 { /* ? */ 1: i32 foo }
+/** Comment-end tokens can of course have more than one asterisk ***/
+struct TestFor3709_05 { /* ? */ 1: i32 foo }
+/*** Comment-end tokens can of course have more than one asterisk */
+struct TestFor3709_06 { /* ? */ 1: i32 foo }
+/*** Comment-end tokens can of course have more than one asterisk **/
+struct TestFor3709_07 { /* ? */ 1: i32 foo }
+/*** Comment-end tokens can of course have more than one asterisk ***/
+struct TestFor3709_08 { /* ? */ 1: i32 foo }
+
+struct TestFor3709 {
+  /** This is a comment */
+  1: required string id,
+  /** This is also a comment **/
+  2: required string typeId,
+  /** Yet another comment! */
+  3: required i32 endTimestamp
+}
+
+
 /* THE END */