Files
swift-mirror/lib/Demangling/DemanglerAssert.h
Alastair Houghton b8a879954a [Demangler] Tidy up a bit, and add line numbers to ManglingErrors.
Because DEMANGLER_ASSERT() might cause the remanglers to return a ManglingError
with the code ManglingError::AssertionFailed, it's useful to have a line number
in the ManglingError as well as the other information.  This is also potentially
helpful for other cases where the code is used multiple times in the remanglers.

rdar://79725187
2021-09-06 17:49:55 +01:00

32 lines
1.3 KiB
C

//===--- DemanglerAssert.h - Assertions for de/re-mangling ----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file implements a macro, DEMANGLE_ASSERT(), which will assert in the
// compiler, but in the runtime will return a ManglingError on failure.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_DEMANGLING_ASSERT_H
#define SWIFT_DEMANGLING_ASSERT_H
#if SWIFT_RUNTIME
#define DEMANGLER_ASSERT(expr, node) \
do { \
if (!(expr)) \
return ManglingError(ManglingError::AssertionFailed, (node), __LINE__); \
} while (0)
#else
#define DEMANGLER_ASSERT(expr, node) assert(expr)
#endif
#endif // SWIFT_DEMANGLING_ASSERT_H