commit 979d6741cf53234c43c1d885c7e973db365ce659
parent 6898b25658d89498ea7c88a15d8b6bfc9658945c
Author: Drew DeVault <sir@cmpwn.com>
Date: Fri, 3 Sep 2021 16:40:19 +0200
all: add @hidden attribute
This is necessary so that the internal symbols in rt for static type
info are not exported to the typedefs file, where the types::typeinfo
types are not available.
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
9 files changed, 37 insertions(+), 23 deletions(-)
diff --git a/include/ast.h b/include/ast.h
@@ -363,6 +363,7 @@ struct ast_expression {
struct ast_global_decl {
char *symbol;
+ bool hidden;
struct identifier ident;
struct ast_type *type;
struct ast_expression *init;
@@ -377,6 +378,7 @@ struct ast_type_decl {
struct ast_function_decl {
char *symbol;
+ bool hidden;
struct identifier ident;
struct ast_function_type prototype;
struct ast_expression *body;
diff --git a/include/check.h b/include/check.h
@@ -81,7 +81,7 @@ struct declaration {
enum declaration_type type;
struct identifier ident;
char *symbol;
- bool exported;
+ bool exported, hidden;
union {
struct constant_decl constant;
struct function_decl func;
diff --git a/include/lex.h b/include/lex.h
@@ -7,6 +7,7 @@
// Keep sorted
enum lexical_token {
T_ATTR_FINI,
+ T_ATTR_HIDDEN,
T_ATTR_INIT,
T_ATTR_NORETURN,
T_ATTR_OFFSET,
diff --git a/rt/types.ha b/rt/types.ha
@@ -21,55 +21,55 @@ type types::builtin = enum u8 {
U16, U32, U64, U8, UINT, UINTPTR, VOID,
};
-export const builtin_char: types::typeinfo = types::typeinfo {
+export const @hidden builtin_char: types::typeinfo = types::typeinfo {
id = 3950255460,
sz = 1, al = 1, flags = 0,
repr = types::builtin::CHAR,
-}, builtin_f32: types::typeinfo = types::typeinfo {
+}, @hidden builtin_f32: types::typeinfo = types::typeinfo {
id = 930681398,
sz = 4, al = 4, flags = 0,
repr = types::builtin::F32,
-}, builtin_f64: types::typeinfo = types::typeinfo {
+}, @hidden builtin_f64: types::typeinfo = types::typeinfo {
id = 2037165609,
sz = 8, al = 8, flags = 0,
repr = types::builtin::F64,
-}, builtin_i8: types::typeinfo = types::typeinfo {
+}, @hidden builtin_i8: types::typeinfo = types::typeinfo {
id = 461893804,
sz = 1, al = 1, flags = 0,
repr = types::builtin::I8,
-}, builtin_i16: types::typeinfo = types::typeinfo {
+}, @hidden builtin_i16: types::typeinfo = types::typeinfo {
id = 3312558843,
sz = 2, al = 2, flags = 0,
repr = types::builtin::I16,
-}, builtin_i32: types::typeinfo = types::typeinfo {
+}, @hidden builtin_i32: types::typeinfo = types::typeinfo {
id = 2674862226,
sz = 4, al = 4, flags = 0,
repr = types::builtin::I32,
-}, builtin_i64: types::typeinfo = types::typeinfo {
+}, @hidden builtin_i64: types::typeinfo = types::typeinfo {
id = 1099590421,
sz = 8, al = 8, flags = 0,
repr = types::builtin::I64,
-}, builtin_rune: types::typeinfo = types::typeinfo {
+}, @hidden builtin_rune: types::typeinfo = types::typeinfo {
id = 2206074632,
sz = 4, al = 4, flags = 0,
repr = types::builtin::RUNE,
-}, builtin_u8: types::typeinfo = types::typeinfo {
+}, @hidden builtin_u8: types::typeinfo = types::typeinfo {
id = 3181589295,
sz = 1, al = 1, flags = 0,
repr = types::builtin::U8,
-}, builtin_u16: types::typeinfo = types::typeinfo {
+}, @hidden builtin_u16: types::typeinfo = types::typeinfo {
id = 3481467866,
sz = 2, al = 2, flags = 0,
repr = types::builtin::U16,
-}, builtin_u32: types::typeinfo = types::typeinfo {
+}, @hidden builtin_u32: types::typeinfo = types::typeinfo {
id = 1906196061,
sz = 4, al = 4, flags = 0,
repr = types::builtin::U32,
-}, builtin_u64: types::typeinfo = types::typeinfo {
+}, @hidden builtin_u64: types::typeinfo = types::typeinfo {
id = 1268499444,
sz = 8, al = 8, flags = 0,
repr = types::builtin::U64,
-}, builtin_void: types::typeinfo = types::typeinfo {
+}, @hidden builtin_void: types::typeinfo = types::typeinfo {
id = 3012680272,
sz = 0, al = 0, flags = 0,
repr = types::builtin::VOID,
diff --git a/rt/types_arch+x86_64.ha b/rt/types_arch+x86_64.ha
@@ -1,28 +1,28 @@
-export const builtin_int: types::typeinfo = types::typeinfo {
+export const @hidden builtin_int: types::typeinfo = types::typeinfo {
id = 1737287038,
sz = 4, al = 4, flags = 0,
repr = types::builtin::INT,
-}, builtin_uint: types::typeinfo = types::typeinfo {
+}, @hidden builtin_uint: types::typeinfo = types::typeinfo {
id = 2543892678,
sz = 4, al = 4, flags = 0,
repr = types::builtin::UINT,
-}, builtin_bool: types::typeinfo = types::typeinfo {
+}, @hidden builtin_bool: types::typeinfo = types::typeinfo {
id = 292984781,
sz = 4, al = 4, flags = 0,
repr = types::builtin::BOOL,
-}, builtin_size: types::typeinfo = types::typeinfo {
+}, @hidden builtin_size: types::typeinfo = types::typeinfo {
id = 4119164483,
sz = 8, al = 8, flags = 0,
repr = types::builtin::SIZE,
-}, builtin_uintptr: types::typeinfo = types::typeinfo {
+}, @hidden builtin_uintptr: types::typeinfo = types::typeinfo {
id = 3650376889,
sz = 8, al = 8, flags = 0,
repr = types::builtin::UINTPTR,
-}, builtin_str: types::typeinfo = types::typeinfo {
+}, @hidden builtin_str: types::typeinfo = types::typeinfo {
id = 3350498318,
sz = 24, al = 8, flags = 0,
repr = types::builtin::STR,
-}, builtin_null: types::typeinfo = types::typeinfo {
+}, @hidden builtin_null: types::typeinfo = types::typeinfo {
id = 2843771249,
sz = 8, al = 8, flags = 0,
repr = types::builtin::NULL,
diff --git a/src/check.c b/src/check.c
@@ -2868,6 +2868,7 @@ check_function(struct context *ctx,
decl->func.type = fntype;
decl->func.flags = afndecl->flags;
+ decl->hidden = afndecl->hidden;
if (afndecl->symbol) {
decl->symbol = strdup(afndecl->symbol);
}
@@ -2959,6 +2960,7 @@ check_global(struct context *ctx,
decl->global.type = type;
decl->global.value = value;
+ decl->hidden = adecl->hidden;
if (adecl->symbol) {
decl->ident.name = strdup(adecl->symbol);
decl->symbol = strdup(adecl->symbol);
diff --git a/src/lex.c b/src/lex.c
@@ -15,6 +15,7 @@
static const char *tokens[] = {
// Must be alpha sorted and match lex.h
[T_ATTR_FINI] = "@fini",
+ [T_ATTR_HIDDEN] = "@hidden",
[T_ATTR_INIT] = "@init",
[T_ATTR_NORETURN] = "@noreturn",
[T_ATTR_OFFSET] = "@offset",
diff --git a/src/parse.c b/src/parse.c
@@ -2321,6 +2321,9 @@ parse_global_decl(struct lexer *lexer, enum lexical_token mode,
case T_ATTR_SYMBOL:
i->symbol = parse_attr_symbol(lexer);
break;
+ case T_ATTR_HIDDEN:
+ i->hidden = true;
+ break;
default:
unlex(lexer, &tok);
break;
@@ -2342,7 +2345,9 @@ parse_global_decl(struct lexer *lexer, enum lexical_token mode,
switch (lex(lexer, &tok)) {
case T_COMMA:
lex(lexer, &tok);
- if (tok.token == T_NAME || tok.token == T_ATTR_SYMBOL) {
+ if (tok.token == T_NAME
+ || tok.token == T_ATTR_SYMBOL
+ || tok.token == T_ATTR_HIDDEN) {
i->next = xcalloc(1, sizeof(struct ast_global_decl));
i = i->next;
unlex(lexer, &tok);
@@ -2395,6 +2400,9 @@ parse_fn_decl(struct lexer *lexer, struct ast_function_decl *decl)
case T_ATTR_FINI:
decl->flags |= FN_FINI;
break;
+ case T_ATTR_HIDDEN:
+ decl->hidden = true;
+ break;
case T_ATTR_INIT:
decl->flags |= FN_INIT;
break;
diff --git a/src/typedef.c b/src/typedef.c
@@ -423,7 +423,7 @@ emit_typedefs(struct unit *unit, FILE *out)
for (struct declarations *decls = unit->declarations;
decls; decls = decls->next) {
struct declaration *decl = decls->decl;
- if (!decl->exported) {
+ if (!decl->exported || decl->hidden) {
continue;
}