|
| 1 | +//===--- MagicIdentifierKinds.def - Swift #ident metaprogramming -*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2020 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 defines macros used for macro-metaprogramming with magic |
| 14 | +// identifier literals. |
| 15 | +// |
| 16 | +//===----------------------------------------------------------------------===// |
| 17 | + |
| 18 | +// Used for any magic identifier. |
| 19 | +#ifndef MAGIC_IDENTIFIER |
| 20 | +#define MAGIC_IDENTIFIER(NAME, STRING, SYNTAX_KIND) |
| 21 | +#endif |
| 22 | + |
| 23 | +// Used for magic identifiers which produce string literals. |
| 24 | +#ifndef MAGIC_STRING_IDENTIFIER |
| 25 | +#define MAGIC_STRING_IDENTIFIER(NAME, STRING, SYNTAX_KIND) MAGIC_IDENTIFIER(NAME, STRING, SYNTAX_KIND) |
| 26 | +#endif |
| 27 | + |
| 28 | +// Used for magic identifiers which produce integer literals. |
| 29 | +#ifndef MAGIC_INT_IDENTIFIER |
| 30 | +#define MAGIC_INT_IDENTIFIER(NAME, STRING, SYNTAX_KIND) MAGIC_IDENTIFIER(NAME, STRING, SYNTAX_KIND) |
| 31 | +#endif |
| 32 | + |
| 33 | +// Used for magic identifiers which produce raw pointers. |
| 34 | +#ifndef MAGIC_POINTER_IDENTIFIER |
| 35 | +#define MAGIC_POINTER_IDENTIFIER(NAME, STRING, SYNTAX_KIND) MAGIC_IDENTIFIER(NAME, STRING, SYNTAX_KIND) |
| 36 | +#endif |
| 37 | + |
| 38 | +// Used when a given token always maps to a particular magic identifier kind. |
| 39 | +#ifndef MAGIC_IDENTIFIER_TOKEN |
| 40 | +#define MAGIC_IDENTIFIER_TOKEN(NAME, TOKEN) |
| 41 | +#endif |
| 42 | + |
| 43 | +// Used when a given token always maps to a particular magic identifier kind, |
| 44 | +// but that token is deprecated. |
| 45 | +#ifndef MAGIC_IDENTIFIER_DEPRECATED_TOKEN |
| 46 | +#define MAGIC_IDENTIFIER_DEPRECATED_TOKEN(NAME, TOKEN) MAGIC_IDENTIFIER_TOKEN(NAME, TOKEN) |
| 47 | +#endif |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +// |
| 52 | +// Magic string literals |
| 53 | +// |
| 54 | + |
| 55 | +/// The \c #fileID magic identifier literal. |
| 56 | +MAGIC_STRING_IDENTIFIER(FileID, "#fileID", PoundFileIDExpr) |
| 57 | + MAGIC_IDENTIFIER_TOKEN(FileID, pound_fileID) |
| 58 | + |
| 59 | +/// The \c #file magic identifier literal, written in code where it is |
| 60 | +/// a synonym for \c #fileID (i.e. "Swift 6 mode" code). |
| 61 | +MAGIC_STRING_IDENTIFIER(FileIDSpelledAsFile, "#file", PoundFileExpr) |
| 62 | + // tok::pound_file is shared with FilePathSpelledAsFile; please write custom |
| 63 | + // code paths for it. |
| 64 | + |
| 65 | +/// The \c #filePath magic identifier literal. |
| 66 | +MAGIC_STRING_IDENTIFIER(FilePath, "#filePath", PoundFilePathExpr) |
| 67 | + MAGIC_IDENTIFIER_TOKEN(FilePath, pound_filePath) |
| 68 | + |
| 69 | +/// The \c #file magic identifier literal, written in code where it is |
| 70 | +/// a synonym for \c #filePath (i.e. Swift 5 mode code). |
| 71 | +MAGIC_STRING_IDENTIFIER(FilePathSpelledAsFile, "#file", PoundFileExpr) |
| 72 | + // tok::pound_file is shared with FileIDSpelledAsFile; please write custom |
| 73 | + // code paths for it. |
| 74 | + MAGIC_IDENTIFIER_DEPRECATED_TOKEN(FilePathSpelledAsFile, kw___FILE__) |
| 75 | + |
| 76 | +/// The \c #function magic identifier literal. |
| 77 | +MAGIC_STRING_IDENTIFIER(Function, "#function", PoundFunctionExpr) |
| 78 | + MAGIC_IDENTIFIER_TOKEN(Function, pound_function) |
| 79 | + MAGIC_IDENTIFIER_DEPRECATED_TOKEN(Function, kw___FUNCTION__) |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +// |
| 84 | +// Magic integer literals |
| 85 | +// |
| 86 | + |
| 87 | +/// The \c #line magic identifier literal. |
| 88 | +MAGIC_INT_IDENTIFIER(Line, "#line", PoundLineExpr) |
| 89 | + MAGIC_IDENTIFIER_TOKEN(Line, pound_line) |
| 90 | + MAGIC_IDENTIFIER_DEPRECATED_TOKEN(Line, kw___LINE__) |
| 91 | + |
| 92 | +/// The \c #column magic identifier literal. |
| 93 | +MAGIC_INT_IDENTIFIER(Column, "#column", PoundColumnExpr) |
| 94 | + MAGIC_IDENTIFIER_TOKEN(Column, pound_column) |
| 95 | + MAGIC_IDENTIFIER_DEPRECATED_TOKEN(Column, kw___COLUMN__) |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +// |
| 100 | +// Magic raw pointer literals |
| 101 | +// |
| 102 | + |
| 103 | +/// The \c #dsohandle magic identifier literal. |
| 104 | +MAGIC_POINTER_IDENTIFIER(DSOHandle, "#dsohandle", PoundDsohandleExpr) |
| 105 | + MAGIC_IDENTIFIER_TOKEN(DSOHandle, pound_dsohandle) |
| 106 | + MAGIC_IDENTIFIER_DEPRECATED_TOKEN(DSOHandle, kw___DSO_HANDLE__) |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +#undef MAGIC_IDENTIFIER |
| 112 | +#undef MAGIC_STRING_IDENTIFIER |
| 113 | +#undef MAGIC_INT_IDENTIFIER |
| 114 | +#undef MAGIC_POINTER_IDENTIFIER |
| 115 | +#undef MAGIC_IDENTIFIER_TOKEN |
| 116 | +#undef MAGIC_IDENTIFIER_DEPRECATED_TOKEN |
0 commit comments