From 307977d4cf6a2b0bd2004bd9facbab00d1e5cb57 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 27 May 2018 13:30:18 +0100 Subject: [PATCH] Remove dead code --- src/checker.cpp | 94 +++++++++++++++---------------------------------- src/parser.cpp | 43 +++------------------- src/parser.hpp | 12 +------ 3 files changed, 34 insertions(+), 115 deletions(-) diff --git a/src/checker.cpp b/src/checker.cpp index 9f9d8bebc..51689d027 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -2352,41 +2352,6 @@ void add_import_dependency_node(Checker *c, AstNode *decl, Mapfullpath; - // 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 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); + 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); + 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(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; - // } - // } - // } + ImportPathItem item = {s, decl}; + if (s == end) { + auto path = array_make(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 diff --git a/src/parser.cpp b/src/parser.cpp index fe552ac9a..355e935ec 100644 --- a/src/parser.cpp +++ b/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, Arrayfullpath = 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; diff --git a/src/parser.hpp b/src/parser.hpp index f08898f1a..3f8b13cb4 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -64,7 +64,7 @@ struct AstFile { isize when_level; Array decls; - Array imports_and_exports; // 'import' 'using import' 'export' + Array 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 using_in_list; \ - CommentGroup docs; \ - CommentGroup comment; \ - bool been_handled; \ - }) */ \ AST_NODE_KIND(ForeignImportDecl, "foreign import declaration", struct { \ Token token; \ Token filepath; \