Browse Source

Remove dead code

gingerBill 7 years ago
parent
commit
307977d4cf
3 changed files with 36 additions and 117 deletions
  1. 30 68
      src/checker.cpp
  2. 5 38
      src/parser.cpp
  3. 1 11
      src/parser.hpp

+ 30 - 68
src/checker.cpp

@@ -2352,41 +2352,6 @@ void add_import_dependency_node(Checker *c, AstNode *decl, Map<ImportGraphNode *
 		}
 	case_end;
 
-
-	// case_ast_node(ed, ExportDecl, decl);
-	// 	String path = ed->fullpath;
-	// 	HashKey key = hash_string(path);
-	// 	Scope **found = map_get(&c->file_scopes, key);
-	// 	if (found == nullptr) {
-	// 		for_array(scope_index, c->file_scopes.entries) {
-	// 			Scope *scope = c->file_scopes.entries[scope_index].value;
-	// 			gb_printf_err("%.*s\n", LIT(scope->file->tokenizer.fullpath));
-	// 		}
-	// 		Token token = ast_node_token(decl);
-	// 		gb_printf_err("%.*s(%td:%td)\n", LIT(token.pos.file), token.pos.line, token.pos.column);
-	// 		GB_PANIC("Unable to find scope for file: %.*s", LIT(path));
-	// 	}
-	// 	Scope *scope = *found;
-	// 	GB_ASSERT(scope != nullptr);
-	// 	ed->file = scope->file;
-
-	// 	ImportGraphNode **found_node = nullptr;
-	// 	ImportGraphNode *m = nullptr;
-	// 	ImportGraphNode *n = nullptr;
-
-	// 	found_node = map_get(M, hash_pointer(scope));
-	// 	GB_ASSERT(found_node != nullptr);
-	// 	m = *found_node;
-
-	// 	found_node = map_get(M, hash_pointer(parent_package_scope));
-	// 	GB_ASSERT(found_node != nullptr);
-	// 	n = *found_node;
-
-	// 	import_graph_node_set_add(&n->succ, m);
-	// 	import_graph_node_set_add(&m->pred, n);
-	// 	ptr_set_add(&m->scope->exported, n->scope);
-	// case_end;
-
 	case_ast_node(ws, WhenStmt, decl);
 		if (ws->body != nullptr) {
 			auto stmts = ws->body->BlockStmt.stmts;
@@ -2474,39 +2439,36 @@ Array<ImportPathItem> find_import_path(Checker *c, Scope *start, Scope *end, Ptr
 	String path = start->package->fullpath;
 	HashKey key = hash_string(path);
 	Scope **found = map_get(&c->package_scopes, key);
-	// if (found) {
-	// 	AstPackage *p = (*found)->package;
-	// 	GB_ASSERT(p != nullptr);
-
-	// 	for_array(i, f->imports_and_exports) {
-	// 		Scope *s = nullptr;
-	// 		AstNode *decl = f->imports_and_exports[i];
-	// 		/* if (decl->kind == AstNode_ExportDecl) {
-	// 			s = decl->ExportDecl.file->scope;
-	// 		} else */
-	// 		if (decl->kind == AstNode_ImportDecl) {
-	// 			if (!decl->ImportDecl.is_using) {
-	// 				// continue;
-	// 			}
-	// 			s = decl->ImportDecl.package->scope;
-	// 		} else {
-	// 			continue;
-	// 		}
-	// 		GB_ASSERT(s != nullptr);
-
-	// 		ImportPathItem item = {s, decl};
-	// 		if (s == end) {
-	// 			auto path = array_make<ImportPathItem>(heap_allocator());
-	// 			array_add(&path, item);
-	// 			return path;
-	// 		}
-	// 		auto next_path = find_import_path(c, s, end, visited);
-	// 		if (next_path.count > 0) {
-	// 			array_add(&next_path, item);
-	// 			return next_path;
-	// 		}
-	// 	}
-	// }
+	if (found) {
+		AstPackage *p = (*found)->package;
+		GB_ASSERT(p != nullptr);
+
+		for_array(i, p->files.entries) {
+			AstFile *f = p->files.entries[i].value;
+			for_array(j, f->imports) {
+				Scope *s = nullptr;
+				AstNode *decl = f->imports[j];
+				if (decl->kind == AstNode_ImportDecl) {
+					s = decl->ImportDecl.package->scope;
+				} else {
+					continue;
+				}
+				GB_ASSERT(s != nullptr && s->is_package);
+
+				ImportPathItem item = {s, decl};
+				if (s == end) {
+					auto path = array_make<ImportPathItem>(heap_allocator());
+					array_add(&path, item);
+					return path;
+				}
+				auto next_path = find_import_path(c, s, end, visited);
+				if (next_path.count > 0) {
+					array_add(&next_path, item);
+					return next_path;
+				}
+			}
+		}
+	}
 	return empty_path;
 }
 #endif

+ 5 - 38
src/parser.cpp

@@ -61,7 +61,6 @@ Token ast_node_token(AstNode *node) {
 
 	case AstNode_ValueDecl:          return ast_node_token(node->ValueDecl.names[0]);
 	case AstNode_ImportDecl:         return node->ImportDecl.token;
-	// case AstNode_ExportDecl:         return node->ExportDecl.token;
 	case AstNode_ForeignImportDecl:  return node->ForeignImportDecl.token;
 
 	case AstNode_ForeignBlockDecl:   return node->ForeignBlockDecl.token;
@@ -1011,16 +1010,6 @@ AstNode *ast_import_decl(AstFile *f, Token token, bool is_using, Token relpath,
 	return result;
 }
 
-// AstNode *ast_export_decl(AstFile *f, Token token, Token relpath,
-//                          CommentGroup docs, CommentGroup comment) {
-// 	AstNode *result = make_ast_node(f, AstNode_ExportDecl);
-// 	result->ExportDecl.token       = token;
-// 	result->ExportDecl.relpath     = relpath;
-// 	result->ExportDecl.docs        = docs;
-// 	result->ExportDecl.comment     = comment;
-// 	return result;
-// }
-
 AstNode *ast_foreign_import_decl(AstFile *f, Token token, Token filepath, Token library_name,
                                  CommentGroup docs, CommentGroup comment) {
 	AstNode *result = make_ast_node(f, AstNode_ForeignImportDecl);
@@ -1319,7 +1308,6 @@ bool is_semicolon_optional_for_node(AstFile *f, AstNode *s) {
 		return s->ProcLit.body != nullptr;
 
 	case AstNode_ImportDecl:
-	// case AstNode_ExportDecl:
 	case AstNode_ForeignImportDecl:
 		return true;
 
@@ -3481,7 +3469,7 @@ AstNode *parse_import_decl(AstFile *f, ImportDeclKind kind) {
 		s = ast_bad_decl(f, import_name, file_path);
 	} else {
 		s = ast_import_decl(f, token, is_using, file_path, import_name, docs, f->line_comment);
-		array_add(&f->imports_and_exports, s);
+		array_add(&f->imports, s);
 	}
 	expect_semicolon(f, s);
 	return s;
@@ -3642,13 +3630,7 @@ AstNode *parse_stmt(AstFile *f) {
 					import_decl->ImportDecl.using_in_list = list;
 				}
 				return import_decl;
-			} /* else if (f->curr_token.kind == Token_export) {
-				AstNode *export_decl = parse_export_decl(f);
-				if (export_decl->kind == AstNode_ExportDecl) {
-					export_decl->ExportDecl.using_in_list = list;
-				}
-				return export_decl;
-			} */
+			}
 
 			AstNode *expr = parse_expr(f, true);
 			expect_semicolon(f, expr);
@@ -3873,7 +3855,7 @@ ParseFileError init_ast_file(AstFile *f, String fullpath, TokenPos *err_pos) {
 	arena_size *= 2*f->tokens.count;
 	gb_arena_init_from_allocator(&f->arena, heap_allocator(), arena_size);
 	array_init(&f->comments, heap_allocator());
-	array_init(&f->imports_and_exports, heap_allocator());
+	array_init(&f->imports, heap_allocator());
 
 	f->curr_proc = nullptr;
 
@@ -3885,7 +3867,7 @@ void destroy_ast_file(AstFile *f) {
 	gb_arena_free(&f->arena);
 	array_free(&f->tokens);
 	array_free(&f->comments);
-	array_free(&f->imports_and_exports);
+	array_free(&f->imports);
 	gb_free(heap_allocator(), f->tokenizer.fullpath.text);
 	destroy_tokenizer(&f->tokenizer);
 }
@@ -4098,22 +4080,7 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array<AstNod
 
 			id->fullpath = import_path;
 			try_add_import_path(p, import_path, original_string, ast_node_token(node).pos);
-		} /* else if (node->kind == AstNode_ExportDecl) {
-			ast_node(ed, ExportDecl, node);
-
-			String original_string = ed->relpath.string;
-			String export_path = {};
-			bool ok = determine_path_from_string(p, node, base_dir, original_string, &export_path);
-			if (!ok) {
-				decls[i] = ast_bad_decl(f, ed->relpath, ed->relpath);
-				continue;
-			}
-
-			export_path = string_trim_whitespace(export_path);
-
-			ed->fullpath = export_path;
-			try_add_import_path(p, export_path, original_string, ast_node_token(node).pos);
-		}  */else if (node->kind == AstNode_ForeignImportDecl) {
+		} else if (node->kind == AstNode_ForeignImportDecl) {
 			ast_node(fl, ForeignImportDecl, node);
 
 			String file_str = fl->filepath.string;

+ 1 - 11
src/parser.hpp

@@ -64,7 +64,7 @@ struct AstFile {
 	isize               when_level;
 
 	Array<AstNode *>    decls;
-	Array<AstNode *>    imports_and_exports; // 'import' 'using import' 'export'
+	Array<AstNode *>    imports; // 'import' 'using import'
 
 
 	AstNode *           curr_proc;
@@ -368,16 +368,6 @@ AST_NODE_KIND(_DeclBegin,      "", struct {}) \
 		bool     is_using;      \
 		bool     been_handled;  \
 	}) \
-	/* AST_NODE_KIND(ExportDecl, "export declaration", struct { \
-		AstFile *file;          \
-		Token    token;         \
-		Token    relpath;       \
-		String   fullpath;      \
-		Array<AstNode *> using_in_list; \
-		CommentGroup docs;      \
-		CommentGroup comment;   \
-		bool     been_handled;  \
-	}) */ \
 	AST_NODE_KIND(ForeignImportDecl, "foreign import declaration", struct { \
 		Token    token;           \
 		Token    filepath;        \