CodeSonar C++ API
[For improved navigation, enable JavaScript.]
cs_api_defs.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, an unpublished work by CodeSecure, Inc.
3  * ALL RIGHTS RESERVED
4  *
5  * Copyright (c) 2013-2023, an unpublished work by GrammaTech, Inc.
6  * ALL RIGHTS RESERVED
7  *
8  * This software is furnished under a license and may be used and
9  * copied only in accordance with the terms of such license and the
10  * inclusion of the above copyright notice. This software or any
11  * other copies thereof may not be provided or otherwise made
12  * available to any other person. Title to and ownership of the
13  * software is retained by CodeSecure, Inc.
14  */
15 
16 #ifndef CS_API_DEFS_HPP
17 #define CS_API_DEFS_HPP
18 
21 #define CS_AS_REPR_PREFIX CS_AS_REPR_OPEN "cs" CS_AS_REPR_SCOPE
22 #define CS_AS_REPR_SUFFIX CS_AS_REPR_CLOSE
23 
24 #define CS_AS_REPR_RAW(middle) (CS_AS_REPR_PREFIX middle CS_AS_REPR_SUFFIX)
25 #define CS_AS_REPR(type, content) CS_AS_REPR_RAW(#type " " + (content) +)
26 #define CS_AS_REPR_FROM_STRING(type) CS_AS_REPR(type, as_string())
27 
28 #ifdef SWIG
29 
30 #define SWIGONLY(...) __VA_ARGS__
31 #define NOTSWIG(...)
32 #define CS_INLINE static inline
33 
34 #define CS_NORETURN(d) d
35 #define CS_EXPECT(e,c) (e)
36 #define cs_unlikely(c) (c)
37 #define cs_likely(c) (c)
38 #define cs_static_assert(c)
39 #define cs_static_assert_alignment(t,a)
40 #define __CS_BEGIN_DECLS extern "C" {
41 #define __CS_END_DECLS }
42 
43 
44 #else
45 
46 #define SWIGONLY(...)
47 #define NOTSWIG(...) __VA_ARGS__
48 
49 #ifndef CS_CPP_NO_EXCEPTIONS
50 # if defined(__GNUC__) && !defined(__EXCEPTIONS)
51 # define CS_CPP_NO_EXCEPTIONS 1
52 
53 # else
54 /* Assume exceptions. You can explicitly
55  * "#define CS_CPP_NO_EXCEPTIONS 1" if not using gcc.
56  *
57  * If anyone knows how other compilers do this, then please
58  * contribute.
59  *
60  * Disabling exceptions will turn exceptions into fatal errors.
61  */
62 # define CS_CPP_NO_EXCEPTIONS 0
63 # endif
64 #endif
65 
66 #if CS_CPP_NO_EXCEPTIONS && !defined(cs) && !defined(CSFE_API)
67 /* This may be needed to guard against one definition rule problems.
68  * I apologize if you happen to have identifiers named "cs."
69  */
70 #define cs cs_noexc
71 #endif
72 
73 #if CS_CPP_NO_EXCEPTIONS
74 #define CS_CPP_TRY(body) do body while(0);
75 #define CS_CPP_CATCH(arg, body)
76 #else
77 #define CS_CPP_TRY(body) try body
78 #define CS_CPP_CATCH(arg, body) catch(arg) body
79 #endif
80 
81 #endif
82 
83 
84 #ifndef SWIG
85 #define CS_AS_REPR_OPEN "<"
86 #define CS_AS_REPR_SCOPE "."
87 #define CS_AS_REPR_CLOSE ">"
88 #endif
89 
90 /* Java and C# have hashable interfaces requiring hash functions to
91  * return ints */
92 #if defined(SWIGJAVA) || defined(SWIGCSHARP)
93 #define CS_BOILERPLATE_HASH_TYPE int
94 #else
95 #define CS_BOILERPLATE_HASH_TYPE cs_hash_t
96 #endif
97 
98 #ifdef SWIG_BUILD
99 #define SWIG_BUILD_ONLY(...) __VA_ARGS__
100 #define NOT_SWIG_BUILD_ONLY(...)
101 #else
102 #define SWIG_BUILD_ONLY(...)
103 #define NOT_SWIG_BUILD_ONLY(...) __VA_ARGS__
104 #endif
105 
106 #ifdef SWIG
107 #define CS_STD_HASH(cls, cs)
108 #else
109 #define CS_STD_HASH(cls, cs) \
110  } namespace std{ \
111  template<> struct hash<cs::cls>{ size_t operator()( const cs::cls &x ) const{ return x.hash(); } }; \
112  } namespace cs{ \
113 
114 #endif
115 
116 #endif /* CS_API_DEFS_HPP */