1 /** 2 * Copyright (c) 2025 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 16 #ifndef ES2PANDA_UTIL_ES2PANDA_MACROS_H 17 #define ES2PANDA_UTIL_ES2PANDA_MACROS_H 18 19 #include "macros.h" 20 #include "lexer/token/sourceLocation.h" 21 namespace ark::es2panda::parser { 22 class Program; 23 } // namespace ark::es2panda::parser 24 25 namespace ark::es2panda { 26 lexer::SourcePosition GetPositionForDiagnostic(); 27 void CompilerBugAction(const lexer::SourcePosition &pos); 28 } // namespace ark::es2panda 29 30 #ifndef NDEBUG 31 // CC-OFFNXT(G.PRE.06) solid logic 32 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 33 #define ES2PANDA_ASSERT_POS(cond, position) \ 34 if (UNLIKELY(!(cond))) { \ 35 ark::es2panda::CompilerBugAction(position); \ 36 ASSERT_FAIL(#cond); \ 37 } 38 39 // CC-OFFNXT(G.PRE.06) solid logic 40 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 41 #define ES2PANDA_ASSERT(cond) ES2PANDA_ASSERT_POS(cond, GetPositionForDiagnostic()) 42 43 // CC-OFFNXT(G.PRE.06) solid logic 44 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 45 #define ES2PANDA_UNREACHABLE_POS(position) \ 46 ark::es2panda::CompilerBugAction(position); \ 47 UNREACHABLE() 48 49 // CC-OFFNXT(G.PRE.06, G.PRE.09) solid logic 50 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 51 #define ES2PANDA_UNREACHABLE() ES2PANDA_UNREACHABLE_POS(GetPositionForDiagnostic()) 52 53 #else // NDEBUG 54 // CC-OFFNXT(G.PRE.06) solid logic 55 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 56 #define ES2PANDA_ASSERT_POS(cond, position) static_cast<void>(0) 57 // CC-OFFNXT(G.PRE.06) solid logic 58 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 59 #define ES2PANDA_ASSERT(cond) static_cast<void>(0) 60 // CC-OFFNXT(G.PRE.06) solid logic 61 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 62 #define ES2PANDA_UNREACHABLE_POS(position) __builtin_unreachable() 63 // CC-OFFNXT(G.PRE.06) solid logic 64 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 65 #define ES2PANDA_UNREACHABLE() __builtin_unreachable() 66 #endif 67 68 #endif // ES2PANDA_UTIL_ES2PANDA_MACROS_H 69