[llvm-commits] [hlvm] r38047 - in /hlvm/trunk: autoconf/configure.ac configure hlvm/Reader/XML/Makefile hlvm/Reader/XML/XMLReader.cpp hlvm/Reader/XML/XMLReader.h tools/hlvm-xml2xml/hlvm-xml2xml.cpp

Reid Spencer reid at x10sys.com
Sat Jul 7 16:59:17 PDT 2007


Author: reid
Date: Sat Jul  7 18:59:17 2007
New Revision: 38047

URL: http://llvm.org/viewvc/llvm-project?rev=38047&view=rev
Log:
Convert to use libxml2 instead of expat. libxml2 understands how to parse and
validate Relax/NG schema grammars and documents based on them. This is a big
win in functionality and cuts down on the amount of code we have to write.

Modified:
    hlvm/trunk/autoconf/configure.ac
    hlvm/trunk/configure
    hlvm/trunk/hlvm/Reader/XML/Makefile
    hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
    hlvm/trunk/hlvm/Reader/XML/XMLReader.h
    hlvm/trunk/tools/hlvm-xml2xml/hlvm-xml2xml.cpp

Modified: hlvm/trunk/autoconf/configure.ac
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/autoconf/configure.ac?rev=38047&r1=38046&r2=38047&view=diff

==============================================================================
--- hlvm/trunk/autoconf/configure.ac (original)
+++ hlvm/trunk/autoconf/configure.ac Sat Jul  7 18:59:17 2007
@@ -291,8 +291,8 @@
                   [Apache Portable Runtime])
 HLVM_FIND_LIBRARY([apru],[apr-1/apu.h],[aprutil-1],[apu_version],
                   [Apache Portable Runtime Utilities])
-HLVM_FIND_LIBRARY([expat],[expat.h],[expat],[XML_ParserCreate],
-                  [expat XML Parser])
+HLVM_FIND_LIBRARY([xml2],[libxml/parser.h],[xml2],
+                  [xmlCreateFileParserCtxt],[libxml2 XML C Parser])
 HLVM_FIND_LIBRARY([syck],[syck.h],[syck],[syck_parse],[Syck Yaml Handler])
 
 dnl -- Check for specific libraries we depend on.

Modified: hlvm/trunk/configure
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/configure?rev=38047&r1=38046&r2=38047&view=diff

==============================================================================
--- hlvm/trunk/configure (original)
+++ hlvm/trunk/configure Sat Jul  7 18:59:17 2007
@@ -315,7 +315,7 @@
 # include <unistd.h>
 #endif"
 
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS HLVM_COPYRIGHT HLVM_PACKAGE HLVM_VERSION HLVM_SO_VERSION HLVM_SO_CURRENT HLVM_SO_REVISION HLVM_SO_AGE HLVM_SHAREDPREFIX HLVM_DEBUG HLVM_OPTIMIZE HLVM_INLINE HLVM_ASSERT HLVM_TRACE HLVM_SMALL HLVM_EFENCE HLVM_PROFILING HLVM_WITH_WORKSPACE HLVM_WITH_INCLUDES HLVM_WITH_LLVM_SRC HLVM_WITH_LLVM_OBJ HLVM_WITH_LLVMGCC CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP CXX CXXFLAGS ac_ct_CXX ifGNUmake apr_INC apr_LIB apru_INC apru_LIB expat_INC expat_LIB syck_INC syck_LIB EGREP HLVM_CFGNAME HLVM_CONFIGTIME HLVM_PREFIX LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS HLVM_COPYRIGHT HLVM_PACKAGE HLVM_VERSION HLVM_SO_VERSION HLVM_SO_CURRENT HLVM_SO_REVISION HLVM_SO_AGE HLVM_SHAREDPREFIX HLVM_DEBUG HLVM_OPTIMIZE HLVM_INLINE HLVM_ASSERT HLVM_TRACE HLVM_SMALL HLVM_EFENCE HLVM_PROFILING HLVM_WITH_WORKSPACE HLVM_WITH_INCLUDES HLVM_WITH_LLVM_SRC HLVM_WITH_LLVM_OBJ HLVM_WITH_LLVMGCC CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP CXX CXXFLAGS ac_ct_CXX ifGNUmake apr_INC apr_LIB apru_INC apru_LIB xml2_INC xml2_LIB syck_INC syck_LIB EGREP HLVM_CFGNAME HLVM_CONFIGTIME HLVM_PREFIX LIBOBJS LTLIBOBJS'
 ac_subst_files=''
 
 # Initialize some variables set by options.
@@ -895,11 +895,12 @@
                           libraries are in DIR
   --with-APRU-inc=DIR     Specify that the Apache Portable Runtime Utilities
                           includes are in DIR
-  --with-EXPAT=DIR        Specify that the expat XML Parser install prefix is
-                          DIR
-  --with-EXPAT-lib=DIR    Specify that expat XML Parser libraries are in DIR
-  --with-EXPAT-inc=DIR    Specify that the expat XML Parser includes are in
+  --with-XML2=DIR         Specify that the libxml2 XML C Parser install prefix
+                          is DIR
+  --with-XML2-lib=DIR     Specify that libxml2 XML C Parser libraries are in
                           DIR
+  --with-XML2-inc=DIR     Specify that the libxml2 XML C Parser includes are
+                          in DIR
   --with-SYCK=DIR         Specify that the Syck Yaml Handler install prefix is
                           DIR
   --with-SYCK-lib=DIR     Specify that Syck Yaml Handler libraries are in DIR
@@ -4756,34 +4757,34 @@
 
 
 
-# Check whether --with-EXPAT or --without-EXPAT was given.
-if test "${with_EXPAT+set}" = set; then
-  withval="$with_EXPAT"
-  expatpfxdir=$withval
+# Check whether --with-XML2 or --without-XML2 was given.
+if test "${with_XML2+set}" = set; then
+  withval="$with_XML2"
+  xml2pfxdir=$withval
 else
-  expatpfxdir=nada
+  xml2pfxdir=nada
 fi;
 
