Skip to content
This repository
Browse code

Made pire build and pass tests with clang-3.0.

  • Loading branch information...
commit a54f25f1b0d3fe9eea59657b084c7ec00cce8aa7 1 parent 1349422
authored June 09, 2012
34  configure.ac
@@ -26,9 +26,43 @@ AC_CHECK_FUNCS([memset strchr])
26 26
 
27 27
 AC_C_BIGENDIAN
28 28
 
  29
+# Utility check routine combining AC_TRY_COMPILE, AC_CACHE_CHECK and AC_DEFINE.
  30
+AC_DEFUN([AX_DEFINE_IF_COMPILES], [
  31
+	pire_saved_CXXFLAGS="$CXXFLAGS"
  32
+	CXXFLAGS="$CXXFLAGS -Wall -Wextra -Werror"
  33
+	AC_CACHE_CHECK([[whether $2]], [pire_cv_$1], AC_TRY_COMPILE([], [$3], [pire_cv_$1=yes], [pire_cv_$1=no]))
  34
+	CXXFLAGS="$pire_saved_CXXFLAGS"
  35
+	if test x[$]pire_cv_$1 = xyes; then
  36
+		AC_DEFINE([$1], 1, [Define to 1 if $2])
  37
+	fi
  38
+])
  39
+
  40
+
  41
+# Alignment check
29 42
 AC_CHECK_ALIGNOF(size_t)
30 43
 AC_CHECK_ALIGNOF(uint64_t)
31 44
 
  45
+AX_DEFINE_IF_COMPILES([HAVE_ALIGNAS], [C++11 alignas is supported], [[
  46
+	struct X { void* p; };
  47
+	alignas(X) static const char x[] = "foo";
  48
+	return x[0] == x[1];
  49
+]])
  50
+
  51
+AX_DEFINE_IF_COMPILES([HAVE_ATTR_ALIGNED], [__attribute__((aligned)) is supported], [[
  52
+	static const char x[] __attribute__((aligned(sizeof(void*)))) = "foo";
  53
+	return x[0] == x[1];
  54
+]])
  55
+
  56
+# Scoped init
  57
+AX_DEFINE_IF_COMPILES([HAVE_LAMBDAS], [C++11 lambdas are supported], [[
  58
+	return ([](int x) -> int { return x - 1; })(1)
  59
+]])
  60
+
  61
+AX_DEFINE_IF_COMPILES([HAVE_SCOPED_EXPR], [gcc-specific scoped expressions are supported], [[
  62
+	return ({ int a = 1; int b = 1; a - b; });
  63
+]])
  64
+
  65
+
32 66
 # Optional features
33 67
 AC_ARG_ENABLE([extra], AS_HELP_STRING([--enable-extra], [Add extra functionality (capturing scanner, etc...)]))
34 68
 AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [Make Pire dump all constructed FSMs to std::clog (useless unless debugging Pire)]))
28  pire/defs.h
@@ -27,19 +27,20 @@
27 27
 #ifndef PIRE_NO_CONFIG
28 28
 #include <pire/config.h>
29 29
 #endif
  30
+#include <stdlib.h>
30 31
 
31 32
 namespace Pire {
32 33
 
33 34
 #ifdef PIRE_DEBUG
34  
-#define PIRE_IFDEBUG(x) x
  35
+#	define PIRE_IFDEBUG(x) x
35 36
 #else
36  
-#define PIRE_IFDEBUG(x)
  37
+#	define PIRE_IFDEBUG(x)
37 38
 #endif
38 39
 	
39 40
 #ifdef PIRE_CHECKED
40  
-#define PIRE_IF_CHECKED(e) e
  41
+#	define PIRE_IF_CHECKED(e) e
41 42
 #else
42  
-#define PIRE_IF_CHECKED(e)
  43
+#	define PIRE_IF_CHECKED(e)
43 44
 #endif
44 45
 
45 46
 
@@ -76,9 +77,26 @@ namespace Pire {
76 77
 		inline size_t SwapBytes<8>(size_t val) { return val & 0xFF; }
77 78
 
78 79
 		inline size_t ToLittleEndian(size_t val) { return SwapBytes<sizeof(val)*8>(val); }
79  
-		
80 80
 #endif
  81
+
  82
+        struct Struct { void* p; };
81 83
 	}
82 84
 }
83 85
 
  86
+#ifndef PIRE_ALIGNED_DECL
  87
+#	if defined(PIRE_HAVE_ALIGNAS)
  88
+#		define PIRE_ALIGNED_DECL(x) alignas(::Pire::Impl::Struct) static const char x[]
  89
+#	elif defined(PIRE_HAVE_ATTR_ALIGNED)
  90
+#		define PIRE_ALIGNED_DECL(x) static const char x[] __attribute__((aligned(sizeof(void*))))
  91
+#	endif
  92
+#endif
  93
+
  94
+#ifndef PIRE_LITERAL
  95
+#	if defined(PIRE_HAVE_LAMBDAS)
  96
+#		define PIRE_LITERAL(data) ([]() -> const char* { PIRE_ALIGNED_DECL(__pire_regexp__) = data; return __pire_regexp__; })()
  97
