Browse Source

Refactor code to remove entity flag for export

gingerBill 7 years ago
parent
commit
56f7a859df
5 changed files with 22 additions and 21 deletions
  1. 3 3
      src/check_decl.cpp
  2. 9 5
      src/checker.cpp
  3. 2 2
      src/entity.cpp
  4. 5 9
      src/ir.cpp
  5. 3 2
      src/ssa.cpp

+ 3 - 3
src/check_decl.cpp

@@ -426,7 +426,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
 	TypeProc *pt = &proc_type->Proc;
 	TypeProc *pt = &proc_type->Proc;
 
 
 	bool is_foreign         = e->Procedure.is_foreign;
 	bool is_foreign         = e->Procedure.is_foreign;
-	bool is_export          = (e->flags & EntityFlag_ForeignExport) != 0;
+	bool is_export          = e->Procedure.is_export;
 	bool is_link_name       = (pl->tags & ProcTag_link_name) != 0;
 	bool is_link_name       = (pl->tags & ProcTag_link_name) != 0;
 	bool is_inline          = (pl->tags & ProcTag_inline)    != 0;
 	bool is_inline          = (pl->tags & ProcTag_inline)    != 0;
 	bool is_no_inline       = (pl->tags & ProcTag_no_inline) != 0;
 	bool is_no_inline       = (pl->tags & ProcTag_no_inline) != 0;
@@ -489,7 +489,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
 			check_procedure_later(c, c->curr_ast_file, e->token, d, proc_type, pl->body, pl->tags);
 			check_procedure_later(c, c->curr_ast_file, e->token, d, proc_type, pl->body, pl->tags);
 		}
 		}
 	} else if (!is_foreign) {
 	} else if (!is_foreign) {
-		if (e->flags & EntityFlag_ForeignExport) {
+		if (e->Procedure.is_export) {
 			error(e->token, "Foreign export procedures must have a body");
 			error(e->token, "Foreign export procedures must have a body");
 		} else {
 		} else {
 			error(e->token, "Only a foreign procedure cannot have a body");
 			error(e->token, "Only a foreign procedure cannot have a body");
@@ -606,7 +606,7 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count
 		}
 		}
 		init_entity_foreign_library(c, e);
 		init_entity_foreign_library(c, e);
 	}
 	}
-	if (e->Variable.is_foreign || (e->flags & EntityFlag_ForeignExport) != 0) {
+	if (e->Variable.is_foreign || e->Variable.is_export) {
 		String name = e->token.string;
 		String name = e->token.string;
 		auto *fp = &c->info.foreigns;
 		auto *fp = &c->info.foreigns;
 		HashKey key = hash_string(name);
 		HashKey key = hash_string(name);

+ 9 - 5
src/checker.cpp

@@ -1482,12 +1482,16 @@ PtrSet<Entity *> generate_minimum_dependency_set(CheckerInfo *info, Entity *star
 				add_dependency_to_map(&map, info, e);
 				add_dependency_to_map(&map, info, e);
 			}
 			}
 		} else if (e->kind == Entity_Procedure) {
 		} else if (e->kind == Entity_Procedure) {
+			if (e->Procedure.is_export) {
+				add_dependency_to_map(&map, info, e);
+			}
 			if (e->Procedure.is_foreign) {
 			if (e->Procedure.is_foreign) {
 				add_dependency_to_map(&map, info, e->Procedure.foreign_library);
 				add_dependency_to_map(&map, info, e->Procedure.foreign_library);
 			}
 			}
-		}
-		if (e->flags & EntityFlag_ForeignExport) {
-			add_dependency_to_map(&map, info, e);
+		} else if (e->kind == Entity_Variable) {
+			if (e->Variable.is_export) {
+				add_dependency_to_map(&map, info, e);
+			}
 		}
 		}
 	}
 	}
 
 
@@ -1971,7 +1975,7 @@ void check_collect_value_decl(Checker *c, AstNode *decl) {
 				e->Variable.is_foreign = true;
 				e->Variable.is_foreign = true;
 				e->Variable.foreign_library_ident = fl;
 				e->Variable.foreign_library_ident = fl;
 			} else if (c->context.in_foreign_export) {
 			} else if (c->context.in_foreign_export) {
-				e->flags |= EntityFlag_ForeignExport;
+				e->Variable.is_export = true;
 			}
 			}
 
 
 			entities[entity_count++] = e;
 			entities[entity_count++] = e;
@@ -2032,7 +2036,7 @@ void check_collect_value_decl(Checker *c, AstNode *decl) {
 					e->Procedure.foreign_library_ident = fl;
 					e->Procedure.foreign_library_ident = fl;
 					e->Procedure.is_foreign = true;
 					e->Procedure.is_foreign = true;
 				} else if (c->context.in_foreign_export) {
 				} else if (c->context.in_foreign_export) {
-					e->flags |= EntityFlag_ForeignExport;
+					e->Procedure.is_export = true;
 				}
 				}
 				d->proc_lit = init;
 				d->proc_lit = init;
 				d->type_expr = pl->type;
 				d->type_expr = pl->type;

+ 2 - 2
src/entity.cpp

@@ -45,8 +45,6 @@ enum EntityFlag {
 	EntityFlag_BitFieldValue = 1<<11,
 	EntityFlag_BitFieldValue = 1<<11,
 
 
 	EntityFlag_CVarArg       = 1<<20,
 	EntityFlag_CVarArg       = 1<<20,
-
-	EntityFlag_ForeignExport = 1<<23,
 };
 };
 
 
 // Zero value means the overloading process is not yet done
 // Zero value means the overloading process is not yet done
