aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/all_types.hpp1
-rw-r--r--src/ast_render.cpp7
-rw-r--r--src/codegen.cpp3
-rw-r--r--src/ir.cpp14
-rw-r--r--src/parser.cpp30
-rw-r--r--src/translate_c.cpp5
6 files changed, 41 insertions, 19 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp
index 1ec3c809a2..28477c8107 100644
--- a/src/all_types.hpp
+++ b/src/all_types.hpp
@@ -1285,7 +1285,6 @@ enum BuiltinFnId {
BuiltinFnIdSetAlignStack,
BuiltinFnIdArgType,
BuiltinFnIdExport,
- BuiltinFnIdExportWithLinkage,
};
struct BuiltinFnEntry {
diff --git a/src/ast_render.cpp b/src/ast_render.cpp
index fc01c79ca6..c22c16d90a 100644
--- a/src/ast_render.cpp
+++ b/src/ast_render.cpp
@@ -111,6 +111,10 @@ static const char *extern_string(bool is_extern) {
return is_extern ? "extern " : "";
}
+static const char *export_string(bool is_export) {
+ return is_export ? "export " : "";
+}
+
//static const char *calling_convention_string(CallingConvention cc) {
// switch (cc) {
// case CallingConventionUnspecified: return "";
@@ -410,8 +414,9 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
{
const char *pub_str = visib_mod_string(node->data.fn_proto.visib_mod);
const char *extern_str = extern_string(node->data.fn_proto.is_extern);
+ const char *export_str = export_string(node->data.fn_proto.is_export);
const char *inline_str = inline_string(node->data.fn_proto.is_inline);
- fprintf(ar->f, "%s%s%sfn", pub_str, inline_str, extern_str);
+ fprintf(ar->f, "%s%s%s%sfn", pub_str, inline_str, export_str, extern_str);
if (node->data.fn_proto.name != nullptr) {
fprintf(ar->f, " ");
print_symbol(ar, node->data.fn_proto.name);
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 5be26eb445..7fe4f95f85 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -5016,8 +5016,7 @@ static void define_builtin_fns(CodeGen *g) {
create_builtin_fn(g, BuiltinFnIdOpaqueType, "OpaqueType", 0);
create_builtin_fn(g, BuiltinFnIdSetAlignStack, "setAlignStack", 1);
create_builtin_fn(g, BuiltinFnIdArgType, "ArgType", 2);
- create_builtin_fn(g, BuiltinFnIdExport, "export", 2);
- create_builtin_fn(g, BuiltinFnIdExportWithLinkage, "exportWithLinkage", 3);
+ create_builtin_fn(g, BuiltinFnIdExport, "export", 3);
}
static const char *bool_to_str(bool b) {
diff --git a/src/ir.cpp b/src/ir.cpp
index 4afc1a2c60..7bd045bd92 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -4739,7 +4739,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
return ir_build_arg_type(irb, scope, node, arg0_value, arg1_value);
}
case BuiltinFnIdExport:
- case BuiltinFnIdExportWithLinkage:
{
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
@@ -4751,15 +4750,10 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
if (arg1_value == irb->codegen->invalid_instruction)
return arg1_value;
- IrInstruction *arg2_value;
- if (builtin_fn->id == BuiltinFnIdExportWithLinkage) {
- AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
- arg2_value = ir_gen_node(irb, arg2_node, scope);
- if (arg2_value == irb->codegen->invalid_instruction)
- return arg2_value;
- } else {
- arg2_value = nullptr;
- }
+ AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
+ IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
+ if (arg2_value == irb->codegen->invalid_instruction)
+ return arg2_value;
return ir_build_export(irb, scope, node, arg0_value, arg1_value, arg2_value);
}
diff --git a/src/parser.cpp b/src/parser.cpp
index cc337471ba..579fe85f3b 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -740,9 +740,21 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
return node;
} else if (token->id == TokenIdAtSign) {
*token_index += 1;
- Token *name_tok = ast_eat_token(pc, token_index, TokenIdSymbol);
+ Token *name_tok = &pc->tokens->at(*token_index);
+ Buf *name_buf;
+ if (name_tok->id == TokenIdKeywordExport) {
+ name_buf = buf_create_from_str("export");
+ *token_index += 1;
+ } else if (name_tok->id == TokenIdSymbol) {
+ name_buf = token_buf(name_tok);
+ *token_index += 1;
+ } else {
+ ast_expect_token(pc, name_tok, TokenIdSymbol);
+ zig_unreachable();
+ }
+
AstNode *name_node = ast_create_node(pc, NodeTypeSymbol, name_tok);
- name_node->data.symbol_expr.symbol = token_buf(name_tok);
+ name_node->data.symbol_expr.symbol = name_buf;
AstNode *node = ast_create_node(pc, NodeTypeFnCallExpr, token);
node->data.fn_call_expr.fn_ref_expr = name_node;
@@ -2254,12 +2266,22 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m
fn_token = ast_eat_token(pc, token_index, TokenIdKeywordFn);
cc = CallingConventionStdcall;
} else if (first_token->id == TokenIdKeywordExtern) {
+ is_extern = true;
*token_index += 1;
- fn_token = ast_eat_token(pc, token_index, TokenIdKeywordFn);
+ Token *next_token = &pc->tokens->at(*token_index);
+ if (next_token->id == TokenIdKeywordFn) {
+ fn_token = next_token;
+ *token_index += 1;
+ } else if (mandatory) {
+ ast_expect_token(pc, next_token, TokenIdKeywordFn);
+ zig_unreachable();
+ } else {
+ *token_index -= 1;
+ return nullptr;
+ }
cc = CallingConventionC;
} else if (first_token->id == TokenIdKeywordFn) {
fn_token = first_token;
- is_extern = true;
*token_index += 1;
cc = CallingConventionUnspecified;
} else if (mandatory) {
diff --git a/src/translate_c.cpp b/src/translate_c.cpp
index 77afc38a51..eba594e085 100644
--- a/src/translate_c.cpp
+++ b/src/translate_c.cpp
@@ -73,6 +73,7 @@ struct Context {
ImportTableEntry *import;
ZigList<ErrorMsg *> *errors;
VisibMod visib_mod;
+ bool want_export;
AstNode *root;
HashMap<const void *, AstNode *, ptr_hash, ptr_eq> decl_table;
HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> macro_table;
@@ -3250,8 +3251,8 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
StorageClass sc = fn_decl->getStorageClass();
if (sc == SC_None) {
- // TODO add export decl
proto_node->data.fn_proto.visib_mod = c->visib_mod;
+ proto_node->data.fn_proto.is_export = fn_decl->hasBody() ? c->want_export : false;
} else if (sc == SC_Extern || sc == SC_Static) {
proto_node->data.fn_proto.visib_mod = c->visib_mod;
} else if (sc == SC_PrivateExtern) {
@@ -4274,8 +4275,10 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
c->errors = errors;
if (buf_ends_with_str(buf_create_from_str(target_file), ".h")) {
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);