-# Check whether --with-EXPAT-lib or --without-EXPAT-lib was given.
-if test "${with_EXPAT_lib+set}" = set; then
-  withval="$with_EXPAT_lib"
-  expatlibdir=$withval
+# Check whether --with-XML2-lib or --without-XML2-lib was given.
+if test "${with_XML2_lib+set}" = set; then
+  withval="$with_XML2_lib"
+  xml2libdir=$withval
 else
-  expatlibdir=nada
+  xml2libdir=nada
 fi;
 
-# Check whether --with-EXPAT-inc or --without-EXPAT-inc was given.
-if test "${with_EXPAT_inc+set}" = set; then
-  withval="$with_EXPAT_inc"
-  expatincdir=$withval
+# Check whether --with-XML2-inc or --without-XML2-inc was given.
+if test "${with_XML2_inc+set}" = set; then
+  withval="$with_XML2_inc"
+  xml2incdir=$withval
 else
-  expatincdir=nada
+  xml2incdir=nada
 fi;
-pfxval="${expatpfxdir}"
-incval="${expatincdir}"
-libval="${expatlibdir}"
-echo "$as_me:$LINENO: checking for expat XML Parser library and header" >&5
-echo $ECHO_N "checking for expat XML Parser library and header... $ECHO_C" >&6
+pfxval="${xml2pfxdir}"
+incval="${xml2incdir}"
+libval="${xml2libdir}"
+echo "$as_me:$LINENO: checking for libxml2 XML C Parser library and header" >&5
+echo $ECHO_N "checking for libxml2 XML C Parser library and header... $ECHO_C" >&6
 hlvm_found_lib=0
 hlvm_found_inc=0
 if test "${pfxval}" != "nada" ; then
@@ -4791,11 +4792,11 @@
 
 hlvm_found_inc=0
 if test -d "${pfxval}" ; then
-  if test -n "expat.h" ; then
-    for dir in "${pfxval}/include" "${pfxval}" "${pfxval}/include/expat" ; do
+  if test -n "libxml/parser.h" ; then
+    for dir in "${pfxval}/include" "${pfxval}" "${pfxval}/include/xml2" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/expat.h" ; then
-          expat_INC="$dir"
+        if test -f "$dir/libxml/parser.h" ; then
+          xml2_INC="$dir"
 
           hlvm_found_inc=1
         fi
@@ -4807,19 +4808,19 @@
 
 hlvm_found_lib=0
 if test -d "${pfxval}" ; then
-  if test -n "expat" ; then
+  if test -n "xml2" ; then
     for dir in "${pfxval}" "${pfxval}/lib" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/libexpat.so" ; then
-          expat_LIB=$dir
+        if test -f "$dir/libxml2.so" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.a" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.a" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.la" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.la" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
         fi
@@ -4831,8 +4832,8 @@
   else
     echo "$as_me:$LINENO: result: failed" >&5
 echo "${ECHO_T}failed" >&6;
