• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef LIBABCKIT_MACROS_H
16 #define LIBABCKIT_MACROS_H
17 
18 #include <iostream>
19 #include "libabckit/src/statuses_impl.h"
20 
21 #include "libabckit/include/c/statuses.h"
22 #include "libabckit/src/logger.h"
23 
24 /*
25  * NOTE: __FUNCTION__ and __PRETTY_FUNCTION__ are non-standard extensions. Use __func__ for portability.
26  */
27 
28 #define LIBABCKIT_CLEAR_LAST_ERROR statuses::SetLastError(ABCKIT_STATUS_NO_ERROR)
29 
30 #define LIBABCKIT_RETURN_VOID
31 // CC-OFFNXT(G.PRE.02) code readability
32 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
33 #define LIBABCKIT_BAD_ARGUMENT(argument, returnvalue)       \
34     if ((argument) == nullptr) {                            \
35         statuses::SetLastError(ABCKIT_STATUS_BAD_ARGUMENT); \
36         /* CC-OFFNXT(G.PRE.05) code generation */           \
37         return returnvalue;                                 \
38     }
39 // CC-OFFNXT(G.PRE.02) code readability
40 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
41 #define LIBABCKIT_BAD_ARGUMENT_VOID(argument)               \
42     if ((argument) == nullptr) {                            \
43         statuses::SetLastError(ABCKIT_STATUS_BAD_ARGUMENT); \
44         /* CC-OFFNXT(G.PRE.05) code generation */           \
45         return;                                             \
46     }
47 // CC-OFFNXT(G.PRE.02) code readability
48 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
49 #define LIBABCKIT_INTERNAL_ERROR(argument, returnValue)       \
50     if ((argument) == nullptr) {                              \
51         statuses::SetLastError(ABCKIT_STATUS_INTERNAL_ERROR); \
52         /* CC-OFFNXT(G.PRE.05) code generation */             \
53         return returnValue;                                   \
54     }
55 // CC-OFFNXT(G.PRE.02) code readability
56 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
57 #define LIBABCKIT_INTERNAL_ERROR_VOID(argument)               \
58     if ((argument) == nullptr) {                              \
59         statuses::SetLastError(ABCKIT_STATUS_INTERNAL_ERROR); \
60         /* CC-OFFNXT(G.PRE.05) code generation */             \
61         return;                                               \
62     }
63 // CC-OFFNXT(G.PRE.02) code readability
64 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
65 #define LIBABCKIT_WRONG_CTX(lhs, rhs, returnvalue)       \
66     if ((lhs) != (rhs)) {                                \
67         statuses::SetLastError(ABCKIT_STATUS_WRONG_CTX); \
68         /* CC-OFFNXT(G.PRE.05) code generation */        \
69         return returnvalue;                              \
70     }
71 // CC-OFFNXT(G.PRE.02) code readability
72 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
73 #define LIBABCKIT_WRONG_CTX_VOID(lhs, rhs)               \
74     if ((lhs) != (rhs)) {                                \
75         statuses::SetLastError(ABCKIT_STATUS_WRONG_CTX); \
76         /* CC-OFFNXT(G.PRE.05) code generation */        \
77         return;                                          \
78     }
79 // CC-OFFNXT(G.PRE.02) code readability
80 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
81 #define LIBABCKIT_WRONG_MODE(graph, expectedMode, returnValue)       \
82     if ((graph)->file->frontend != (expectedMode)) {                 \
83         libabckit::statuses::SetLastError(ABCKIT_STATUS_WRONG_MODE); \
84         /* CC-OFFNXT(G.PRE.05) code generation */                    \
85         return returnValue;                                          \
86     }
87 // CC-OFFNXT(G.PRE.02) code readability
88 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
89 #define LIBABCKIT_ZERO_ARGUMENT(argument, returnvalue)      \
90     if ((argument) == 0) {                                  \
91         statuses::SetLastError(ABCKIT_STATUS_BAD_ARGUMENT); \
92         /* CC-OFFNXT(G.PRE.05) code generation */           \
93         return returnvalue;                                 \
94     }
95 // CC-OFFNXT(G.PRE.02) code readability
96 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
97 #define LIBABCKIT_ZERO_ARGUMENT_VOID(argument)              \
98     if ((argument) == 0) {                                  \
99         statuses::SetLastError(ABCKIT_STATUS_BAD_ARGUMENT); \
100         /* CC-OFFNXT(G.PRE.05) code generation */           \
101         return;                                             \
102     }
103 // CC-OFFNXT(G.PRE.09) code generation
104 // CC-OFFNXT(G.PRE.02) necessary macro
105 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
106 #define LIBABCKIT_CONCAT_INNER(x, y) x##y
107 // CC-OFFNXT(G.PRE.09) code generation
108 // CC-OFFNXT(G.PRE.02) necessary macro
109 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
110 #define LIBABCKIT_CONCAT(x, y) LIBABCKIT_CONCAT_INNER(x, y)
111 // CC-OFFNXT(G.PRE.09) code generation
112 // CC-OFFNXT(G.PRE.02) necessary macro
113 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
114 #define LIBABCKIT_UNIQUE_VAR(name) LIBABCKIT_CONCAT(_##name##_, LIBABCKIT_LINE)
115 #endif
116