more fixes for libantlr3c v3.4
authorMorgan Deters <mdeters@gmail.com>
Tue, 4 Oct 2011 00:59:29 +0000 (00:59 +0000)
committerMorgan Deters <mdeters@gmail.com>
Tue, 4 Oct 2011 00:59:29 +0000 (00:59 +0000)
config/antlr.m4
src/parser/antlr_input.cpp
src/parser/memory_mapped_input_buffer.cpp

index 4ec81cbc7a1c1b95ffe35a56b301ec7dbf316bdd..cb6e2dc64d255738306c8d390f758afdb77c265e 100644 (file)
@@ -81,6 +81,47 @@ AC_DEFUN([AC_LIB_ANTLR],[
     )
   done
 
+  AC_MSG_CHECKING([for presence of older antlr3AsciiFileStreamNew()])
+  AC_LINK_IFELSE(
+    [
+      #include <antlr3.h>
+
+      int main() {
+        pANTLR3_UINT8 fName = (pANTLR3_UINT8)"foo";
+        pANTLR3_INPUT_STREAM input = antlr3AsciiFileStreamNew(fName);
+        return 0;
+      }
+    ],
+    [
+      AC_MSG_RESULT([found it (must be antlr3 3.2 or similar)])
+      CVC4_ANTLR3_OLD_INPUT_STREAM=0
+    ],
+        [
+          AC_MSG_RESULT(failed)
+          AC_MSG_CHECKING([for presence of newer antlr3FileStreamNew()])
+          AC_LINK_IFELSE(
+            [
+              #include <antlr3.h>
+
+              int main() {
+                pANTLR3_UINT8 fName = (pANTLR3_UINT8)"foo";
+                pANTLR3_INPUT_STREAM input = antlr3FileStreamNew(fName, ANTLR3_ENC_8BIT);
+                return 0;
+              }
+            ],
+            [
+              AC_MSG_RESULT([found it (must be antlr3 3.4 or similar)])
+              CVC4_ANTLR3_OLD_INPUT_STREAM=0
+            ],
+                [
+                  AC_MSG_ERROR([cannot figure out how to create an antlr3 input stream, bailing..])
+                ]
+          )
+        ]
+  )
+
+  AC_DEFINE_UNQUOTED(CVC4_ANTLR3_OLD_INPUT_STREAM, [$CVC4_ANTLR3_OLD_INPUT_STREAM], [Defined to 1 if we have libantlr3c v3.2 or equivalent.])
+
   # Return the old compile variables and pop the language.
   LIBS="$OLD_LIBS"
   CPPFLAGS="$OLD_CPPFLAGS"
index c51d4b8c39409d3f4b3ba231750a85786c6efcf8..6ec1c584639be0e18f95044615846a8aaa827de6 100644 (file)
@@ -68,7 +68,12 @@ AntlrInputStream::newFileInputStream(const std::string& name,
   if( useMmap ) {
     input = MemoryMappedInputBufferNew(name);
   } else {
+    // libantlr3c v3.2 isn't source-compatible with v3.4
+#if CVC4_ANTLR3_OLD_INPUT_STREAM
     input = antlr3AsciiFileStreamNew((pANTLR3_UINT8) name.c_str());
+#else /* CVC4_ANTLR3_OLD_INPUT_STREAM */
+    input = antlr3FileStreamNew((pANTLR3_UINT8) name.c_str(), ANTLR3_ENC_8BIT);
+#endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */
   }
   if( input == NULL ) {
     throw InputStreamException("Couldn't open file: " + name);
@@ -112,10 +117,18 @@ AntlrInputStream::newStreamInputStream(std::istream& input,
   }
 
   /* Create an ANTLR input backed by the buffer. */
+#if CVC4_ANTLR3_OLD_INPUT_STREAM
   pANTLR3_INPUT_STREAM inputStream =
       antlr3NewAsciiStringInPlaceStream((pANTLR3_UINT8) basep,
                                         cp - basep,
                                         (pANTLR3_UINT8) strdup(name.c_str()));
+#else /* CVC4_ANTLR3_OLD_INPUT_STREAM */
+  pANTLR3_INPUT_STREAM inputStream =
+      antlr3StringStreamNew((pANTLR3_UINT8) basep,
+                            ANTLR3_ENC_8BIT,
+                            cp - basep,
+                            (pANTLR3_UINT8) strdup(name.c_str()));
+#endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */
   if( inputStream==NULL ) {
     throw InputStreamException("Couldn't initialize input: " + name);
   }
@@ -130,10 +143,18 @@ AntlrInputStream::newStringInputStream(const std::string& input,
   char* inputStr = strdup(input.c_str());
   char* nameStr = strdup(name.c_str());
   AlwaysAssert( inputStr!=NULL && nameStr!=NULL );
+#if CVC4_ANTLR3_OLD_INPUT_STREAM
   pANTLR3_INPUT_STREAM inputStream =
       antlr3NewAsciiStringInPlaceStream((pANTLR3_UINT8) inputStr,
                                         input.size(),
                                         (pANTLR3_UINT8) nameStr);
+#else /* CVC4_ANTLR3_OLD_INPUT_STREAM */
+  pANTLR3_INPUT_STREAM inputStream =
+      antlr3StringStreamNew((pANTLR3_UINT8) inputStr,
+                            ANTLR3_ENC_8BIT,
+                            input.size(),
+                            (pANTLR3_UINT8) nameStr);
+#endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */
   if( inputStream==NULL ) {
     throw InputStreamException("Couldn't initialize string input: '" + input + "'");
   }
index dad38c913721c3acce4127db3113da237f7401d2..1c0f76e1e28f150ebaa87eb5040252c55bd11b5a 100644 (file)
@@ -61,7 +61,11 @@ pANTLR3_INPUT_STREAM MemoryMappedInputBufferNew(const std::string& filename) {
   // Call the common 8 bit ASCII input stream handler
   // Initializer type thingy doobry function.
   //
+#if CVC4_ANTLR3_OLD_INPUT_STREAM
   antlr3AsciiSetupStream(input, ANTLR3_CHARSTREAM);
+#else /* CVC4_ANTLR3_OLD_INPUT_STREAM */
+  antlr38BitSetupStream(input);
+#endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */
 
   // Now we can set up the file name
   //