| ... | ... | @@ -90,7 +90,7 @@ struct Context { |
| 90 | 90 | bool warnings_on; |
| 91 | 91 | |
| 92 | 92 | CodeGen *codegen; |
| 93 | | clang::ASTContext *ctx; |
| 93 | ZigClangASTContext *ctx; |
| 94 | 94 | |
| 95 | 95 | TransScopeRoot *global_scope; |
| 96 | 96 | HashMap<Buf *, bool, buf_hash, buf_eql_buf> ptr_params; |
| ... | ... | @@ -132,6 +132,16 @@ static ZigClangSourceLocation bitcast(clang::SourceLocation src) { |
| 132 | 132 | memcpy(&dest, &src, sizeof(ZigClangSourceLocation)); |
| 133 | 133 | return dest; |
| 134 | 134 | } |
| 135 | static ZigClangQualType bitcast(clang::QualType src) { |
| 136 | ZigClangQualType dest; |
| 137 | memcpy(&dest, &src, sizeof(ZigClangQualType)); |
| 138 | return dest; |
| 139 | } |
| 140 | static clang::QualType bitcast(ZigClangQualType src) { |
| 141 | clang::QualType dest; |
| 142 | memcpy(&dest, &src, sizeof(ZigClangQualType)); |
| 143 | return dest; |
| 144 | } |
| 135 | 145 | |
| 136 | 146 | ATTRIBUTE_PRINTF(3, 4) |
| 137 | 147 | static void emit_warning(Context *c, const clang::SourceLocation &clang_sl, const char *format, ...) { |
| ... | ... | @@ -509,7 +519,7 @@ static clang::QualType get_expr_qual_type(Context *c, const clang::Expr *expr) { |
| 509 | 519 | const clang::ArrayType *array_type = static_cast<const clang::ArrayType *>(array_qt.getTypePtr()); |
| 510 | 520 | clang::QualType pointee_qt = array_type->getElementType(); |
| 511 | 521 | pointee_qt.addConst(); |
| 512 | | return c->ctx->getPointerType(pointee_qt); |
| 522 | return bitcast(ZigClangASTContext_getPointerType(c->ctx, bitcast(pointee_qt))); |
| 513 | 523 | } |
| 514 | 524 | } |
| 515 | 525 | } |
| ... | ... | @@ -1221,7 +1231,7 @@ static AstNode *trans_return_stmt(Context *c, TransScope *scope, const clang::Re |
| 1221 | 1231 | |
| 1222 | 1232 | static AstNode *trans_integer_literal(Context *c, const clang::IntegerLiteral *stmt) { |
| 1223 | 1233 | llvm::APSInt result; |
| 1224 | | if (!stmt->EvaluateAsInt(result, *c->ctx)) { |
| 1234 | if (!stmt->EvaluateAsInt(result, *reinterpret_cast<clang::ASTContext *>(c->ctx))) { |
| 1225 | 1235 | emit_warning(c, stmt->getLocStart(), "invalid integer literal"); |
| 1226 | 1236 | return nullptr; |
| 1227 | 1237 | } |
| ... | ... | @@ -4240,7 +4250,8 @@ static void visit_var_decl(Context *c, const clang::VarDecl *var_decl) { |
| 4240 | 4250 | return; |
| 4241 | 4251 | } |
| 4242 | 4252 | |
| 4243 | | static bool decl_visitor(void *context, const clang::Decl *decl) { |
| 4253 | static bool decl_visitor(void *context, const ZigClangDecl *zdecl) { |
| 4254 | const clang::Decl *decl = reinterpret_cast<const clang::Decl *>(zdecl); |
| 4244 | 4255 | Context *c = (Context*)context; |
| 4245 | 4256 | |
| 4246 | 4257 | switch (decl->getKind()) { |
| ... | ... | @@ -4678,12 +4689,13 @@ static void process_macro(Context *c, CTokenize *ctok, Buf *name, const char *ch |
| 4678 | 4689 | c->macro_table.put(name, result_node); |
| 4679 | 4690 | } |
| 4680 | 4691 | |
| 4681 | | static void process_preprocessor_entities(Context *c, clang::ASTUnit &unit) { |
| 4692 | static void process_preprocessor_entities(Context *c, ZigClangASTUnit *zunit) { |
| 4693 | clang::ASTUnit *unit = reinterpret_cast<clang::ASTUnit *>(zunit); |
| 4682 | 4694 | CTokenize ctok = {{0}}; |
| 4683 | 4695 | |
| 4684 | 4696 | // TODO if we see #undef, delete it from the table |
| 4685 | 4697 | |
| 4686 | | for (clang::PreprocessedEntity *entity : unit.getLocalPreprocessingEntities()) { |
| 4698 | for (clang::PreprocessedEntity *entity : unit->getLocalPreprocessingEntities()) { |
| 4687 | 4699 | switch (entity->getKind()) { |
| 4688 | 4700 | case clang::PreprocessedEntity::InvalidKind: |
| 4689 | 4701 | case clang::PreprocessedEntity::InclusionDirectiveKind: |
| ... | ... | @@ -4832,7 +4844,7 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const |
| 4832 | 4844 | bool for_serialization = false; |
| 4833 | 4845 | const char *resources_path = buf_ptr(codegen->zig_c_headers_dir); |
| 4834 | 4846 | std::unique_ptr<clang::ASTUnit> err_unit; |
| 4835 | | std::unique_ptr<clang::ASTUnit> ast_unit(clang::ASTUnit::LoadFromCommandLine( |
| 4847 | ZigClangASTUnit *ast_unit = reinterpret_cast<ZigClangASTUnit *>(clang::ASTUnit::LoadFromCommandLine( |
| 4836 | 4848 | &clang_argv.at(0), &clang_argv.last(), |
| 4837 | 4849 | pch_container_ops, diags, resources_path, |
| 4838 | 4850 | only_local_decls, capture_diagnostics, clang::None, true, 0, clang::TU_Complete, |
| ... | ... | @@ -4847,7 +4859,7 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const |
| 4847 | 4859 | |
| 4848 | 4860 | if (diags->getClient()->getNumErrors() > 0) { |
| 4849 | 4861 | if (ast_unit) { |
| 4850 | | err_unit = std::move(ast_unit); |
| 4862 | err_unit = std::unique_ptr<clang::ASTUnit>(reinterpret_cast<clang::ASTUnit *>(ast_unit)); |
| 4851 | 4863 | } |
| 4852 | 4864 | |
| 4853 | 4865 | for (clang::ASTUnit::stored_diag_iterator it = err_unit->stored_diag_begin(), |
| ... | ... | @@ -4894,14 +4906,14 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const |
| 4894 | 4906 | return ErrorCCompileErrors; |
| 4895 | 4907 | } |
| 4896 | 4908 | |
| 4897 | | c->ctx = &ast_unit->getASTContext(); |
| 4898 | | c->source_manager = reinterpret_cast<ZigClangSourceManager *>(&ast_unit->getSourceManager()); |
| 4909 | c->ctx = ZigClangASTUnit_getASTContext(ast_unit); |
| 4910 | c->source_manager = ZigClangASTUnit_getSourceManager(ast_unit); |
| 4899 | 4911 | c->root = trans_create_node(c, NodeTypeContainerDecl); |
| 4900 | 4912 | c->root->data.container_decl.is_root = true; |
| 4901 | 4913 | |
| 4902 | | ast_unit->visitLocalTopLevelDecls(c, decl_visitor); |
| 4914 | ZigClangASTUnit_visitLocalTopLevelDecls(ast_unit, c, decl_visitor); |
| 4903 | 4915 | |
| 4904 | | process_preprocessor_entities(c, *ast_unit); |
| 4916 | process_preprocessor_entities(c, ast_unit); |
| 4905 | 4917 | |
| 4906 | 4918 | render_macros(c); |
| 4907 | 4919 | render_aliases(c); |