]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/antlr4-common.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / antlr4-common.h
1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2  * Use of this file is governed by the BSD 3-clause license that
3  * can be found in the LICENSE.txt file in the project root.
4  */
5
6 #pragma once
7
8 #include <algorithm>
9 #include <assert.h>
10 #include <atomic>
11 #include <chrono>
12 #include <fstream>
13 #include <iostream>
14 #include <iterator>
15 #include <limits>
16 #include <limits.h>
17 #include <list>
18 #include <map>
19 #include <memory>
20 #include <set>
21 #include <stdarg.h>
22 #include <stdint.h>
23 #include <stdlib.h>
24 #include <sstream>
25 #include <stack>
26 #include <string>
27 #include <typeinfo>
28 #include <type_traits>
29 #include <unordered_map>
30 #include <unordered_set>
31 #include <utility>
32 #include <vector>
33 #include <mutex>
34 #include <exception>
35 #include <bitset>
36 #include <condition_variable>
37 #include <functional>
38
39 #ifndef USE_UTF8_INSTEAD_OF_CODECVT
40   #include <codecvt>
41 #endif
42
43 // Defines for the Guid class and other platform dependent stuff.
44 #ifdef _WIN32
45   #ifdef _MSC_VER
46     #pragma warning (disable: 4250) // Class inherits by dominance.
47     #pragma warning (disable: 4512) // assignment operator could not be generated
48
49     #if _MSC_VER < 1900
50       // Before VS 2015 code like "while (true)" will create a (useless) warning in level 4.
51       #pragma warning (disable: 4127) // conditional expression is constant
52     #endif
53   #endif
54
55   #define GUID_WINDOWS
56
57   #ifdef _WIN64
58     typedef __int64 ssize_t;
59   #else
60     typedef __int32 ssize_t;
61   #endif
62
63   #if _MSC_VER >= 1900 && _MSC_VER < 2000
64     // VS 2015 has a known bug when using std::codecvt_utf8<char32_t>
65     // so we have to temporarily use __int32 instead.
66     // https://connect.microsoft.com/VisualStudio/feedback/details/1403302/unresolved-external-when-using-codecvt-utf8
67     typedef std::basic_string<__int32> i32string;
68
69     typedef i32string UTF32String;
70   #else
71     typedef std::u32string UTF32String;
72   #endif
73
74   #ifdef ANTLR4CPP_EXPORTS
75     #define ANTLR4CPP_PUBLIC __declspec(dllexport)
76   #else
77     #ifdef ANTLR4CPP_STATIC
78       #define ANTLR4CPP_PUBLIC
79     #else
80       #define ANTLR4CPP_PUBLIC __declspec(dllimport)
81     #endif
82   #endif
83
84   #if defined(_MSC_VER) && !defined(__clang__)
85     // clang-cl should escape this to prevent [ignored-attributes].
86     namespace std {
87       class ANTLR4CPP_PUBLIC exception; // Prevents warning C4275 from MSVC.
88     } // namespace std
89   #endif
90
91 #elif defined(__APPLE__)
92   typedef std::u32string UTF32String;
93
94   #define GUID_CFUUID
95   #if __GNUC__ >= 4
96     #define ANTLR4CPP_PUBLIC __attribute__ ((visibility ("default")))
97   #else
98     #define ANTLR4CPP_PUBLIC
99   #endif
100 #else
101   typedef std::u32string UTF32String;
102
103   #define GUID_LIBUUID
104   #if __GNUC__ >= 6
105     #define ANTLR4CPP_PUBLIC __attribute__ ((visibility ("default")))
106   #else
107     #define ANTLR4CPP_PUBLIC
108   #endif
109 #endif
110
111 #include "support/guid.h"
112 #include "support/Declarations.h"
113
114 #if !defined(HAS_NOEXCEPT)
115   #if defined(__clang__)
116     #if __has_feature(cxx_noexcept)
117       #define HAS_NOEXCEPT
118     #endif
119   #else
120     #if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 || \
121       defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026
122       #define HAS_NOEXCEPT
123     #endif
124   #endif
125
126   #ifdef HAS_NOEXCEPT
127     #define NOEXCEPT noexcept
128   #else
129     #define NOEXCEPT
130   #endif
131 #endif
132
133 // We have to undefine this symbol as ANTLR will use this name for own members and even
134 // generated functions. Because EOF is a global macro we cannot use e.g. a namespace scope to disambiguate.
135 #ifdef EOF
136 #undef EOF
137 #endif
138
139 #define INVALID_INDEX std::numeric_limits<size_t>::max()
140 template<class T> using Ref = std::shared_ptr<T>;