remove concept of translate mode

master
Vexu 2019-12-12 14:26:24 +02:00
parent d08dc21116
commit 69dee57d95
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
8 changed files with 15 additions and 54 deletions

View File

@ -33,12 +33,6 @@ export fn stage2_panic(ptr: [*]const u8, len: usize) void {
@panic(ptr[0..len]);
}
// ABI warning
const TranslateMode = extern enum {
import,
translate,
};
// ABI warning
const Error = extern enum {
None,
@ -99,14 +93,10 @@ export fn stage2_translate_c(
out_errors_len: *usize,
args_begin: [*]?[*]const u8,
args_end: [*]?[*]const u8,
mode: TranslateMode,
resources_path: [*]const u8,
) Error {
var errors: []translate_c.ClangErrMsg = undefined;
out_ast.* = translate_c.translate(std.heap.c_allocator, args_begin, args_end, switch (mode) {
.import => translate_c.Mode.import,
.translate => translate_c.Mode.translate,
}, &errors, resources_path) catch |err| switch (err) {
out_ast.* = translate_c.translate(std.heap.c_allocator, args_begin, args_end, &errors, resources_path) catch |err| switch (err) {
error.SemanticAnalyzeFail => {
out_errors_ptr.* = errors.ptr;
out_errors_len.* = errors.len;

View File

@ -7,11 +7,6 @@ const ast = std.zig.ast;
const Token = std.zig.Token;
usingnamespace @import("clang.zig");
pub const Mode = enum {
import,
translate,
};
const CallingConvention = std.builtin.TypeInfo.CallingConvention;
pub const ClangErrMsg = Stage2ErrorMsg;
@ -104,7 +99,6 @@ const Context = struct {
source_manager: *ZigClangSourceManager,
decl_table: DeclTable,
global_scope: *Scope.Root,
mode: Mode,
ptr_params: std.BufSet,
clang_context: *ZigClangASTContext,
@ -133,7 +127,6 @@ pub fn translate(
backing_allocator: *std.mem.Allocator,
args_begin: [*]?[*]const u8,
args_end: [*]?[*]const u8,
mode: Mode,
errors: *[]ClangErrMsg,
resources_path: [*]const u8,
) !*ast.Tree {
@ -185,7 +178,6 @@ pub fn translate(
.err = undefined,
.decl_table = DeclTable.init(arena),
.global_scope = try arena.create(Scope.Root),
.mode = mode,
.ptr_params = std.BufSet.init(arena),
.clang_context = ZigClangASTUnit_getASTContext(ast_unit).?,
};
@ -262,7 +254,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
.storage_class = storage_class,
.scope = &scope,
.is_export = switch (storage_class) {
.None => has_body and c.mode != .import,
.None => has_body,
.Extern, .Static => false,
.PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern", .{}),
.Auto => unreachable, // Not legal on functions

View File

@ -9020,10 +9020,6 @@ void codegen_translate_c(CodeGen *g, Buf *full_path, FILE *out_file, bool use_us
init(g);
Stage2TranslateMode trans_mode = buf_ends_with_str(full_path, ".h") ?
Stage2TranslateModeImport : Stage2TranslateModeTranslate;
ZigList<const char *> clang_argv = {0};
add_cc_args(g, clang_argv, nullptr, true);
@ -9047,10 +9043,10 @@ void codegen_translate_c(CodeGen *g, Buf *full_path, FILE *out_file, bool use_us
if (use_userland_implementation) {
err = stage2_translate_c(&ast, &errors_ptr, &errors_len,
&clang_argv.at(0), &clang_argv.last(), trans_mode, resources_path);
&clang_argv.at(0), &clang_argv.last(), resources_path);
} else {
err = parse_h_file(g, &root_node, &errors_ptr, &errors_len, &clang_argv.at(0), &clang_argv.last(),
trans_mode, resources_path);
err = parse_h_file(g, &root_node, &errors_ptr, &errors_len, &clang_argv.at(0),
&clang_argv.last(), resources_path);
}
if (err == ErrorCCompileErrors && errors_len > 0) {

View File

@ -23343,7 +23343,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
const char *resources_path = buf_ptr(ira->codegen->zig_c_headers_dir);
if ((err = parse_h_file(ira->codegen, &root_node, &errors_ptr, &errors_len,
&clang_argv.at(0), &clang_argv.last(), Stage2TranslateModeImport, resources_path)))
&clang_argv.at(0), &clang_argv.last(), resources_path)))
{
if (err != ErrorCCompileErrors) {
ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err)));

View File

@ -64,8 +64,6 @@ struct TransScopeWhile {
struct Context {
AstNode *root;
VisibMod visib_mod;
bool want_export;
HashMap<const void *, AstNode *, ptr_hash, ptr_eq> decl_table;
HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> macro_table;
HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> global_table;
@ -367,7 +365,7 @@ static AstNode *trans_create_node_var_decl(Context *c, VisibMod visib_mod, bool
static AstNode *trans_create_node_var_decl_global(Context *c, bool is_const, Buf *var_name, AstNode *type_node,
AstNode *init_node)
{
return trans_create_node_var_decl(c, c->visib_mod, is_const, var_name, type_node, init_node);
return trans_create_node_var_decl(c, VisibModPub, is_const, var_name, type_node, init_node);
}
static AstNode *trans_create_node_var_decl_local(Context *c, bool is_const, Buf *var_name, AstNode *type_node,
@ -379,7 +377,7 @@ static AstNode *trans_create_node_var_decl_local(Context *c, bool is_const, Buf
static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *ref_node, AstNode *src_proto_node) {
AstNode *fn_def = trans_create_node(c, NodeTypeFnDef);
AstNode *fn_proto = trans_create_node(c, NodeTypeFnProto);
fn_proto->data.fn_proto.visib_mod = c->visib_mod;
fn_proto->data.fn_proto.visib_mod = VisibModPub;
fn_proto->data.fn_proto.name = fn_name;
fn_proto->data.fn_proto.fn_inline = FnInlineAlways;
fn_proto->data.fn_proto.return_type = src_proto_node->data.fn_proto.return_type; // TODO ok for these to alias?
@ -4091,10 +4089,10 @@ static void visit_fn_decl(Context *c, const ZigClangFunctionDecl *fn_decl) {
ZigClangStorageClass sc = ZigClangFunctionDecl_getStorageClass(fn_decl);
if (sc == ZigClangStorageClass_None) {
proto_node->data.fn_proto.visib_mod = c->visib_mod;
proto_node->data.fn_proto.is_export = ZigClangFunctionDecl_hasBody(fn_decl) ? c->want_export : false;
proto_node->data.fn_proto.visib_mod = VisibModPub;
proto_node->data.fn_proto.is_export = ZigClangFunctionDecl_hasBody(fn_decl);
} else if (sc == ZigClangStorageClass_Extern || sc == ZigClangStorageClass_Static) {
proto_node->data.fn_proto.visib_mod = c->visib_mod;
proto_node->data.fn_proto.visib_mod = VisibModPub;
} else if (sc == ZigClangStorageClass_PrivateExtern) {
emit_warning(c, ZigClangFunctionDecl_getLocation(fn_decl), "unsupported storage class: private extern");
return;
@ -5113,18 +5111,11 @@ static void process_preprocessor_entities(Context *c, ZigClangASTUnit *unit) {
Error parse_h_file(CodeGen *codegen, AstNode **out_root_node,
Stage2ErrorMsg **errors_ptr, size_t *errors_len,
const char **args_begin, const char **args_end,
Stage2TranslateMode mode, const char *resources_path)
const char *resources_path)
{
Context context = {0};
Context *c = &context;
c->warnings_on = codegen->verbose_cimport;
if (mode == Stage2TranslateModeImport) {
c->visib_mod = VisibModPub;
c->want_export = false;
} else {
c->visib_mod = VisibModPub;
c->want_export = true;
}
c->decl_table.init(8);
c->macro_table.init(8);
c->global_table.init(8);

View File

@ -14,6 +14,6 @@
Error parse_h_file(CodeGen *codegen, AstNode **out_root_node,
Stage2ErrorMsg **errors_ptr, size_t *errors_len,
const char **args_begin, const char **args_end,
Stage2TranslateMode mode, const char *resources_path);
const char *resources_path);
#endif

View File

@ -9,8 +9,7 @@
Error stage2_translate_c(struct Stage2Ast **out_ast,
struct Stage2ErrorMsg **out_errors_ptr, size_t *out_errors_len,
const char **args_begin, const char **args_end, enum Stage2TranslateMode mode,
const char *resources_path)
const char **args_begin, const char **args_end, const char *resources_path)
{
const char *msg = "stage0 called stage2_translate_c";
stage2_panic(msg, strlen(msg));

View File

@ -80,12 +80,6 @@ enum Error {
ErrorImportOutsidePkgPath,
};
// ABI warning
enum Stage2TranslateMode {
Stage2TranslateModeImport,
Stage2TranslateModeTranslate,
};
// ABI warning
struct Stage2ErrorMsg {
const char *filename_ptr; // can be null
@ -104,8 +98,7 @@ struct Stage2Ast;
// ABI warning
ZIG_EXTERN_C enum Error stage2_translate_c(struct Stage2Ast **out_ast,
struct Stage2ErrorMsg **out_errors_ptr, size_t *out_errors_len,
const char **args_begin, const char **args_end, enum Stage2TranslateMode mode,
const char *resources_path);
const char **args_begin, const char **args_end, const char *resources_path);
// ABI warning
ZIG_EXTERN_C void stage2_free_clang_errors(struct Stage2ErrorMsg *ptr, size_t len);