+#	elif defined(PIRE_HAVE_SCOPED_EXPR)
  98
+#		define PIRE_LITERAL(data) ({ PIRE_ALIGNED_DECL(__pire_regexp__) = data; __pire_regexp__; })
  99
+#	endif
  100
+#endif
  101
+
84 102
 #endif
4  pire/easy.h
@@ -122,9 +122,9 @@ class Option {
122 122
 	}
123 123
 	
124 124
 	template<class Arg2>
125  
-	friend Options operator | (const Option<Arg2>& a, const Option<Arg>& b)
  125
+	Options operator | (const Option<Arg2>& other) const
126 126
 	{
127  
-		return Options() | a | b;
  127
+		return Options() | *this | other;
128 128
 	}
129 129
 
130 130
 private:
4  pire/inline.lpp
@@ -178,7 +178,7 @@ void eatComment(void (*action)(char));
178 178
 	AlignedOutput stream(&buf);
179 179
 	Save(&stream, sc);
180 180
 
181  
-	fprintf(yyout, "Pire::MmappedScanner<Pire::Scanner>( // %s \n    \"", pattern.c_str());
  181
+	fprintf(yyout, "Pire::MmappedScanner<Pire::Scanner>(PIRE_LITERAL( // %s \n    \"", pattern.c_str());
182 182
 	size_t pos = 5;
183 183
 	for (BufferIterator i = buf.Buffer().Begin(), ie = buf.Buffer().End(); i != ie; ++i) {
184 184
 		pos += fprintf(yyout, "\\x%02X", static_cast<unsigned char>(*i));
@@ -187,7 +187,7 @@ void eatComment(void (*action)(char));
187 187
 			pos = 5;
188 188
 		}
189 189
 	}
190  
-	fprintf(yyout, "\", %u)\n#line %d \"%s\"\n",
  190
+	fprintf(yyout, "\"), %u)\n#line %d \"%s\"\n",
191 191
 		(unsigned int) buf.Buffer().Size(), line, filename.c_str());
192 192
 	BEGIN(INITIAL);
193 193
 }
