| author | |
| committer | |
| log | 2dfa76a1a754d2537b9cc6faf7b98461de0b1429 |
| tree | 409d9b7554b17b042aa15e4a462212677ef6d187 |
| parent | 356cfa08f49a9e92dfa4135cbcf2ddc079ddf228 |
3 files changed, 33 insertions(+), 32 deletions(-)
src/translate_c.cpp+10-10| ... | @@ -4,7 +4,6 @@ | ... | @@ -4,7 +4,6 @@ |
| 4 | * This file is part of zig, which is MIT licensed. | 4 | * This file is part of zig, which is MIT licensed. |
| 5 | * See http://opensource.org/licenses/MIT | 5 | * See http://opensource.org/licenses/MIT |
| 6 | */ | 6 | */ |
| 7 | |||
| 8 | #include "all_types.hpp" | 7 | #include "all_types.hpp" |
| 9 | #include "analyze.hpp" | 8 | #include "analyze.hpp" |
| 10 | #include "c_tokenizer.hpp" | 9 | #include "c_tokenizer.hpp" |
| ... | @@ -13,6 +12,7 @@ | ... | @@ -13,6 +12,7 @@ |
| 13 | #include "os.hpp" | 12 | #include "os.hpp" |
| 14 | #include "translate_c.hpp" | 13 | #include "translate_c.hpp" |
| 15 | #include "parser.hpp" | 14 | #include "parser.hpp" |
| 15 | #include "zig_clang.h" | ||
| 16 | 16 | ||
| 17 | #if __GNUC__ >= 8 | 17 | #if __GNUC__ >= 8 |
| 18 | #pragma GCC diagnostic push | 18 | #pragma GCC diagnostic push |
| ... | @@ -27,13 +27,6 @@ | ... | @@ -27,13 +27,6 @@ |
| 27 | #pragma GCC diagnostic pop | 27 | #pragma GCC diagnostic pop |
| 28 | #endif | 28 | #endif |
| 29 | 29 | ||
| 30 | |||
| 31 | // Before the #include of zig_clang.h | ||
| 32 | // Temporary transitional thing: override ZigClangSourceLocation with clang::SourceLocation | ||
| 33 | #define ZigClangSourceLocation clang::SourceLocation | ||
| 34 | #define ZIG_CLANG_SOURCE_LOCATION ZigClangABISourceLocation | ||
| 35 | #include "zig_clang.h" | ||
| 36 | |||
| 37 | #include <string.h> | 30 | #include <string.h> |
| 38 | 31 | ||
| 39 | struct Alias { | 32 | struct Alias { |
| ... | @@ -134,8 +127,14 @@ static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope | ... | @@ -134,8 +127,14 @@ static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope |
| 134 | static AstNode *trans_qual_type(Context *c, clang::QualType qt, const clang::SourceLocation &source_loc); | 127 | static AstNode *trans_qual_type(Context *c, clang::QualType qt, const clang::SourceLocation &source_loc); |
| 135 | static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr, TransLRValue lrval); | 128 | static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr, TransLRValue lrval); |
| 136 | 129 | ||
| 130 | static ZigClangSourceLocation bitcast(clang::SourceLocation src) { | ||
| 131 | ZigClangSourceLocation dest; | ||
| 132 | memcpy(&dest, &src, sizeof(ZigClangSourceLocation)); | ||
| 133 | return dest; | ||
| 134 | } | ||
| 135 | |||
| 137 | ATTRIBUTE_PRINTF(3, 4) | 136 | ATTRIBUTE_PRINTF(3, 4) |
| 138 | static void emit_warning(Context *c, const clang::SourceLocation &sl, const char *format, ...) { | 137 | static void emit_warning(Context *c, const clang::SourceLocation &clang_sl, const char *format, ...) { |
| 139 | if (!c->warnings_on) { | 138 | if (!c->warnings_on) { |
| 140 | return; | 139 | return; |
| 141 | } | 140 | } |
| ... | @@ -145,6 +144,7 @@ static void emit_warning(Context *c, const clang::SourceLocation &sl, const char | ... | @@ -145,6 +144,7 @@ static void emit_warning(Context *c, const clang::SourceLocation &sl, const char |
| 145 | Buf *msg = buf_vprintf(format, ap); | 144 | Buf *msg = buf_vprintf(format, ap); |
| 146 | va_end(ap); | 145 | va_end(ap); |
| 147 | 146 | ||
| 147 | ZigClangSourceLocation sl = bitcast(clang_sl); | ||
| 148 | const char *filename_bytes = ZigClangSourceManager_getFilename(c->source_manager, | 148 | const char *filename_bytes = ZigClangSourceManager_getFilename(c->source_manager, |
| 149 | ZigClangSourceManager_getSpellingLoc(c->source_manager, sl)); | 149 | ZigClangSourceManager_getSpellingLoc(c->source_manager, sl)); |
| 150 | Buf *path; | 150 | Buf *path; |
| ... | @@ -4707,7 +4707,7 @@ static void process_preprocessor_entities(Context *c, clang::ASTUnit &unit) { | ... | @@ -4707,7 +4707,7 @@ static void process_preprocessor_entities(Context *c, clang::ASTUnit &unit) { |
| 4707 | continue; | 4707 | continue; |
| 4708 | } | 4708 | } |
| 4709 | 4709 | ||
| 4710 | const char *begin_c = ZigClangSourceManager_getCharacterData(c->source_manager, begin_loc); | 4710 | const char *begin_c = ZigClangSourceManager_getCharacterData(c->source_manager, bitcast(begin_loc)); |
| 4711 | process_macro(c, &ctok, name, begin_c); | 4711 | process_macro(c, &ctok, name, begin_c); |
| 4712 | } | 4712 | } |
| 4713 | } | 4713 | } |
src/zig_clang.cpp+22-17| ... | @@ -12,6 +12,7 @@ | ... | @@ -12,6 +12,7 @@ |
| 12 | * 2. Provide a C interface to the Clang functions we need for self-hosting purposes. | 12 | * 2. Provide a C interface to the Clang functions we need for self-hosting purposes. |
| 13 | * 3. Prevent C++ from infecting the rest of the project. | 13 | * 3. Prevent C++ from infecting the rest of the project. |
| 14 | */ | 14 | */ |
| 15 | #include "zig_clang.h" | ||
| 15 | 16 | ||
| 16 | #if __GNUC__ >= 8 | 17 | #if __GNUC__ >= 8 |
| 17 | #pragma GCC diagnostic push | 18 | #pragma GCC diagnostic push |
| ... | @@ -26,14 +27,6 @@ | ... | @@ -26,14 +27,6 @@ |
| 26 | #pragma GCC diagnostic pop | 27 | #pragma GCC diagnostic pop |
| 27 | #endif | 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 | // Detect additions to the enum | 30 | // Detect additions to the enum |
| 38 | void zig2clang_BO(ZigClangBO op) { | 31 | void zig2clang_BO(ZigClangBO op) { |
| 39 | switch (op) { | 32 | switch (op) { |
| ... | @@ -144,35 +137,47 @@ static_assert((clang::UnaryOperatorKind)ZigClangUO_PreDec == clang::UO_PreDec, " | ... | @@ -144,35 +137,47 @@ static_assert((clang::UnaryOperatorKind)ZigClangUO_PreDec == clang::UO_PreDec, " |
| 144 | static_assert((clang::UnaryOperatorKind)ZigClangUO_PreInc == clang::UO_PreInc, ""); | 137 | static_assert((clang::UnaryOperatorKind)ZigClangUO_PreInc == clang::UO_PreInc, ""); |
| 145 | static_assert((clang::UnaryOperatorKind)ZigClangUO_Real == clang::UO_Real, ""); | 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, | 142 | static ZigClangSourceLocation bitcast(clang::SourceLocation src) { |
| 150 | clang::SourceLocation Loc) | 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 | const char *ZigClangSourceManager_getFilename(const ZigClangSourceManager *self, | 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 | return (const char *)s.bytes_begin(); | 164 | return (const char *)s.bytes_begin(); |
| 160 | } | 165 | } |
| 161 | 166 | ||
| 162 | unsigned ZigClangSourceManager_getSpellingLineNumber(const ZigClangSourceManager *self, | 167 | unsigned ZigClangSourceManager_getSpellingLineNumber(const ZigClangSourceManager *self, |
| 163 | ZigClangSourceLocation Loc) | 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 | unsigned ZigClangSourceManager_getSpellingColumnNumber(const ZigClangSourceManager *self, | 173 | unsigned ZigClangSourceManager_getSpellingColumnNumber(const ZigClangSourceManager *self, |
| 169 | ZigClangSourceLocation Loc) | 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 | const char* ZigClangSourceManager_getCharacterData(const ZigClangSourceManager *self, | 179 | const char* ZigClangSourceManager_getCharacterData(const ZigClangSourceManager *self, |
| 175 | ZigClangSourceLocation SL) | 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 | } |
src/zig_clang.h+1-5| ... | @@ -17,11 +17,7 @@ | ... | @@ -17,11 +17,7 @@ |
| 17 | // ATTENTION: If you modify this file, be sure to update the corresponding | 17 | // ATTENTION: If you modify this file, be sure to update the corresponding |
| 18 | // extern function declarations in the self-hosted compiler. | 18 | // extern function declarations in the self-hosted compiler. |
| 19 | 19 | ||
| 20 | #ifndef ZIG_CLANG_SOURCE_LOCATION | 20 | struct ZigClangSourceLocation { |
| 21 | #define ZIG_CLANG_SOURCE_LOCATION ZigClangSourceLocation | ||
| 22 | #endif | ||
| 23 | |||
| 24 | struct ZIG_CLANG_SOURCE_LOCATION { | ||
| 25 | unsigned ID; | 21 | unsigned ID; |
| 26 | }; | 22 | }; |
| 27 | 23 |