|
| 1 | +//===--- Errors.h - Demangling library error handling -----------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2022 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +// |
| 13 | +// This file exists because not every client links to libswiftCore (the |
| 14 | +// runtime), so calling swift::fatalError() or swift::warning() from within |
| 15 | +// the demangler is not an option. |
| 16 | +// |
| 17 | +//===----------------------------------------------------------------------===// |
| 18 | + |
| 19 | +#ifndef SWIFT_DEMANGLING_ERRORS_H |
| 20 | +#define SWIFT_DEMANGLING_ERRORS_H |
| 21 | + |
| 22 | +#include "../../../stdlib/public/SwiftShims/Visibility.h" |
| 23 | +#include "swift/Demangling/NamespaceMacros.h" |
| 24 | +#include <inttypes.h> |
| 25 | +#include <stdarg.h> |
| 26 | + |
| 27 | +#ifndef SWIFT_FORMAT |
| 28 | +// SWIFT_FORMAT(fmt,first) marks a function as taking a format string argument |
| 29 | +// at argument `fmt`, with the first argument for the format string as `first`. |
| 30 | +#if __has_attribute(format) |
| 31 | +#define SWIFT_FORMAT(fmt, first) __attribute__((format(printf, fmt, first))) |
| 32 | +#else |
| 33 | +#define SWIFT_FORMAT(fmt, first) |
| 34 | +#endif |
| 35 | +#endif |
| 36 | + |
| 37 | +#ifndef SWIFT_VFORMAT |
| 38 | +// SWIFT_VFORMAT(fmt) marks a function as taking a format string argument at |
| 39 | +// argument `fmt`, with the arguments in a `va_list`. |
| 40 | +#if __has_attribute(format) |
| 41 | +#define SWIFT_VFORMAT(fmt) __attribute__((format(printf, fmt, 0))) |
| 42 | +#else |
| 43 | +#define SWIFT_VFORMAT(fmt) |
| 44 | +#endif |
| 45 | +#endif |
| 46 | + |
| 47 | +namespace swift { |
| 48 | +namespace Demangle { |
| 49 | +SWIFT_BEGIN_INLINE_NAMESPACE |
| 50 | + |
| 51 | +SWIFT_NORETURN SWIFT_FORMAT(2, 3) void fatal(uint32_t flags, const char *format, |
| 52 | + ...); |
| 53 | +SWIFT_FORMAT(2, 3) void warn(uint32_t flags, const char *format, ...); |
| 54 | + |
| 55 | +SWIFT_NORETURN SWIFT_VFORMAT(2) void fatalv(uint32_t flags, const char *format, |
| 56 | + va_list val); |
| 57 | +SWIFT_VFORMAT(2) void warnv(uint32_t flags, const char *format, va_list val); |
| 58 | + |
| 59 | +SWIFT_END_INLINE_NAMESPACE |
| 60 | +} // end namespace Demangle |
| 61 | +} // end namespace swift |
| 62 | + |
| 63 | +#endif // SWIFT_DEMANGLING_DEMANGLE_H |
0 commit comments