2  pire/scanners/multi.h
@@ -1009,7 +1009,7 @@ class ScannerGlueTask: public ScannerGlueCommon<Scanner> {
1009 1009
 		size_t finalTableSize = 0;
1010 1010
 		for (typename yvector<State>::const_iterator i = states.begin(), ie = states.end(); i != ie; ++i)
1011 1011
 			finalTableSize += RangeLen(Lhs().AcceptedRegexps(i->first)) + RangeLen(Rhs().AcceptedRegexps(i->second));
1012  
-		SetSc(new Scanner);
  1012
+		this->SetSc(new Scanner);
1013 1013
 		Sc().Init(states.size(), Letters(), finalTableSize, size_t(0), Lhs().RegexpsCount() + Rhs().RegexpsCount());
1014 1014
 				
1015 1015
 		for (size_t state = 0; state != states.size(); ++state) {
6  pire/stub/saveload.h
@@ -52,7 +52,7 @@ namespace Pire {
52 52
 				if (!Traits::eq_int_type(ret, Traits::eof())) {
53 53
 					m_ch = (Char) ret;
54 54
 					m_read += sizeof(Char);
55  
-					setg(&m_ch, &m_ch, &m_ch+1);
  55
+					this->setg(&m_ch, &m_ch, &m_ch+1);
56 56
 				}
57 57
 				return ret;
58 58
 			}
@@ -64,7 +64,7 @@ namespace Pire {
64 64
 				return ret;
65 65
 			}
66 66
 
67  
-			typename Traits::int_type overflow(Char c)
  67
+			typename Traits::int_type overflow(typename Traits::int_type c)
68 68
 			{
69 69
 				typename Traits::int_type ret = m_backend->sputc(c);
70 70
 				if (!Traits::eq_int_type(ret, Traits::eof()))
@@ -119,7 +119,7 @@ namespace Pire {
119 119
 				: std::basic_ostream<Char, Traits>(0)
120 120
 				, m_streambuf(backend->rdbuf())
121 121
 			{
122  
-				rdbuf(&m_streambuf);
  122
+				this->rdbuf(&m_streambuf);
123 123
 			}
124 124
 
125 125
 			void Align(size_t divisor = sizeof(void*))
3  pire/stub/stl.h
@@ -28,6 +28,7 @@
28 28
 #ifndef PIRE_COMPAT_H_INCLUDED
29 29
 #define PIRE_COMPAT_H_INCLUDED
30 30
 
  31
+#include "../defs.h"
31 32
 #include <string>
32 33
 #include <vector>
33 34
 #include <deque>
@@ -199,7 +200,7 @@ namespace Pire {
199 200
 	template<class T>
200 201
 	inline const T& ymax(const T& a, const T& b) { return std::max(a, b); }
201 202
 
202  
-	static std::ostream& Cdbg = std::clog;
  203
+	PIRE_IFDEBUG(static std::ostream& Cdbg = std::clog);
203 204
 
204 205
 	inline yostream& Endl(yostream& s) { return std::endl(s); }
205 206
 
2  pire/stub/unidata_cpp.h
@@ -38,7 +38,7 @@
38 38
 */
39 39
 
40 40
 
41  
-const i32 unicode_types[282] = {
  41
+const ui32 unicode_types[282] = {
42 42
 	0x00000018,0x00090019,0x00080019,0x0008001A,0x0009001A,0x000A0014,0x000B002C,0x000B002B,
43 43
 	0x0005002A,0x00050031,0x000B002A,0x000B0038,0x000B0023,0x000B0025,0x0005002F,0x0007002C,
44 44
 	0x00050022,0x0004002A,0x00030210,0xFC030610,0x000B002F,0x08010241,0x08010041,0x000B0032,
4  pire/stub/unidata_h.h
@@ -113,7 +113,7 @@ enum WC_TYPE {
113 113
 
114 114
 const size_t DEFCHAR_BUF = 58; // CCL_NUM + 1
115 115
 
116  
-extern const i32  unicode_types[];
  116
+extern const ui32 unicode_types[];
117 117
 extern const wchar32 decomp_mapping[];
118 118
 extern const ui32 *unicode_pages[];
119 119
 
@@ -132,7 +132,7 @@ ui32 _runeinfo(wchar32 ch)
132 132
 		return _runeinfo(0xE001);//as characters from Private Use Zone
133 133
 	return unicode_pages[(ch>>5)&0x7FF][ch&0x1F];
134 134
 }
135  
-i32 wc_info(wchar32 ch)
  135
+ui32 wc_info(wchar32 ch)
136 136
 {
137 137
 	return unicode_types[(_runeinfo(ch)>>TYPES_OFFSET) & TYPES_MASK];
138 138
 }
14  tools/bench/bench.cpp
@@ -92,7 +92,7 @@ class ITester {
92 92
 
93 93
 // Sinlge regexp scanner
94 94
 template<class Scanner>
95  
-struct Compile {
  95
+struct CompileRe {
96 96
 	static Scanner Do(const Patterns& patterns, bool surround)
97 97
 	{
98 98
 		if (patterns.size() != 1)
@@ -106,7 +106,7 @@ struct Compile {
106 106
 
107 107
 // Multi regexp scanner
108 108
 template<class Relocation, class Shortcutting>
109  
-struct Compile< Pire::Impl::Scanner<Relocation, Shortcutting> > {
  109
+struct CompileRe< Pire::Impl::Scanner<Relocation, Shortcutting> > {
110 110
 	static Pire::Impl::Scanner<Relocation, Shortcutting> Do(const Patterns& patterns, bool surround)
111 111
 	{
112 112
 		typedef Pire::Impl::Scanner<Relocation, Shortcutting> Sc;
@@ -172,7 +172,7 @@ struct PrintResult< Pire::ScannerPair<Scanner1, Scanner2> > {
172 172
 
173 173
 #ifdef BENCH_EXTRA_ENABLED
174 174
 template <>
175  
-struct Compile<Pire::CapturingScanner> {
  175
+struct CompileRe<Pire::CapturingScanner> {
176 176
 	static Pire::CapturingScanner Do(const Patterns& patterns, bool surround)
177 177
 	{
178 178
 		if (patterns.size() != 1)
@@ -185,7 +185,7 @@ struct Compile<Pire::CapturingScanner> {
185 185
 };
186 186
 
187 187
 template <>
188  
-struct Compile<Pire::CountingScanner> {
  188
+struct CompileRe<Pire::CountingScanner> {
189 189
 	static Pire::CountingScanner Do(const Patterns& patterns, bool /*surround*/)
190 190
 	{
191 191
 		Pire::CountingScanner sc;
@@ -268,7 +268,7 @@ class Tester: public TesterBase<Scanner> {
268 268
 	{
269 269
 		if (patterns.size() != 1)
270 270
 			throw std::runtime_error("Only one set of regexps is allowed for this scanner");
271  
-		Base::sc = ::Compile<Scanner>::Do(patterns[0], surround);
  271
+		Base::sc = ::CompileRe<Scanner>::Do(patterns[0], surround);
272 272
 	}
273 273
 };
274 274
 
@@ -280,8 +280,8 @@ class PairTester: public TesterBase< Pire::ScannerPair<Scanner1, Scanner2> > {
280 280
 	{
281 281
 		if (patterns.size() != 2)
282 282
 			throw std::runtime_error("Only two sets of regexps are allowed for this scanner");
283  
-		sc1 = ::Compile<Scanner1>::Do(patterns[0], surround);
284  
-		sc2 = ::Compile<Scanner2>::Do(patterns[1], surround);
  283
+		sc1 = ::CompileRe<Scanner1>::Do(patterns[0], surround);
  284
+		sc2 = ::CompileRe<Scanner2>::Do(patterns[1], surround);
285 285
 		typedef Pire::ScannerPair<Scanner1, Scanner2> Pair;
286 286
 		Base::sc = Pair(sc1, sc2);
287 287
 	}

0 notes on commit a54f25f

Please sign in to comment.
Something went wrong with that request. Please try again.