Permalink
Browse files

Made pire build and pass tests with clang-3.0.

  • Loading branch information...
Dmitry Prokoptsev
Dmitry Prokoptsev committed Jun 8, 2012
1 parent 1349422 commit a54f25f1b0d3fe9eea59657b084c7ec00cce8aa7
Showing with 77 additions and 24 deletions.
  1. +34 −0 configure.ac
  2. +23 −5 pire/defs.h
  3. +2 −2 pire/easy.h
  4. +2 −2 pire/inline.lpp
  5. +1 −1 pire/scanners/multi.h
  6. +3 −3 pire/stub/saveload.h
  7. +2 −1 pire/stub/stl.h
  8. +1 −1 pire/stub/unidata_cpp.h
  9. +2 −2 pire/stub/unidata_h.h
  10. +7 −7 tools/bench/bench.cpp
View
@@ -26,9 +26,43 @@ AC_CHECK_FUNCS([memset strchr])
AC_C_BIGENDIAN
+# Utility check routine combining AC_TRY_COMPILE, AC_CACHE_CHECK and AC_DEFINE.
+AC_DEFUN([AX_DEFINE_IF_COMPILES], [
+ pire_saved_CXXFLAGS="$CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS -Wall -Wextra -Werror"
+ AC_CACHE_CHECK([[whether $2]], [pire_cv_$1], AC_TRY_COMPILE([], [$3], [pire_cv_$1=yes], [pire_cv_$1=no]))
+ CXXFLAGS="$pire_saved_CXXFLAGS"
+ if test x[$]pire_cv_$1 = xyes; then
+ AC_DEFINE([$1], 1, [Define to 1 if $2])
+ fi
+])
+
+
+# Alignment check
AC_CHECK_ALIGNOF(size_t)
AC_CHECK_ALIGNOF(uint64_t)
+AX_DEFINE_IF_COMPILES([HAVE_ALIGNAS], [C++11 alignas is supported], [[
+ struct X { void* p; };
+ alignas(X) static const char x[] = "foo";
+ return x[0] == x[1];
+]])
+
+AX_DEFINE_IF_COMPILES([HAVE_ATTR_ALIGNED], [__attribute__((aligned)) is supported], [[
+ static const char x[] __attribute__((aligned(sizeof(void*)))) = "foo";
+ return x[0] == x[1];
+]])
+
+# Scoped init
+AX_DEFINE_IF_COMPILES([HAVE_LAMBDAS], [C++11 lambdas are supported], [[
+ return ([](int x) -> int { return x - 1; })(1)
+]])
+
+AX_DEFINE_IF_COMPILES([HAVE_SCOPED_EXPR], [gcc-specific scoped expressions are supported], [[
+ return ({ int a = 1; int b = 1; a - b; });
+]])
+
+
# Optional features
AC_ARG_ENABLE([extra], AS_HELP_STRING([--enable-extra], [Add extra functionality (capturing scanner, etc...)]))
AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [Make Pire dump all constructed FSMs to std::clog (useless unless debugging Pire)]))
View
@@ -27,19 +27,20 @@
#ifndef PIRE_NO_CONFIG
#include <pire/config.h>
#endif
+#include <stdlib.h>
namespace Pire {
#ifdef PIRE_DEBUG
-#define PIRE_IFDEBUG(x) x
+# define PIRE_IFDEBUG(x) x
#else
-#define PIRE_IFDEBUG(x)
+# define PIRE_IFDEBUG(x)
#endif
#ifdef PIRE_CHECKED
-#define PIRE_IF_CHECKED(e) e
+# define PIRE_IF_CHECKED(e) e
#else
-#define PIRE_IF_CHECKED(e)
+# define PIRE_IF_CHECKED(e)
#endif
@@ -76,9 +77,26 @@ namespace Pire {
inline size_t SwapBytes<8>(size_t val) { return val & 0xFF; }
inline size_t ToLittleEndian(size_t val) { return SwapBytes<sizeof(val)*8>(val); }
-
#endif
+
+ struct Struct { void* p; };
}
}
+#ifndef PIRE_ALIGNED_DECL
+# if defined(PIRE_HAVE_ALIGNAS)
+# define PIRE_ALIGNED_DECL(x) alignas(::Pire::Impl::Struct) static const char x[]
+# elif defined(PIRE_HAVE_ATTR_ALIGNED)
+# define PIRE_ALIGNED_DECL(x) static const char x[] __attribute__((aligned(sizeof(void*))))
+# endif
+#endif
+
+#ifndef PIRE_LITERAL
+# if defined(PIRE_HAVE_LAMBDAS)
+# define PIRE_LITERAL(data) ([]() -> const char* { PIRE_ALIGNED_DECL(__pire_regexp__) = data; return __pire_regexp__; })()
+# elif defined(PIRE_HAVE_SCOPED_EXPR)
+# define PIRE_LITERAL(data) ({ PIRE_ALIGNED_DECL(__pire_regexp__) = data; __pire_regexp__; })
+# endif
+#endif
+
#endif
View
@@ -122,9 +122,9 @@ class Option {
}
template<class Arg2>
- friend Options operator | (const Option<Arg2>& a, const Option<Arg>& b)
+ Options operator | (const Option<Arg2>& other) const
{
- return Options() | a | b;
+ return Options() | *this | other;
}
private:
View
@@ -178,7 +178,7 @@ void eatComment(void (*action)(char));
AlignedOutput stream(&buf);
Save(&stream, sc);
- fprintf(yyout, "Pire::MmappedScanner<Pire::Scanner>( // %s \n \"", pattern.c_str());
+ fprintf(yyout, "Pire::MmappedScanner<Pire::Scanner>(PIRE_LITERAL( // %s \n \"", pattern.c_str());
size_t pos = 5;
for (BufferIterator i = buf.Buffer().Begin(), ie = buf.Buffer().End(); i != ie; ++i) {
pos += fprintf(yyout, "\\x%02X", static_cast<unsigned char>(*i));
@@ -187,7 +187,7 @@ void eatComment(void (*action)(char));
pos = 5;
}
}
- fprintf(yyout, "\", %u)\n#line %d \"%s\"\n",
+ fprintf(yyout, "\"), %u)\n#line %d \"%s\"\n",
(unsigned int) buf.Buffer().Size(), line, filename.c_str());
BEGIN(INITIAL);
}
View
@@ -1009,7 +1009,7 @@ class ScannerGlueTask: public ScannerGlueCommon<Scanner> {
size_t finalTableSize = 0;
for (typename yvector<State>::const_iterator i = states.begin(), ie = states.end(); i != ie; ++i)
finalTableSize += RangeLen(Lhs().AcceptedRegexps(i->first)) + RangeLen(Rhs().AcceptedRegexps(i->second));
- SetSc(new Scanner);
+ this->SetSc(new Scanner);
Sc().Init(states.size(), Letters(), finalTableSize, size_t(0), Lhs().RegexpsCount() + Rhs().RegexpsCount());
for (size_t state = 0; state != states.size(); ++state) {
View
@@ -52,7 +52,7 @@ namespace Pire {
if (!Traits::eq_int_type(ret, Traits::eof())) {
m_ch = (Char) ret;
m_read += sizeof(Char);
- setg(&m_ch, &m_ch, &m_ch+1);
+ this->setg(&m_ch, &m_ch, &m_ch+1);
}
return ret;
}
@@ -64,7 +64,7 @@ namespace Pire {
return ret;
}
- typename Traits::int_type overflow(Char c)
+ typename Traits::int_type overflow(typename Traits::int_type c)
{
typename Traits::int_type ret = m_backend->sputc(c);
if (!Traits::eq_int_type(ret, Traits::eof()))
@@ -119,7 +119,7 @@ namespace Pire {
: std::basic_ostream<Char, Traits>(0)
, m_streambuf(backend->rdbuf())
{
- rdbuf(&m_streambuf);
+ this->rdbuf(&m_streambuf);
}
void Align(size_t divisor = sizeof(void*))
View
@@ -28,6 +28,7 @@
#ifndef PIRE_COMPAT_H_INCLUDED
#define PIRE_COMPAT_H_INCLUDED
+#include "../defs.h"
#include <string>
#include <vector>
#include <deque>
@@ -199,7 +200,7 @@ namespace Pire {
template<class T>
inline const T& ymax(const T& a, const T& b) { return std::max(a, b); }
- static std::ostream& Cdbg = std::clog;
+ PIRE_IFDEBUG(static std::ostream& Cdbg = std::clog);
inline yostream& Endl(yostream& s) { return std::endl(s); }
View
@@ -38,7 +38,7 @@
*/
-const i32 unicode_types[282] = {
+const ui32 unicode_types[282] = {
0x00000018,0x00090019,0x00080019,0x0008001A,0x0009001A,0x000A0014,0x000B002C,0x000B002B,
0x0005002A,0x00050031,0x000B002A,0x000B0038,0x000B0023,0x000B0025,0x0005002F,0x0007002C,
0x00050022,0x0004002A,0x00030210,0xFC030610,0x000B002F,0x08010241,0x08010041,0x000B0032,
View
@@ -113,7 +113,7 @@ enum WC_TYPE {
const size_t DEFCHAR_BUF = 58; // CCL_NUM + 1
-extern const i32 unicode_types[];
+extern const ui32 unicode_types[];
extern const wchar32 decomp_mapping[];
extern const ui32 *unicode_pages[];
@@ -132,7 +132,7 @@ ui32 _runeinfo(wchar32 ch)
return _runeinfo(0xE001);//as characters from Private Use Zone
return unicode_pages[(ch>>5)&0x7FF][ch&0x1F];
}
-i32 wc_info(wchar32 ch)
+ui32 wc_info(wchar32 ch)
{
return unicode_types[(_runeinfo(ch)>>TYPES_OFFSET) & TYPES_MASK];
}
View
@@ -92,7 +92,7 @@ class ITester {
// Sinlge regexp scanner
template<class Scanner>
-struct Compile {
+struct CompileRe {
static Scanner Do(const Patterns& patterns, bool surround)
{
if (patterns.size() != 1)
@@ -106,7 +106,7 @@ struct Compile {
// Multi regexp scanner
template<class Relocation, class Shortcutting>
-struct Compile< Pire::Impl::Scanner<Relocation, Shortcutting> > {
+struct CompileRe< Pire::Impl::Scanner<Relocation, Shortcutting> > {
static Pire::Impl::Scanner<Relocation, Shortcutting> Do(const Patterns& patterns, bool surround)
{
typedef Pire::Impl::Scanner<Relocation, Shortcutting> Sc;
@@ -172,7 +172,7 @@ struct PrintResult< Pire::ScannerPair<Scanner1, Scanner2> > {
#ifdef BENCH_EXTRA_ENABLED
template <>
-struct Compile<Pire::CapturingScanner> {
+struct CompileRe<Pire::CapturingScanner> {
static Pire::CapturingScanner Do(const Patterns& patterns, bool surround)
{
if (patterns.size() != 1)
@@ -185,7 +185,7 @@ struct Compile<Pire::CapturingScanner> {
};
template <>
-struct Compile<Pire::CountingScanner> {
+struct CompileRe<Pire::CountingScanner> {
static Pire::CountingScanner Do(const Patterns& patterns, bool /*surround*/)
{
Pire::CountingScanner sc;
@@ -268,7 +268,7 @@ class Tester: public TesterBase<Scanner> {
{
if (patterns.size() != 1)
throw std::runtime_error("Only one set of regexps is allowed for this scanner");
- Base::sc = ::Compile<Scanner>::Do(patterns[0], surround);
+ Base::sc = ::CompileRe<Scanner>::Do(patterns[0], surround);
}
};
@@ -280,8 +280,8 @@ class PairTester: public TesterBase< Pire::ScannerPair<Scanner1, Scanner2> > {
{
if (patterns.size() != 2)
throw std::runtime_error("Only two sets of regexps are allowed for this scanner");
- sc1 = ::Compile<Scanner1>::Do(patterns[0], surround);
- sc2 = ::Compile<Scanner2>::Do(patterns[1], surround);
+ sc1 = ::CompileRe<Scanner1>::Do(patterns[0], surround);
+ sc2 = ::CompileRe<Scanner2>::Do(patterns[1], surround);
typedef Pire::ScannerPair<Scanner1, Scanner2> Pair;
Base::sc = Pair(sc1, sc2);
}

0 comments on commit a54f25f

Please sign in to comment.