| ... | ... | @@ -12,6 +12,7 @@ |
| 12 | 12 | * 2. Provide a C interface to the Clang functions we need for self-hosting purposes. |
| 13 | 13 | * 3. Prevent C++ from infecting the rest of the project. |
| 14 | 14 | */ |
| 15 | #include "zig_clang.h" |
| 15 | 16 | |
| 16 | 17 | #if __GNUC__ >= 8 |
| 17 | 18 | #pragma GCC diagnostic push |
| ... | ... | @@ -26,14 +27,6 @@ |
| 26 | 27 | #pragma GCC diagnostic pop |
| 27 | 28 | #endif |
| 28 | 29 | |
| 29 | | // Before the #include of zig_clang.h |
| 30 | | // We'll check that the types are compatible but just use |
| 31 | | // the clang type. |
| 32 | | #define ZigClangSourceLocation clang::SourceLocation |
| 33 | | #define ZIG_CLANG_SOURCE_LOCATION ZigClangABISourceLocation |
| 34 | | |
| 35 | | #include "zig_clang.h" |
| 36 | | |
| 37 | 30 | // Detect additions to the enum |
| 38 | 31 | void zig2clang_BO(ZigClangBO op) { |
| 39 | 32 | switch (op) { |
| ... | ... | @@ -144,35 +137,47 @@ static_assert((clang::UnaryOperatorKind)ZigClangUO_PreDec == clang::UO_PreDec, " |
| 144 | 137 | static_assert((clang::UnaryOperatorKind)ZigClangUO_PreInc == clang::UO_PreInc, ""); |
| 145 | 138 | static_assert((clang::UnaryOperatorKind)ZigClangUO_Real == clang::UO_Real, ""); |
| 146 | 139 | |
| 147 | | static_assert(sizeof(ZigClangABISourceLocation) == sizeof(clang::SourceLocation)); |
| 140 | static_assert(sizeof(ZigClangSourceLocation) == sizeof(clang::SourceLocation), ""); |
| 148 | 141 | |
| 149 | | clang::SourceLocation ZigClangSourceManager_getSpellingLoc(const ZigClangSourceManager *self, |
| 150 | | clang::SourceLocation Loc) |
| 142 | static ZigClangSourceLocation bitcast(clang::SourceLocation src) { |
| 143 | ZigClangSourceLocation dest; |
| 144 | memcpy(&dest, &src, sizeof(ZigClangSourceLocation)); |
| 145 | return dest; |
| 146 | } |
| 147 | |
| 148 | static clang::SourceLocation bitcast(ZigClangSourceLocation src) { |
| 149 | clang::SourceLocation dest; |
| 150 | memcpy(&dest, &src, sizeof(ZigClangSourceLocation)); |
| 151 | return dest; |
| 152 | } |
| 153 | |
| 154 | ZigClangSourceLocation ZigClangSourceManager_getSpellingLoc(const ZigClangSourceManager *self, |
| 155 | ZigClangSourceLocation Loc) |
| 151 | 156 | { |
| 152 | | return reinterpret_cast<const clang::SourceManager *>(self)->getSpellingLoc(Loc); |
| 157 | return bitcast(reinterpret_cast<const clang::SourceManager *>(self)->getSpellingLoc(bitcast(Loc))); |
| 153 | 158 | } |
| 154 | 159 | |
| 155 | 160 | const char *ZigClangSourceManager_getFilename(const ZigClangSourceManager *self, |
| 156 | | clang::SourceLocation SpellingLoc) |
| 161 | ZigClangSourceLocation SpellingLoc) |
| 157 | 162 | { |
| 158 | | StringRef s = reinterpret_cast<const clang::SourceManager *>(self)->getFilename(SpellingLoc); |
| 163 | StringRef s = reinterpret_cast<const clang::SourceManager *>(self)->getFilename(bitcast(SpellingLoc)); |
| 159 | 164 | return (const char *)s.bytes_begin(); |
| 160 | 165 | } |
| 161 | 166 | |
| 162 | 167 | unsigned ZigClangSourceManager_getSpellingLineNumber(const ZigClangSourceManager *self, |
| 163 | 168 | ZigClangSourceLocation Loc) |
| 164 | 169 | { |
| 165 | | return reinterpret_cast<const clang::SourceManager *>(self)->getSpellingLineNumber(Loc); |
| 170 | return reinterpret_cast<const clang::SourceManager *>(self)->getSpellingLineNumber(bitcast(Loc)); |
| 166 | 171 | } |
| 167 | 172 | |
| 168 | 173 | unsigned ZigClangSourceManager_getSpellingColumnNumber(const ZigClangSourceManager *self, |
| 169 | 174 | ZigClangSourceLocation Loc) |
| 170 | 175 | { |
| 171 | | return reinterpret_cast<const clang::SourceManager *>(self)->getSpellingColumnNumber(Loc); |
| 176 | return reinterpret_cast<const clang::SourceManager *>(self)->getSpellingColumnNumber(bitcast(Loc)); |
| 172 | 177 | } |
| 173 | 178 | |
| 174 | 179 | const char* ZigClangSourceManager_getCharacterData(const ZigClangSourceManager *self, |
| 175 | 180 | ZigClangSourceLocation SL) |
| 176 | 181 | { |
| 177 | | return reinterpret_cast<const clang::SourceManager *>(self)->getCharacterData(SL); |
| 182 | return reinterpret_cast<const clang::SourceManager *>(self)->getCharacterData(bitcast(SL)); |
| 178 | 183 | } |