From a513b477803c94408be5c6f0d6ae6282ade00ba4 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 27 May 2018 23:33:10 +0100 Subject: [PATCH] Remove unused packages --- core/runtime/core.odin | 2 +- core/strings/strings.odin | 1 - core/unicode/utf16/utf16.odin | 2 -- examples/demo/demo.odin | 1 + src/checker.cpp | 44 ++++++++++++++++++++++++----------- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 87839538a..c4d3dd920 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -1,13 +1,13 @@ package runtime import "core:os" -import "core:unicode/utf8" import "core:raw" import "core:mem" // Naming Conventions: // In general, Ada_Case for types and snake_case for values // +// Package Name: snake_case (but prefer single word) // Import Name: snake_case (but prefer single word) // Types: Ada_Case // Enum Values: Ada_Case diff --git a/core/strings/strings.odin b/core/strings/strings.odin index 9cee48bc8..acbd3f054 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -1,6 +1,5 @@ package strings -import "core:mem" import "core:raw" new_string :: proc(s: string) -> string { diff --git a/core/unicode/utf16/utf16.odin b/core/unicode/utf16/utf16.odin index 971290a1e..5242efc9a 100644 --- a/core/unicode/utf16/utf16.odin +++ b/core/unicode/utf16/utf16.odin @@ -1,7 +1,5 @@ package utf16 -import "core:unicode/utf8" - REPLACEMENT_CHAR :: '\uFFFD'; MAX_RUNE :: '\U0010FFFF'; diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index 05636ea58..0c6d654f5 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -85,6 +85,7 @@ general_stuff :: proc() { x3: b32 = true; x4: b64 = false; + fmt.printf("x0: %T = %v;\n", x0, x0); fmt.printf("x1: %T = %v;\n", x1, x1); fmt.printf("x2: %T = %v;\n", x2, x2); fmt.printf("x3: %T = %v;\n", x3, x3); diff --git a/src/checker.cpp b/src/checker.cpp index 0b9323eb4..c70256b45 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -445,8 +445,14 @@ void check_scope_usage(Checker *c, Scope *scope) { for_array(i, scope->elements.entries) { Entity *e = scope->elements.entries[i].value; - if (e != nullptr && e->kind == Entity_Variable && (e->flags&EntityFlag_Used) == 0) { - array_add(&unused, e); + if (e != nullptr && (e->flags&EntityFlag_Used) == 0) { + switch (e->kind) { + case Entity_Variable: + case Entity_ImportName: + case Entity_LibraryName: + array_add(&unused, e); + break; + } } } @@ -901,23 +907,25 @@ bool add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) { } void add_entity_use(Checker *c, AstNode *identifier, Entity *entity) { - GB_ASSERT(identifier != nullptr); - if (identifier->kind != AstNode_Ident) { - return; - } if (entity == nullptr) { return; } - if (entity->identifier == nullptr) { - entity->identifier = identifier; - } - identifier->Ident.entity = entity; - add_declaration_dependency(c, entity); // TODO(bill): Should this be here? + if (identifier != nullptr) { + if (identifier->kind != AstNode_Ident) { + return; + } + if (entity->identifier == nullptr) { + entity->identifier = identifier; + } + identifier->Ident.entity = entity; - String dmsg = entity->deprecated_message; - if (dmsg.len > 0) { - warning(identifier, "%.*s is deprecated: %.*s", LIT(entity->token.string), LIT(dmsg)); + String dmsg = entity->deprecated_message; + if (dmsg.len > 0) { + warning(identifier, "%.*s is deprecated: %.*s", LIT(entity->token.string), LIT(dmsg)); + } } + entity->flags |= EntityFlag_Used; + add_declaration_dependency(c, entity); // TODO(bill): Should this be here? } @@ -2545,6 +2553,9 @@ void check_add_import_decl(Checker *c, AstNodeImportDecl *id) { scope); add_entity(c, parent_scope, nullptr, e); + if (id->is_using) { + add_entity_use(c, nullptr, e); + } } } @@ -2991,6 +3002,11 @@ void check_parsed_files(Checker *c) { check_proc_body(c, pi->token, pi->decl, pi->type, pi->body); } + for_array(i, c->info.files.entries) { + AstFile *f = c->info.files.entries[i].value; + check_scope_usage(c, f->scope); + } + TIME_SECTION("generate minimum dependency set"); generate_minimum_dependency_set(c, c->info.entry_point);