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 @@...@@ -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/MIT5 * 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"
1616
17#if __GNUC__ >= 817#if __GNUC__ >= 8
18#pragma GCC diagnostic push18#pragma GCC diagnostic push
...@@ -27,13 +27,6 @@...@@ -27,13 +27,6 @@
27#pragma GCC diagnostic pop27#pragma GCC diagnostic pop
28#endif28#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
37#include <string.h>30#include <string.h>
3831
39struct Alias {32struct 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
134static AstNode *trans_qual_type(Context *c, clang::QualType qt, const clang::SourceLocation &source_loc);127static AstNode *trans_qual_type(Context *c, clang::QualType qt, const clang::SourceLocation &source_loc);
135static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr, TransLRValue lrval);128static 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
137ATTRIBUTE_PRINTF(3, 4)136ATTRIBUTE_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, ...) {
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);
147146
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 }
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));
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"
1516
16#if __GNUC__ >= 817#if __GNUC__ >= 8
17#pragma GCC diagnostic push18#pragma GCC diagnostic push
...@@ -26,14 +27,6 @@...@@ -26,14 +27,6 @@
26#pragma GCC diagnostic pop27#pragma GCC diagnostic pop
27#endif28#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
37// Detect additions to the enum30// Detect additions to the enum
38void zig2clang_BO(ZigClangBO op) {31void 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, "
144static_assert((clang::UnaryOperatorKind)ZigClangUO_PreInc == clang::UO_PreInc, "");137static_assert((clang::UnaryOperatorKind)ZigClangUO_PreInc == clang::UO_PreInc, "");
145static_assert((clang::UnaryOperatorKind)ZigClangUO_Real == clang::UO_Real, "");138static_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,142static ZigClangSourceLocation bitcast(clang::SourceLocation src) {
150 clang::SourceLocation Loc)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)
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}
154159
155const char *ZigClangSourceManager_getFilename(const ZigClangSourceManager *self,160const 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}
161166
162unsigned ZigClangSourceManager_getSpellingLineNumber(const ZigClangSourceManager *self,167unsigned 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}
167172
168unsigned ZigClangSourceManager_getSpellingColumnNumber(const ZigClangSourceManager *self,173unsigned 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}
173178
174const char* ZigClangSourceManager_getCharacterData(const ZigClangSourceManager *self,179const 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 corresponding17// 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.
1919
20#ifndef ZIG_CLANG_SOURCE_LOCATION20struct ZigClangSourceLocation {
21#define ZIG_CLANG_SOURCE_LOCATION ZigClangSourceLocation
22#endif
23
24struct ZIG_CLANG_SOURCE_LOCATION {
25 unsigned ID;21 unsigned ID;
26};22};
2723