@@ -88,6 +86,7 @@ struct Entity {
 			bool       is_immutable;
 			bool       is_immutable;
 			bool       is_thread_local;
 			bool       is_thread_local;
 			bool       is_foreign;
 			bool       is_foreign;
+			bool       is_export;
 			Entity *   foreign_library;
 			Entity *   foreign_library;
 			AstNode *  foreign_library_ident;
 			AstNode *  foreign_library_ident;
 			String     link_name;
 			String     link_name;
@@ -100,6 +99,7 @@ struct Entity {
 			OverloadKind overload_kind;
 			OverloadKind overload_kind;
 			String       link_name;
 			String       link_name;
 			u64          tags;
 			u64          tags;
+			bool         is_export;
 			bool         is_foreign;
 			bool         is_foreign;
 			Entity *     foreign_library;
 			Entity *     foreign_library;
 			AstNode *    foreign_library_ident;
 			AstNode *    foreign_library_ident;

+ 5 - 9
src/ir.cpp

@@ -7353,12 +7353,8 @@ void ir_build_proc(irValue *value, irProcedure *parent) {
 		String filename = e->token.pos.file;
 		String filename = e->token.pos.file;
 		AstFile *f = ast_file_of_filename(info, filename);
 		AstFile *f = ast_file_of_filename(info, filename);
 
 
-		if (e->flags & EntityFlag_ForeignExport) {
-			proc->is_export = true;
-		}
-		if (e->Procedure.is_foreign) {
-			proc->is_foreign = true;
-		}
+		proc->is_export = e->Procedure.is_export;
+		proc->is_foreign = e->Procedure.is_foreign;
 
 
 		irDebugInfo *di_file = nullptr;
 		irDebugInfo *di_file = nullptr;
 
 
@@ -8120,7 +8116,7 @@ void ir_gen_tree(irGen *s) {
 				GB_ASSERT(e == entry_point);
 				GB_ASSERT(e == entry_point);
 				// entry_point = e;
 				// entry_point = e;
 			}
 			}
-			if ((e->flags & EntityFlag_ForeignExport) != 0 ||
+			if (e->Procedure.is_export ||
 			    (e->Procedure.link_name.len > 0) ||
 			    (e->Procedure.link_name.len > 0) ||
 			    (e->scope->is_file && e->Procedure.link_name.len > 0)) {
 			    (e->scope->is_file && e->Procedure.link_name.len > 0)) {
 				if (!has_dll_main && name == "DllMain") {
 				if (!has_dll_main && name == "DllMain") {
@@ -8165,7 +8161,7 @@ void ir_gen_tree(irGen *s) {
 
 
 
 
 			bool is_foreign = e->Variable.is_foreign;
 			bool is_foreign = e->Variable.is_foreign;
-			bool is_export = (e->flags & EntityFlag_ForeignExport) != 0;
+			bool is_export  = e->Variable.is_export;
 
 
 			String name = e->token.string;
 			String name = e->token.string;
 			String original_name = name;
 			String original_name = name;
@@ -8252,7 +8248,7 @@ void ir_gen_tree(irGen *s) {
 		String original_name = name;
 		String original_name = name;
 
 
 		if (!scope->is_global || polymorphic_struct || is_type_polymorphic(e->type)) {
 		if (!scope->is_global || polymorphic_struct || is_type_polymorphic(e->type)) {
-			if (e->kind == Entity_Procedure && (e->flags & EntityFlag_ForeignExport) != 0) {
+			if (e->kind == Entity_Procedure && e->Procedure.is_export) {
 			} else if (e->kind == Entity_Procedure && e->Procedure.link_name.len > 0) {
 			} else if (e->kind == Entity_Procedure && e->Procedure.link_name.len > 0) {
 				// Handle later
 				// Handle later
 			// } else if (scope->is_init && e->kind == Entity_Procedure && name == "main") {
 			// } else if (scope->is_init && e->kind == Entity_Procedure && name == "main") {

+ 3 - 2
src/ssa.cpp

@@ -2431,7 +2431,7 @@ bool ssa_generate(Parser *parser, CheckerInfo *info) {
 			if (e->scope->is_init && name == "main") {
 			if (e->scope->is_init && name == "main") {
 				entry_point = e;
 				entry_point = e;
 			}
 			}
-			if ((e->flags & EntityFlag_ForeignExport) != 0 ||
+			if (e->Procedure.is_export ||
 			    (e->Procedure.link_name.len > 0) ||
 			    (e->Procedure.link_name.len > 0) ||
 			    (e->scope->is_file && e->Procedure.link_name.len > 0)) {
 			    (e->scope->is_file && e->Procedure.link_name.len > 0)) {
 				if (!has_dll_main && name == "DllMain") {
 				if (!has_dll_main && name == "DllMain") {
@@ -2464,7 +2464,8 @@ bool ssa_generate(Parser *parser, CheckerInfo *info) {
 		}
 		}
 
 
 		if (!scope->is_global) {
 		if (!scope->is_global) {
-			if (e->kind == Entity_Procedure && (e->flags & EntityFlag_ForeignExport) != 0) {
+			if (e->kind == Entity_Procedure && e->Procedure.is_export) {
+			} else if (e->kind == Entity_Variable && e->Variable.is_export) {
 			} else if (e->kind == Entity_Procedure && e->Procedure.link_name.len > 0) {
 			} else if (e->kind == Entity_Procedure && e->Procedure.link_name.len > 0) {
 				// Handle later
 				// Handle later
 			} else if (scope->is_init && e->kind == Entity_Procedure && name == "main") {
 			} else if (scope->is_init && e->kind == Entity_Procedure && name == "main") {