authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-16 16:17:30-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-16 16:17:30-05:00
log2dfa76a1a754d2537b9cc6faf7b98461de0b1429
tree409d9b7554b17b042aa15e4a462212677ef6d187
parent356cfa08f49a9e92dfa4135cbcf2ddc079ddf228

fix regressions from previous commit when building with clang


3 files changed, 33 insertions(+), 32 deletions(-)

src/translate_c.cpp+10-10
......@@ -4,7 +4,6 @@
44 * This file is part of zig, which is MIT licensed.
55 * See http://opensource.org/licenses/MIT
66 */
7
87#include "all_types.hpp"
98#include "analyze.hpp"
109#include "c_tokenizer.hpp"
......@@ -13,6 +12,7 @@
1312#include "os.hpp"
1413#include "translate_c.hpp"
1514#include "parser.hpp"
15#include "zig_clang.h"
1616
1717#if __GNUC__ >= 8
1818#pragma GCC diagnostic push
......@@ -27,13 +27,6 @@
2727#pragma GCC diagnostic pop
2828#endif
2929
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
3730#include <string.h>
3831
3932struct Alias {
......@@ -134,8 +127,14 @@ static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope
134127static AstNode *trans_qual_type(Context *c, clang::QualType qt, const clang::SourceLocation &source_loc);
135128static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr, TransLRValue lrval);
136129
130static ZigClangSourceLocation bitcast(clang::SourceLocation src) {
131 ZigClangSourceLocation dest;
132 memcpy(&dest, &src, sizeof(ZigClangSourceLocation));
133 return dest;
134}
135
137136ATTRIBUTE_PRINTF(3, 4)
138static void emit_warning(Context *c, const clang::SourceLocation &sl, const char *format, ...) {
137static void emit_warning(Context *c, const clang::SourceLocation &clang_sl, const char *format, ...) {
139138 if (!c->warnings_on) {
140139 return;
141140 }
......@@ -145,6 +144,7 @@ static void emit_warning(Context *c, const clang::SourceLocation &sl, const char
145144 Buf *msg = buf_vprintf(format, ap);
146145 va_end(ap);
147146
147 ZigClangSourceLocation sl = bitcast(clang_sl);
148148 const char *filename_bytes = ZigClangSourceManager_getFilename(c->source_manager,
149149 ZigClangSourceManager_getSpellingLoc(c->source_manager, sl));
150150 Buf *path;
......@@ -4707,7 +4707,7 @@ static void process_preprocessor_entities(Context *c, clang::ASTUnit &unit) {
47074707 continue;
47084708 }
47094709
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));
47114711 process_macro(c, &ctok, name, begin_c);
47124712 }
47134713 }
src/zig_clang.cpp+22-17
......@@ -12,6 +12,7 @@
1212 * 2. Provide a C interface to the Clang functions we need for self-hosting purposes.
1313 * 3. Prevent C++ from infecting the rest of the project.
1414 */
15#include "zig_clang.h"
1516
1617#if __GNUC__ >= 8
1718#pragma GCC diagnostic push
......@@ -26,14 +27,6 @@
2627#pragma GCC diagnostic pop
2728#endif
2829
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
3730// Detect additions to the enum
3831void zig2clang_BO(ZigClangBO op) {
3932 switch (op) {
......@@ -144,35 +137,47 @@ static_assert((clang::UnaryOperatorKind)ZigClangUO_PreDec == clang::UO_PreDec, "
144137static_assert((clang::UnaryOperatorKind)ZigClangUO_PreInc == clang::UO_PreInc, "");
145138static_assert((clang::UnaryOperatorKind)ZigClangUO_Real == clang::UO_Real, "");
146139
147static_assert(sizeof(ZigClangABISourceLocation) == sizeof(clang::SourceLocation));
140static_assert(sizeof(ZigClangSourceLocation) == sizeof(clang::SourceLocation), "");
148141
149clang::SourceLocation ZigClangSourceManager_getSpellingLoc(const ZigClangSourceManager *self,
150 clang::SourceLocation Loc)
142static ZigClangSourceLocation bitcast(clang::SourceLocation src) {
143 ZigClangSourceLocation dest;
144 memcpy(&dest, &src, sizeof(ZigClangSourceLocation));
145 return dest;
146}
147
148static clang::SourceLocation bitcast(ZigClangSourceLocation src) {
149 clang::SourceLocation dest;
150 memcpy(&dest, &src, sizeof(ZigClangSourceLocation));
151 return dest;
152}
153
154ZigClangSourceLocation ZigClangSourceManager_getSpellingLoc(const ZigClangSourceManager *self,
155 ZigClangSourceLocation Loc)
151156{
152 return reinterpret_cast<const clang::SourceManager *>(self)->getSpellingLoc(Loc);
157 return bitcast(reinterpret_cast<const clang::SourceManager *>(self)->getSpellingLoc(bitcast(Loc)));
153158}
154159
155160const char *ZigClangSourceManager_getFilename(const ZigClangSourceManager *self,
156 clang::SourceLocation SpellingLoc)
161 ZigClangSourceLocation SpellingLoc)
157162{
158 StringRef s = reinterpret_cast<const clang::SourceManager *>(self)->getFilename(SpellingLoc);
163 StringRef s = reinterpret_cast<const clang::SourceManager *>(self)->getFilename(bitcast(SpellingLoc));
159164 return (const char *)s.bytes_begin();
160165}
161166
162167unsigned ZigClangSourceManager_getSpellingLineNumber(const ZigClangSourceManager *self,
163168 ZigClangSourceLocation Loc)
164169{
165 return reinterpret_cast<const clang::SourceManager *>(self)->getSpellingLineNumber(Loc);
170 return reinterpret_cast<const clang::SourceManager *>(self)->getSpellingLineNumber(bitcast(Loc));
166171}
167172
168173unsigned ZigClangSourceManager_getSpellingColumnNumber(const ZigClangSourceManager *self,
169174 ZigClangSourceLocation Loc)
170175{
171 return reinterpret_cast<const clang::SourceManager *>(self)->getSpellingColumnNumber(Loc);
176 return reinterpret_cast<const clang::SourceManager *>(self)->getSpellingColumnNumber(bitcast(Loc));
172177}
173178
174179const char* ZigClangSourceManager_getCharacterData(const ZigClangSourceManager *self,
175180 ZigClangSourceLocation SL)
176181{
177 return reinterpret_cast<const clang::SourceManager *>(self)->getCharacterData(SL);
182 return reinterpret_cast<const clang::SourceManager *>(self)->getCharacterData(bitcast(SL));
178183}
src/zig_clang.h+1-5
......@@ -17,11 +17,7 @@
1717// ATTENTION: If you modify this file, be sure to update the corresponding
1818// extern function declarations in the self-hosted compiler.
1919
20#ifndef ZIG_CLANG_SOURCE_LOCATION
21#define ZIG_CLANG_SOURCE_LOCATION ZigClangSourceLocation
22#endif
23
24struct ZIG_CLANG_SOURCE_LOCATION {
20struct ZigClangSourceLocation {
2521 unsigned ID;
2622};
2723