-    { { echo "$as_me:$LINENO: error: The --with-expat value must be a directory" >&5
-echo "$as_me: error: The --with-expat value must be a directory" >&2;}
+    { { echo "$as_me:$LINENO: error: The --with-xml2 value must be a directory" >&5
+echo "$as_me: error: The --with-xml2 value must be a directory" >&2;}
    { (exit 1); exit 1; }; }
   fi
 else
@@ -4840,19 +4841,19 @@
 
 hlvm_found_lib=0
 if test -d "${libval}" ; then
-  if test -n "expat" ; then
+  if test -n "xml2" ; then
     for dir in "${libval}" "${libval}/lib" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/libexpat.so" ; then
-          expat_LIB=$dir
+        if test -f "$dir/libxml2.so" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.a" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.a" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.la" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.la" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
         fi
@@ -4866,11 +4867,11 @@
 
 hlvm_found_inc=0
 if test -d "${incval}" ; then
-  if test -n "expat.h" ; then
-    for dir in "${incval}/include" "${incval}" "${incval}/include/expat" ; do
+  if test -n "libxml/parser.h" ; then
+    for dir in "${incval}/include" "${incval}" "${incval}/include/xml2" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/expat.h" ; then
-          expat_INC="$dir"
+        if test -f "$dir/libxml/parser.h" ; then
+          xml2_INC="$dir"
 
           hlvm_found_inc=1
         fi
@@ -4885,19 +4886,19 @@
 
 hlvm_found_lib=0
 if test -d "/usr" ; then
-  if test -n "expat" ; then
+  if test -n "xml2" ; then
     for dir in "/usr" "/usr/lib" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/libexpat.so" ; then
-          expat_LIB=$dir
+        if test -f "$dir/libxml2.so" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.a" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.a" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.la" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.la" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
         fi
@@ -4911,19 +4912,19 @@
 
 hlvm_found_lib=0
 if test -d "/usr/local" ; then
-  if test -n "expat" ; then
+  if test -n "xml2" ; then
     for dir in "/usr/local" "/usr/local/lib" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/libexpat.so" ; then
-          expat_LIB=$dir
+        if test -f "$dir/libxml2.so" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.a" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.a" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.la" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.la" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
         fi
@@ -4937,19 +4938,19 @@
 
 hlvm_found_lib=0
 if test -d "/proj/install" ; then
-  if test -n "expat" ; then
+  if test -n "xml2" ; then
     for dir in "/proj/install" "/proj/install/lib" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/libexpat.so" ; then
-          expat_LIB=$dir
+        if test -f "$dir/libxml2.so" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.a" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.a" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.la" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.la" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
         fi
@@ -4963,19 +4964,19 @@
 
 hlvm_found_lib=0
 if test -d "/sw" ; then
-  if test -n "expat" ; then
+  if test -n "xml2" ; then
     for dir in "/sw" "/sw/lib" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/libexpat.so" ; then
-          expat_LIB=$dir
+        if test -f "$dir/libxml2.so" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.a" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.a" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.la" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.la" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
         fi
@@ -4989,19 +4990,19 @@
 
 hlvm_found_lib=0
 if test -d "/opt" ; then
-  if test -n "expat" ; then
+  if test -n "xml2" ; then
     for dir in "/opt" "/opt/lib" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/libexpat.so" ; then
-          expat_LIB=$dir
+        if test -f "$dir/libxml2.so" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.a" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.a" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
-        elif test -f "$dir/libexpat.la" ; then
-          expat_LIB=$dir
+        elif test -f "$dir/libxml2.la" ; then
+          xml2_LIB=$dir
 
           hlvm_found_lib=1
         fi
@@ -5015,11 +5016,11 @@
 
 hlvm_found_inc=0
 if test -d "/usr" ; then
-  if test -n "expat.h" ; then
-    for dir in "/usr/include" "/usr" "/usr/include/expat" ; do
+  if test -n "libxml/parser.h" ; then
+    for dir in "/usr/include" "/usr" "/usr/include/xml2" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/expat.h" ; then
-          expat_INC="$dir"
+        if test -f "$dir/libxml/parser.h" ; then
+          xml2_INC="$dir"
 
           hlvm_found_inc=1
         fi
@@ -5033,11 +5034,11 @@
 
 hlvm_found_inc=0
 if test -d "/usr/local" ; then
-  if test -n "expat.h" ; then
-    for dir in "/usr/local/include" "/usr/local" "/usr/local/include/expat" ; do
+  if test -n "libxml/parser.h" ; then
+    for dir in "/usr/local/include" "/usr/local" "/usr/local/include/xml2" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/expat.h" ; then
-          expat_INC="$dir"
+        if test -f "$dir/libxml/parser.h" ; then
+          xml2_INC="$dir"
 
           hlvm_found_inc=1
         fi
@@ -5051,11 +5052,11 @@
 
 hlvm_found_inc=0
 if test -d "/proj/install" ; then
-  if test -n "expat.h" ; then
-    for dir in "/proj/install/include" "/proj/install" "/proj/install/include/expat" ; do
+  if test -n "libxml/parser.h" ; then
+    for dir in "/proj/install/include" "/proj/install" "/proj/install/include/xml2" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/expat.h" ; then
-          expat_INC="$dir"
+        if test -f "$dir/libxml/parser.h" ; then
+          xml2_INC="$dir"
 
           hlvm_found_inc=1
         fi
@@ -5069,11 +5070,11 @@
 
 hlvm_found_inc=0
 if test -d "/sw" ; then
-  if test -n "expat.h" ; then
-    for dir in "/sw/include" "/sw" "/sw/include/expat" ; do
+  if test -n "libxml/parser.h" ; then
+    for dir in "/sw/include" "/sw" "/sw/include/xml2" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/expat.h" ; then
-          expat_INC="$dir"
+        if test -f "$dir/libxml/parser.h" ; then
+          xml2_INC="$dir"
 
           hlvm_found_inc=1
         fi
@@ -5087,11 +5088,11 @@
 
 hlvm_found_inc=0
 if test -d "/opt" ; then
-  if test -n "expat.h" ; then
-    for dir in "/opt/include" "/opt" "/opt/include/expat" ; do
+  if test -n "libxml/parser.h" ; then
+    for dir in "/opt/include" "/opt" "/opt/include/xml2" ; do
       if test -d "$dir" ; then
-        if test -f "$dir/expat.h" ; then
-          expat_INC="$dir"
+        if test -f "$dir/libxml/parser.h" ; then
+          xml2_INC="$dir"
 
           hlvm_found_inc=1
         fi
@@ -5105,21 +5106,21 @@
   if test "$hlvm_found_lib" == 1 ; then
     echo "$as_me:$LINENO: result: found" >&5
 echo "${ECHO_T}found" >&6
-    incdir=${expat_INC}
-    libdir=${expat_LIB}
+    incdir=${xml2_INC}
+    libdir=${xml2_LIB}
 
  echo "$LDFLAGS" | grep -- "-L"${libdir}"" >/dev/null 2>/dev/null
  if test $? -ne 0 ; then
    LDFLAGS="$LDFLAGS -L"${libdir}""
  fi
 
-    echo "$as_me:$LINENO: checking for library containing XML_ParserCreate" >&5
-echo $ECHO_N "checking for library containing XML_ParserCreate... $ECHO_C" >&6
-if test "${ac_cv_search_XML_ParserCreate+set}" = set; then
+    echo "$as_me:$LINENO: checking for library containing xmlCreateFileParserCtxt" >&5
+echo $ECHO_N "checking for library containing xmlCreateFileParserCtxt... $ECHO_C" >&6
+if test "${ac_cv_search_xmlCreateFileParserCtxt+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   ac_func_search_save_LIBS=$LIBS
-ac_cv_search_XML_ParserCreate=no
+ac_cv_search_xmlCreateFileParserCtxt=no
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -5133,11 +5134,11 @@
 #endif
 /* We use char because int might match the return type of a gcc2
    builtin and then its argument prototype would still apply.  */
-char XML_ParserCreate ();
+char xmlCreateFileParserCtxt ();
 int
 main ()
 {
-XML_ParserCreate ();
+xmlCreateFileParserCtxt ();
   ;
   return 0;
 }
@@ -5164,7 +5165,7 @@
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_cv_search_XML_ParserCreate="none required"
+  ac_cv_search_xmlCreateFileParserCtxt="none required"
 else
   echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
@@ -5172,8 +5173,8 @@
 fi
 rm -f conftest.err conftest.$ac_objext \
       conftest$ac_exeext conftest.$ac_ext
-if test "$ac_cv_search_XML_ParserCreate" = no; then
-  for ac_lib in expat; do
+if test "$ac_cv_search_xmlCreateFileParserCtxt" = no; then
+  for ac_lib in xml2; do
     LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
     cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -5188,11 +5189,11 @@
 #endif
 /* We use char because int might match the return type of a gcc2
    builtin and then its argument prototype would still apply.  */
-char XML_ParserCreate ();
+char xmlCreateFileParserCtxt ();
 int
 main ()
 {
-XML_ParserCreate ();
+xmlCreateFileParserCtxt ();
   ;
   return 0;
 }
@@ -5219,7 +5220,7 @@
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_cv_search_XML_ParserCreate="-l$ac_lib"
+  ac_cv_search_xmlCreateFileParserCtxt="-l$ac_lib"
 break
 else
   echo "$as_me: failed program was:" >&5
@@ -5232,18 +5233,18 @@
 fi
 LIBS=$ac_func_search_save_LIBS
 fi
-echo "$as_me:$LINENO: result: $ac_cv_search_XML_ParserCreate" >&5
-echo "${ECHO_T}$ac_cv_search_XML_ParserCreate" >&6
-if test "$ac_cv_search_XML_ParserCreate" != no; then
-  test "$ac_cv_search_XML_ParserCreate" = "none required" || LIBS="$ac_cv_search_XML_ParserCreate $LIBS"
+echo "$as_me:$LINENO: result: $ac_cv_search_xmlCreateFileParserCtxt" >&5
+echo "${ECHO_T}$ac_cv_search_xmlCreateFileParserCtxt" >&6
+if test "$ac_cv_search_xmlCreateFileParserCtxt" != no; then
+  test "$ac_cv_search_xmlCreateFileParserCtxt" = "none required" || LIBS="$ac_cv_search_xmlCreateFileParserCtxt $LIBS"
   found_sym=1
 else
   found_sym=0
 fi
 
     if test "$found_sym" == "1" ; then
-      { echo "$as_me:$LINENO: Found expat in ${incdir} and ${libdir}" >&5
-echo "$as_me: Found expat in ${incdir} and ${libdir}" >&6;}
+      { echo "$as_me:$LINENO: Found xml2 in ${incdir} and ${libdir}" >&5
+echo "$as_me: Found xml2 in ${incdir} and ${libdir}" >&6;}
 
  echo "$CPPFLAGS" | grep -- "-I"${incdir}"" >/dev/null 2>/dev/null
  if test $? -ne 0 ; then
@@ -5251,21 +5252,21 @@
  fi
 
     else
-      { echo "$as_me:$LINENO: Symbol 'XML_ParserCreate' not found in library expat in ${libdir}" >&5
-echo "$as_me: Symbol 'XML_ParserCreate' not found in library expat in ${libdir}" >&6;}
+      { echo "$as_me:$LINENO: Symbol 'xmlCreateFileParserCtxt' not found in library xml2 in ${libdir}" >&5
+echo "$as_me: Symbol 'xmlCreateFileParserCtxt' not found in library xml2 in ${libdir}" >&6;}
     fi
   else
     echo "$as_me:$LINENO: result: failed to find library file" >&5
 echo "${ECHO_T}failed to find library file" >&6
-    { { echo "$as_me:$LINENO: error: The --with-expat-libdir option must be used" >&5
-echo "$as_me: error: The --with-expat-libdir option must be used" >&2;}
+    { { echo "$as_me:$LINENO: error: The --with-xml2-libdir option must be used" >&5
+echo "$as_me: error: The --with-xml2-libdir option must be used" >&2;}
    { (exit 1); exit 1; }; }
   fi
 else
   echo "$as_me:$LINENO: result: failed to find header file" >&5
 echo "${ECHO_T}failed to find header file" >&6
-  { { echo "$as_me:$LINENO: error: The --with-expat-incdir option must be used" >&5
-echo "$as_me: error: The --with-expat-incdir option must be used" >&2;}
+  { { echo "$as_me:$LINENO: error: The --with-xml2-incdir option must be used" >&5
+echo "$as_me: error: The --with-xml2-incdir option must be used" >&2;}
    { (exit 1); exit 1; }; }
 fi
 
@@ -7013,8 +7014,8 @@
 s, at apr_LIB@,$apr_LIB,;t t
 s, at apru_INC@,$apru_INC,;t t
 s, at apru_LIB@,$apru_LIB,;t t
-s, at expat_INC@,$expat_INC,;t t
-s, at expat_LIB@,$expat_LIB,;t t
+s, at xml2_INC@,$xml2_INC,;t t
+s, at xml2_LIB@,$xml2_LIB,;t t
 s, at syck_INC@,$syck_INC,;t t
 s, at syck_LIB@,$syck_LIB,;t t
 s, at EGREP@,$EGREP,;t t

Modified: hlvm/trunk/hlvm/Reader/XML/Makefile
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XML/Makefile?rev=38047&r1=38046&r2=38047&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/Makefile (original)
+++ hlvm/trunk/hlvm/Reader/XML/Makefile Sat Jul  7 18:59:17 2007
@@ -9,7 +9,7 @@
 DONT_BUILD_RELINKED 	:= 1
 BUILD_ARCHIVE 		:= 1
 EXTRA_DIST 		:= HLVM.rng
-BUILT_SOURCES 		:= HLVMTokenizer.cpp 
+BUILT_SOURCES 		:= HLVMTokenizer.cpp HLVM.rng.inc
 INSTALL_INCLUDES 	:= XMLReader.h
 
 include $(LEVEL)/Makefile.hlvm
@@ -27,3 +27,8 @@
 	$(Echo) Building Tokenizer For $*
 	$(Verb) $(HLVM_top_srcdir)/utils/bin/mkTokenizer -f \
 	  $(PROJ_SRC_DIR)/HLVM.rng
+
+HLVM.rng.inc : $(PROJ_SRC_DIR)/HLVM.rng Makefile
+	$(Echo) "Converting HLVM.rng -> HLVM.inc"
+	$(Verb) sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' \
+	            -e 's/^/"/' -e 's/$$/"/' $< > $@

Modified: hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp?rev=38047&r1=38046&r2=38047&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp Sat Jul  7 18:59:17 2007
@@ -32,7 +32,8 @@
 #include <hlvm/Base/Locator.h>
 #include <hlvm/Base/Source.h>
 #include <hlvm/AST/Bundle.h>
-#include <expat.h>
+#include <libxml/parser.h>
+#include <libxml/relaxng.h>
 #include <vector>
 #include <string>
 #include <iostream>
@@ -42,146 +43,31 @@
 
 namespace {
 
-/// This structure provides information about an attribute and its value.
-/// It is used during parsing of an XML document when the parser calls
-/// the Handler's ElementStart method.
-/// @brief Attribute Information Structure.
-enum AttributeTypes
-{
-  CDATA_AttrType,
-  ID_AttrType,
-  IDREF_AttrType,
-  IDREFS_AttrType,
-  NMTOKEN_AttrType,
-  NMTOKENS_AttrType,
-  ENTITY_AttrType,
-  ENTITIES_AttrType,
-  NOTATION_AttrType,
-};
-
-enum SpecialTokens 
-{
-  NamespaceToken = -1,
-  CharactersToken = -2,
-  CommentToken = -3,
-  CDATASectionToken = -4,
-  ProcessingInstructionToken = -5,
-
-};
-
-struct AttrInfo
-{
-  std::string uri;    ///< The namespace URI of the attribute
-  std::string local;  ///< The name of the attribute
-  std::string value;  ///< The value of the attribute
-  AttributeTypes type;///< The basic type of the attribute
-  int32_t token;      ///< The token for the attribute name
-  uint32_t ns;        ///< The token for the attribute namespace
-};
-
-struct NodeInfo : public hlvm::Locator
-{
-  std::string uri;    ///< The namespace uri of the element
-  std::string local;  ///< The local name of the element
-  int32_t token;      ///< Tokenized value of local name
-  uint32_t ns;        ///< Tokenized value of namespace name
-  mutable AST::Node* node;    ///< The corresponding AST Node
-};
-
-/// This structure provides information about an element. It is used during
-/// parsing of an XML document when the parser calls the Handler's 
-/// ElementStart method. 
-/// @brief Element Information Structure.
-struct ElementInfo : public NodeInfo {
-  std::vector<NodeInfo> kids;   ///< Node info of child elements
-  std::vector<AttrInfo> attrs; ///< Attributes of the element
-  void find_attrs(
-    int token1, const std::string*& value1) const;
-  void find_attrs(
-    int token1, const std::string*& value1,
-    int token2, const std::string*& value2
-  ) const;
-  void find_attrs(
-    int token1, const std::string*& value1,
-    int token2, const std::string*& value2,
-    int token3, const std::string*& value3
-  ) const;
-};
+const char HLVMGrammar[] = 
+#include "HLVM.rng.inc"
+;
 
 class XMLReaderImpl : public XMLReader {
-  hlvm::Base::Source* in_;
+  std::string path_;
   AST::Node* node_;
-  XML_Parser xp_;
-  std::vector<ElementInfo> elems_; ///< The element stack
-  ElementInfo* etop_; ///< A pointer to the top of the element stack
+  xmlDocPtr doc_;
 public:
-  XMLReaderImpl(Base::Source* input)
-    : in_(input), node_(0), xp_(0), elems_(), etop_(0)
+  XMLReaderImpl(const std::string& path)
+    : path_(path), node_(0)
   {
-    xp_ = XML_ParserCreate( "UTF-8");
-    // Reserve some space on the elements and attributes list so we aren't
-    // mucking around with tiny allocations. If we cross 64 elements on the
-    // stack or 64 attributes on one element, then they will double to 128. 
-    // Its unlikely that documents will reach these limits and so there 
-    // will be no reallocation after this initial reserve.
-    elems_.reserve(64);
   }
 
   virtual ~XMLReaderImpl() 
   { 
     if (node_) delete node_; 
-    XML_ParserFree( xp_ );
+    if (doc_) xmlFreeDoc(doc_);
   }
 
   virtual void read();
   virtual AST::Node* get();
 
-  void CDataSectionStart(void );
-  void CDataSectionEnd();
-  void NamespaceStart( const char* prefix, const char* uri );
-  void NamespaceEnd( const char* prefix );
-  void ElementStart( const ElementInfo& elem); 
-  void ElementEnd( const ElementInfo& elem, uint32_t line, uint32_t column );
-
-  void ProcessingInstruction(const std::string& target, const std::string&data);
-  void Comment( const std::string& );
-  void WhiteSpace( const std::string& );
-  void Characters( const std::string& );
-  void EntityDeclaration(const char *entityName, 
-    int is_parameter_entity, const char *value, int value_length,
-    const char *base, const char *systemId, 
-    const char *publicId, const char *notationName);
-  void NotationDeclaration(const std::string& notationName, 
-    const std::string& systemId, const std::string& publicId);
-
-  uint32_t depth() const { return elems_.size(); }
-
-  const ElementInfo* first() const {
-    if (elems_.empty())
-      return 0;
-    return &elems_.back();
-  }
-
-  const ElementInfo* second() const {
-    if (elems_.size() < 2) return 0;
-    const ElementInfo* result = &elems_.back();
-    return result - 1;
-  }
-
-  const ElementInfo* third() const {
-    if (elems_.size() < 3) return 0;
-    const ElementInfo* result = &elems_.back();
-    return result - 2;
-  }
-
-  const ElementInfo* fourth() const {
-    if (elems_.size() < 4) return 0;
-    const ElementInfo* result = &elems_.back();
-    return result - 3;
-  }
-
-  void make_error(const std::string& msg) {
-    std::cerr << msg;
+  void error(const std::string& msg) {
+    std::cerr << msg << "\n";
   }
 
   std::string getToken(int32_t token) const
@@ -189,358 +75,174 @@
     return HLVMTokenizer::lookup(token);
   }
 
-private:
-
-  static void XMLCALL 
-  StartElementHandler(
-    void *user_data, const XML_Char* name, const XML_Char** attributes
-  )
-  {
-    // Convert the user data to our XMLReaderImpl pointer
-    register XMLReaderImpl* p = reinterpret_cast<XMLReaderImpl*>(user_data);
-
-    // Make a new element info on the top of the stack.
-    p->elems_.resize(p->elems_.size()+1);
-    p->etop_ = &p->elems_.back();
-    ElementInfo& ei = *(p->etop_);
-
-    // Fill in the element info
-    ei.local = name;
-    ei.token = HLVMTokenizer::recognize(name);
-    ei.set("", "{in}",
-      uint32_t(XML_GetCurrentLineNumber(p->xp_)), 
-      uint32_t(XML_GetCurrentColumnNumber(p->xp_))
-    );
-    ei.kids.clear();
-    ei.attrs.clear();
-
-    // Handle the attributes
-    if ( attributes )
-    {
-      // Determine index of first default attribute
-      // size_t default_attr_index = XML_GetSpecifiedAttributeCount( p->xp_ );
-
-      // Process all the attributes
-      size_t curr_attr = 0;
-      while ( *attributes != 0 )
-      {
-        // Resize the attrs vector to accommodate this attribute and get
-        // a preference to that current attribute for ease of expression
-        ei.attrs.resize(curr_attr+1);
-        AttrInfo& attr = ei.attrs[curr_attr];
-
-        // Get the token for the
-        attr.local = *attributes;
-        attr.token = HLVMTokenizer::recognize(*attributes);
-        attr.value = attributes[1];
-
-        // Increment loop counters
-        attributes +=2;
-        curr_attr++;
-      }
-    }
-
-    // Tell the handler about the element
-    p->ElementStart(ei);
-  }
-
-  static void XMLCALL 
-  EndElementHandler( void *user_data, const XML_Char *name)
-  {
-    // Get the parser
-    register XMLReaderImpl* p = reinterpret_cast<XMLReaderImpl*>(user_data);
-
-    // Get the current position
-    int line = XML_GetCurrentLineNumber( p->xp_ );
-    int column = XML_GetCurrentColumnNumber( p->xp_ );
-
-    // Convert the element name to a token
-    int name_token = HLVMTokenizer::recognize(name);
-
-    // Save the previous token before poping it and make sure that it is the
-    // same as the one the parser told us we're popping.
-    int32_t token = p->elems_.back().token;
-    assert(token == name_token);
-
-    // Tell the handler that we're ending an element.
-    p->ElementEnd( p->elems_.back(), line, column );
-
-    // Pop the element token and then push it on the "kids" list of the 
-    // parent element indicating that we've completed parsing one child element.
-    NodeInfo ki = static_cast<NodeInfo&>(p->elems_.back());
-    p->elems_.pop_back();
-    if (!p->elems_.empty())
-    {
-      p->etop_ = & p->elems_.back();
-      p->etop_->kids.push_back(ki);
-    }
-  }
-
-  static void XMLCALL 
-  CharacterDataHandler( void *user_data, const XML_Char *s, int len)
-  {
-    // Get the parser
-    register XMLReaderImpl* p = reinterpret_cast<XMLReaderImpl*>(user_data);
-
-    // Tell the handler about the characters
-    std::string tmp;
-    tmp.assign(s,len);
-    p->Characters(tmp);
-  }
-
-  static void XMLCALL 
-  ProcessingInstructionHandler(
-    void *user_data, const XML_Char *target, const XML_Char *data)
-  {
-    // Get the parser
-    register XMLReaderImpl* p = reinterpret_cast<XMLReaderImpl*>(user_data);
-
-    // Tell the handler about the processing instruction
-    p->ProcessingInstruction(target,data);
-  }
-
-  static void XMLCALL 
-  CommentHandler( void *user_data, const XML_Char *data)
-  {
-    // Get the parser
-    register XMLReaderImpl* p = reinterpret_cast<XMLReaderImpl*>(user_data);
-
-    // Comments are always valid
-    p->Comment(data);
-  }
-
-  static void XMLCALL 
-  StartCdataSectionHandler(void *user_data)
-  {
-    // Get the parser
-    register XMLReaderImpl* p = reinterpret_cast<XMLReaderImpl*>(user_data);
-
-    // Put the CData Section on the element stack
-    ElementInfo ei;
-    ei.ns = 0;
-    ei.local = "CDATA";
-    ei.token = CDATASectionToken;
-    ei.setLine( XML_GetCurrentLineNumber( p->xp_ ));
-    ei.setColumn( XML_GetCurrentColumnNumber( p->xp_ ));
-    ei.kids.clear();
-    p->elems_.push_back(ei);
-
-    // Inform the handler of the CData Section
-    p->CDataSectionStart();
-  }
-
-  static void XMLCALL 
-  EndCdataSectionHandler(void *user_data)
-  {
-    // Get the parser
-    register XMLReaderImpl* p = reinterpret_cast<XMLReaderImpl*>(user_data);
-
-    // validate that the top of stack is a CDataSection
-    assert(p->etop_->token == CDATASectionToken);
-
-    // Pop the CData off the stack
-    NodeInfo ki = static_cast<NodeInfo&>(p->elems_.back());
-    p->elems_.pop_back();
-    p->etop_ = & p->elems_.back();
-    p->etop_->kids.push_back(ki);
-
-    // Inform the handler (always valid)
-    p->CDataSectionEnd();
-  }
-
-  static int XMLCALL 
-  UnknownEncodingHandler( 
-    void * /*encodingHandlerData*/,
-    const XML_Char * /*name*/, 
-    XML_Encoding * /*info*/)
-  {
-    // make_error("Unknown Encoding");
-    return 1;
-  }
+  inline void handleParseError(xmlErrorPtr error);
+  inline void handleValidationError(xmlErrorPtr error);
 
+  void parseTree();
+  void parseBundle(xmlNodePtr cur);
+private:
 };
 
-AST::Node*
-XMLReaderImpl::get()
+inline void
+XMLReaderImpl::handleValidationError(xmlErrorPtr e)
 {
-  return node_;
+  std::cerr << e->file << ":" << e->line << ": validation " <<
+    (e->level == XML_ERR_WARNING ? "warning" : 
+     (e->level == XML_ERR_ERROR ? "error" :
+      (e->level == XML_ERR_FATAL ? "fatal error" : "message"))) 
+    << ": " << e->message << "\n";
 }
 
-static const XML_Char Namespace_Separator = 4; 
-
-void
-XMLReaderImpl::read() {
-  // Set up the parser for parsing a document.
-  XML_ParserReset(xp_,"UTF-8");
-  XML_SetUserData(xp_, this );
-  XML_SetElementHandler(xp_, &StartElementHandler, &EndElementHandler );
-  XML_SetCharacterDataHandler( xp_, CharacterDataHandler );
-  XML_SetProcessingInstructionHandler(xp_, ProcessingInstructionHandler );
-  XML_SetCommentHandler( xp_, CommentHandler );
-  XML_SetCdataSectionHandler( xp_, StartCdataSectionHandler, 
-    EndCdataSectionHandler );
-  XML_SetUnknownEncodingHandler( xp_, UnknownEncodingHandler, this);
-
-  try
-  {
-    int actual_len = 0;
-    in_->prepare(65536);
-
-    // While there is more input to read
-    while ( in_->more() )
-    {
-      // Read a chunk of data
-      const char* ptr = in_->read(actual_len);
-
-      // Parse it.
-      int parse_result = XML_Parse( xp_, ptr, actual_len, in_->more() ) ;
-
-      if ( XML_STATUS_ERROR == parse_result )
-      {
-        std::cerr << "Parsing Error\n";
-
-        // Signal end of the parsing if we didn't already
-        if (in_->more())
-          XML_Parse( xp_, 0, 0, 1 );
-        in_->finish();
-        return;
-      }
-    }
-
-    // Signal the end of parsing
-    XML_StopParser( xp_, 0);
-    in_->finish();
-  } catch (...) {
-    XML_StopParser(xp_,0);
-    in_->finish();
-    throw;
-  }
-}
-
-void 
-XMLReaderImpl::CDataSectionStart(void )
-{
-}
-
-void 
-XMLReaderImpl::CDataSectionEnd()
+inline void
+XMLReaderImpl::handleParseError(xmlErrorPtr e)
 {
+  std::cerr << e->file << ":" << e->line << ": parse " <<
+    (e->level == XML_ERR_WARNING ? "warning" : 
+     (e->level == XML_ERR_ERROR ? "error" :
+      (e->level == XML_ERR_FATAL ? "fatal error" : "message"))) 
+    << ": " << e->message << "\n";
 }
 
-void 
-XMLReaderImpl::NamespaceStart( const char* prefix, const char* uri )
+void ParseHandler(void* userData, xmlErrorPtr error) 
 {
+  XMLReaderImpl* reader = reinterpret_cast<XMLReaderImpl*>(userData);
+  reader->handleParseError(error);
 }
 
-void 
-XMLReaderImpl::NamespaceEnd( const char* prefix )
+void ValidationHandler(void* userData, xmlErrorPtr error)
 {
+  XMLReaderImpl* reader = reinterpret_cast<XMLReaderImpl*>(userData);
+  reader->handleValidationError(error);
 }
 
-void 
-XMLReaderImpl::ElementStart( const ElementInfo& elem)
+bool skipBlanks(xmlNodePtr cur)
 {
-  switch (elem.token) {
-    case TKN_bundle: {
-      const std::string* pubid = 0;
-      elem.find_attrs(TKN_pubid,pubid);
-      if (pubid) {
-        elem.node = 
-          new hlvm::AST::Bundle(static_cast<hlvm::AST::Bundle*>(0),*pubid);
-        node_ = elem.node;
-      }
-      break;
-    }
-    default:
-      break;
+  while ( cur && xmlIsBlankNode ( cur ) ) 
+  {
+    cur = cur -> next;
   }
+  return cur == 0;
 }
 
-void 
-XMLReaderImpl::ElementEnd( 
-  const ElementInfo& elem, uint32_t line, uint32_t column )
-{
-}
-
-void 
-XMLReaderImpl::ProcessingInstruction(
-  const std::string& target, const std::string&data)
-{
-}
-
-void 
-XMLReaderImpl::Comment( const std::string& )
-{
-}
-
-void 
-XMLReaderImpl::WhiteSpace( const std::string& )
-{
-}
-
-void 
-XMLReaderImpl::Characters( const std::string& )
-{
-}
-
-
 void
-ElementInfo::find_attrs(int token1, const std::string*& value1) const
+XMLReaderImpl::parseBundle(xmlNodePtr cur) 
 {
-  value1 = 0;
-  std::vector<AttrInfo>::const_iterator I = attrs.begin();
-  std::vector<AttrInfo>::const_iterator E = attrs.end();
-  for ( ; I != E && value1 == 0; ++I ) {
-    if (I->token == token1)
-      value1 = &I->value;
-  }
+  int tkn = 
+    HLVMTokenizer::recognize(reinterpret_cast<const char*>(cur->name));
+  assert(tkn == TKN_bundle && "Expecting bundle element");
+  xmlChar* pubid = 
+    xmlGetNoNsProp(cur,reinterpret_cast<const xmlChar*>("pubid"));
 }
 
 void
-ElementInfo::find_attrs(
-  int token1, const std::string*& value1,
-  int token2, const std::string*& value2
-) const
+XMLReaderImpl::parseTree() 
 {
-  value1 = value2 = 0;
-  std::vector<AttrInfo>::const_iterator I = attrs.begin();
-  std::vector<AttrInfo>::const_iterator E = attrs.end();
-  for ( ; I != E; ++I ) {
-    if (I->token == token1 && value1 == 0)
-      value1 = &I->value;
-    else if (I->token == token2 && value2 == 0)
-      value2 = &I->value;
-    else if (value1 != 0 && value2 !=0)
-      break;
-  }
+  if (node_)
+    delete node_;
+  node_ = 0;
+  xmlNodePtr cur = xmlDocGetRootElement(doc_);
+  if (!cur) {
+    error("No root node");
+    return;
+  }
+  int tkn = 
+    HLVMTokenizer::recognize(reinterpret_cast<const char*>(cur->name));
+  assert(tkn == TKN_hlvm && "Expecting hlvm element");
+  cur = cur->xmlChildrenNode;
+  if (skipBlanks(cur)) return;
+  parseBundle(cur);
+}
+
+// Implement the read interface to parse, validate, and convert the
+// XML document into AST Nodes. 
+// TODO: This needs  to (eventually) use the XMLTextReader API that libxml2
+// supports. 
+void
+XMLReaderImpl::read() {
+
+  // create the RelaxNG Parser Context
+  xmlRelaxNGParserCtxtPtr rngparser =
+    xmlRelaxNGNewMemParserCtxt(HLVMGrammar, sizeof(HLVMGrammar));
+  if (!rngparser) {
+    error("Failed to allocate RNG Parser Context");
+    return;
+  }
+
+  // Provide the error handler for parsing the schema
+  xmlRelaxNGSetParserStructuredErrors(rngparser, ParseHandler, this);
+
+  // Parse the schema and build an internal structure for it
+  xmlRelaxNGPtr schema = xmlRelaxNGParse(rngparser);
+  if (!schema) {
+    error("Failed to parse the RNG Schema");
+    xmlRelaxNGFreeParserCtxt(rngparser);
+    return;
+  }
+
+  // create a document parser context
+  xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
+  if (!ctxt) {
+    error("Failed to allocate document parser context");
+    xmlRelaxNGFreeParserCtxt(rngparser);
+    xmlRelaxNGFree(schema);
+    return;
+  }
+
+  // Parse the file, creating a Document tree
+  doc_ = xmlCtxtReadFile(ctxt, path_.c_str(), 0, 0);
+  if (!doc_) {
+    error("Failed to parse the document");
+    xmlRelaxNGFreeParserCtxt(rngparser);
+    xmlRelaxNGFree(schema);
+    xmlFreeParserCtxt(ctxt);
+    return;
+  }
+
+  // Create a validation context
+  xmlRelaxNGValidCtxtPtr validation = xmlRelaxNGNewValidCtxt(schema);
+  if (!validation) {
+    error("Failed to create the validation context");
+    xmlRelaxNGFreeParserCtxt(rngparser);
+    xmlRelaxNGFree(schema);
+    xmlFreeParserCtxt(ctxt);
+    xmlFreeDoc(doc_);
+    doc_ = 0;
+    return;
+  }
+
+  // Provide the error handler for parsing the schema
+  xmlRelaxNGSetValidStructuredErrors(validation, ValidationHandler, this);
+
+  // Validate the document with the schema
+  if (xmlRelaxNGValidateDoc(validation, doc_)) {
+    error("Document didn't pass RNG schema validation");
+    xmlRelaxNGFreeParserCtxt(rngparser);
+    xmlRelaxNGFree(schema);
+    xmlFreeParserCtxt(ctxt);
+    xmlFreeDoc(doc_);
+    xmlRelaxNGFreeValidCtxt(validation);
+    return;
+  }
+
+  // Parse
+  parseTree();
+  xmlRelaxNGFreeParserCtxt(rngparser);
+  xmlRelaxNGFree(schema);
+  xmlFreeParserCtxt(ctxt);
+  xmlRelaxNGFreeValidCtxt(validation);
 }
 
-void
-ElementInfo::find_attrs(
-  int token1, const std::string*& value1,
-  int token2, const std::string*& value2,
-  int token3, const std::string*& value3
-) const
+AST::Node*
+XMLReaderImpl::get()
 {
-  value1 = value2 = value3 = 0;
-  std::vector<AttrInfo>::const_iterator I = attrs.begin();
-  std::vector<AttrInfo>::const_iterator E = attrs.end();
-  for ( ; I != E; ++I ) {
-    if (I->token == token1 && value1 == 0)
-      value1 = &I->value;
-    else if (I->token == token2 && value2 == 0)
-      value2 = &I->value;
-    else if (I->token == token3 && value3 == 0)
-      value3 = &I->value;
-    else if (value1 != 0 && value2 !=0 && value3 != 0)
-      break;
-  }
+  return node_;
 }
 
+
 }
 
 XMLReader* 
-hlvm::XMLReader::create(hlvm::Base::Source* src)
+hlvm::XMLReader::create(const std::string& src)
 {
   return new XMLReaderImpl(src);
 }

Modified: hlvm/trunk/hlvm/Reader/XML/XMLReader.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XML/XMLReader.h?rev=38047&r1=38046&r2=38047&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/XMLReader.h (original)
+++ hlvm/trunk/hlvm/Reader/XML/XMLReader.h Sat Jul  7 18:59:17 2007
@@ -31,7 +31,7 @@
 #define XPS_READER_XML_XMLREADER_H
 
 #include <hlvm/Reader/Reader.h>
-#include <hlvm/Base/Source.h>
+#include <string>
 
 namespace hlvm {
 
@@ -43,7 +43,7 @@
     /// This method instantiates an XMLReader that is prepared to read from
     /// the path provided.
     /// @brief Create a new XmlReader
-    static XMLReader* create(Base::Source* in);
+    static XMLReader* create(const std::string& path);
 
     virtual ~XMLReader() {}
   };

Modified: hlvm/trunk/tools/hlvm-xml2xml/hlvm-xml2xml.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/tools/hlvm-xml2xml/hlvm-xml2xml.cpp?rev=38047&r1=38046&r2=38047&view=diff

==============================================================================
--- hlvm/trunk/tools/hlvm-xml2xml/hlvm-xml2xml.cpp (original)
+++ hlvm/trunk/tools/hlvm-xml2xml/hlvm-xml2xml.cpp Sat Jul  7 18:59:17 2007
@@ -76,23 +76,19 @@
       Out = &std::cout;
     }
 
-    Base::Source* src = 0;
-    llvm::sys::MappedFile* mf = 0;
     if (InputFilename == "-" ) {
-      src = Base::new_StreamSource(std::cin);
+      std::cerr << "Not supported yet: input from stdin\n";
+      exit(2);
     } else {
       llvm::sys::Path path(InputFilename);
-      if (path.canRead()) {
-        mf = new llvm::sys::MappedFile(path);
-        src = Base::new_MappedFileSource(*mf);
-      } else {
+      if (!path.canRead()) {
         std::cerr << argv[0] << ": can't read input file: " << InputFilename
                   << "\n";
         exit(2);
       }
     }
 
-    XMLReader* rdr = XMLReader::create(src);
+    XMLReader* rdr = XMLReader::create(InputFilename);
     XMLWriter* wrtr = XMLWriter::create(*Out);
     rdr->read();
     AST::Node* node = rdr->get();
@@ -101,10 +97,6 @@
     }
     delete rdr;
     delete wrtr;
-    if (mf) {
-      mf->close();
-      delete mf;
-    }
 
     if (Out != &std::cout) {
       static_cast<std::ofstream*>(Out)->close();





More information about the llvm-commits mailing list