mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-12 05:18:09 +00:00
Allow all set entry types to be implicitly cast to their key/value type to allow for easier iteration
This commit is contained in:
@@ -1332,11 +1332,10 @@ gb_internal void enable_target_feature(TokenPos pos, String const &target_featur
|
||||
gb_internal char const *target_features_set_to_cstring(gbAllocator allocator, bool with_quotes) {
|
||||
isize len = 0;
|
||||
isize i = 0;
|
||||
for (auto const &entry : build_context.target_features_set) {
|
||||
for (String const &feature : build_context.target_features_set) {
|
||||
if (i != 0) {
|
||||
len += 1;
|
||||
}
|
||||
String feature = entry.value;
|
||||
len += feature.len;
|
||||
if (with_quotes) len += 2;
|
||||
i += 1;
|
||||
@@ -1344,13 +1343,12 @@ gb_internal char const *target_features_set_to_cstring(gbAllocator allocator, bo
|
||||
char *features = gb_alloc_array(allocator, char, len+1);
|
||||
len = 0;
|
||||
i = 0;
|
||||
for (auto const &entry : build_context.target_features_set) {
|
||||
for (String const &feature : build_context.target_features_set) {
|
||||
if (i != 0) {
|
||||
features[len++] = ',';
|
||||
}
|
||||
|
||||
if (with_quotes) features[len++] = '"';
|
||||
String feature = entry.value;
|
||||
gb_memmove(features + len, feature.text, feature.len);
|
||||
len += feature.len;
|
||||
if (with_quotes) features[len++] = '"';
|
||||
|
||||
@@ -1587,16 +1587,14 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
|
||||
|
||||
MUTEX_GUARD_BLOCK(decl->deps_mutex)
|
||||
MUTEX_GUARD_BLOCK(decl->parent->deps_mutex) {
|
||||
for (auto const &entry : decl->deps) {
|
||||
Entity *e = entry.ptr;
|
||||
for (Entity *e : decl->deps) {
|
||||
ptr_set_add(&decl->parent->deps, e);
|
||||
}
|
||||
}
|
||||
|
||||
MUTEX_GUARD_BLOCK(decl->type_info_deps_mutex)
|
||||
MUTEX_GUARD_BLOCK(decl->parent->type_info_deps_mutex) {
|
||||
for (auto const &entry : decl->type_info_deps) {
|
||||
Type *t = entry.ptr;
|
||||
for (Type *t : decl->type_info_deps) {
|
||||
ptr_set_add(&decl->parent->type_info_deps, t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,8 +202,8 @@ gb_internal void check_did_you_mean_objc_entity(String const &name, Entity *e, b
|
||||
|
||||
DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), set.entries.count, name);
|
||||
defer (did_you_mean_destroy(&d));
|
||||
for (auto const &entry : set) {
|
||||
did_you_mean_append(&d, entry.value);
|
||||
for (String const &target : set) {
|
||||
did_you_mean_append(&d, target);
|
||||
}
|
||||
check_did_you_mean_print(&d, prefix);
|
||||
}
|
||||
@@ -4942,8 +4942,7 @@ gb_internal isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lh
|
||||
if (e != nullptr) {
|
||||
DeclInfo *decl = decl_info_of_entity(e);
|
||||
if (decl != nullptr) {
|
||||
for (auto const &entry : decl->deps) {
|
||||
Entity *dep = entry.ptr;
|
||||
for (Entity *dep : decl->deps) {
|
||||
ptr_set_add(&c->decl->deps, dep);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2222,12 +2222,11 @@ gb_internal void add_dependency_to_set(Checker *c, Entity *entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto const &entry : decl->type_info_deps) {
|
||||
add_min_dep_type_info(c, entry.ptr);
|
||||
for (Type *t : decl->type_info_deps) {
|
||||
add_min_dep_type_info(c, t);
|
||||
}
|
||||
|
||||
for (auto const &entry : decl->deps) {
|
||||
Entity *e = entry.ptr;
|
||||
for (Entity *e : decl->deps) {
|
||||
add_dependency_to_set(c, e);
|
||||
if (e->kind == Entity_Procedure && e->Procedure.is_foreign) {
|
||||
Entity *fl = e->Procedure.foreign_library;
|
||||
@@ -2510,8 +2509,7 @@ gb_internal Array<EntityGraphNode *> generate_entity_dependency_graph(CheckerInf
|
||||
DeclInfo *decl = decl_info_of_entity(e);
|
||||
GB_ASSERT(decl != nullptr);
|
||||
|
||||
for (auto const &entry : decl->deps) {
|
||||
Entity *dep = entry.ptr;
|
||||
for (Entity *dep : decl->deps) {
|
||||
if (dep->flags & EntityFlag_Field) {
|
||||
continue;
|
||||
}
|
||||
@@ -2537,15 +2535,12 @@ gb_internal Array<EntityGraphNode *> generate_entity_dependency_graph(CheckerInf
|
||||
if (e->kind == Entity_Procedure) {
|
||||
// Connect each pred 'p' of 'n' with each succ 's' and from
|
||||
// the procedure node
|
||||
for (auto const &p_entry : n->pred) {
|
||||
EntityGraphNode *p = p_entry.ptr;
|
||||
|
||||
for (EntityGraphNode *p : n->pred) {
|
||||
// Ignore self-cycles
|
||||
if (p != n) {
|
||||
// Each succ 's' of 'n' becomes a succ of 'p', and
|
||||
// each pred 'p' of 'n' becomes a pred of 's'
|
||||
for (auto const &s_entry : n->succ) {
|
||||
EntityGraphNode *s = s_entry.ptr;
|
||||
for (EntityGraphNode *s : n->succ) {
|
||||
// Ignore self-cycles
|
||||
if (s != n) {
|
||||
if (p->entity->kind == Entity_Procedure &&
|
||||
@@ -4784,8 +4779,7 @@ gb_internal void check_import_entities(Checker *c) {
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const &entry : n->pred) {
|
||||
ImportGraphNode *p = entry.ptr;
|
||||
for (ImportGraphNode *p : n->pred) {
|
||||
p->dep_count = gb_max(p->dep_count-1, 0);
|
||||
priority_queue_fix(&pq, p->index);
|
||||
}
|
||||
@@ -4893,8 +4887,7 @@ gb_internal bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet<Entity
|
||||
if (var_decl == nullptr) {
|
||||
continue;
|
||||
}
|
||||
for (auto const &entry : var_decl->deps) {
|
||||
Entity *dep = entry.ptr;
|
||||
for (Entity *dep : var_decl->deps) {
|
||||
if (dep == end) {
|
||||
auto path = array_make<Entity *>(heap_allocator());
|
||||
array_add(&path, dep);
|
||||
@@ -4944,8 +4937,7 @@ gb_internal Array<Entity *> find_entity_path(Entity *start, Entity *end, PtrSet<
|
||||
return path;
|
||||
}
|
||||
} else {
|
||||
for (auto const &entry : decl->deps) {
|
||||
Entity *dep = entry.ptr;
|
||||
for (Entity *dep : decl->deps) {
|
||||
if (dep == end) {
|
||||
auto path = array_make<Entity *>(heap_allocator());
|
||||
array_add(&path, dep);
|
||||
@@ -5002,8 +4994,7 @@ gb_internal void calculate_global_init_order(Checker *c) {
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const &entry : n->pred) {
|
||||
EntityGraphNode *p = entry.ptr;
|
||||
for (EntityGraphNode *p : n->pred) {
|
||||
p->dep_count -= 1;
|
||||
p->dep_count = gb_max(p->dep_count, 0);
|
||||
priority_queue_fix(&pq, p->index);
|
||||
@@ -5163,8 +5154,7 @@ gb_internal void check_unchecked_bodies(Checker *c) {
|
||||
// use the `procs_to_check` array
|
||||
global_procedure_body_in_worker_queue = false;
|
||||
|
||||
for (auto const &entry : c->info.minimum_dependency_set) {
|
||||
Entity *e = entry.ptr;
|
||||
for (Entity *e : c->info.minimum_dependency_set) {
|
||||
if (e == nullptr || e->kind != Entity_Procedure) {
|
||||
continue;
|
||||
}
|
||||
@@ -5239,8 +5229,7 @@ gb_internal void check_test_procedures(Checker *c) {
|
||||
AstPackage *pkg = c->info.init_package;
|
||||
Scope *s = pkg->scope;
|
||||
|
||||
for (auto const &entry : build_context.test_names) {
|
||||
String name = entry.value;
|
||||
for (String const &name : build_context.test_names) {
|
||||
Entity *e = scope_lookup(s, name);
|
||||
if (e == nullptr) {
|
||||
Token tok = {};
|
||||
@@ -5744,8 +5733,7 @@ gb_internal void check_parsed_files(Checker *c) {
|
||||
DeclInfo *decl = e->decl_info;
|
||||
ast_node(pl, ProcLit, decl->proc_lit);
|
||||
if (pl->inlining == ProcInlining_inline) {
|
||||
for (auto const &entry : decl->deps) {
|
||||
Entity *dep = entry.ptr;
|
||||
for (Entity *dep : decl->deps) {
|
||||
if (dep == e) {
|
||||
error(e->token, "Cannot inline recursive procedure '%.*s'", LIT(e->token.string));
|
||||
break;
|
||||
|
||||
@@ -2,6 +2,10 @@ template <typename T>
|
||||
struct PtrSetEntry {
|
||||
T ptr;
|
||||
MapIndex next;
|
||||
|
||||
operator T() const noexcept {
|
||||
return this->ptr;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -245,21 +249,21 @@ gb_internal gb_inline void ptr_set_clear(PtrSet<T> *s) {
|
||||
|
||||
|
||||
template <typename T>
|
||||
gb_internal PtrSetEntry<T> *begin(PtrSet<T> &m) {
|
||||
gb_internal PtrSetEntry<T> *begin(PtrSet<T> &m) noexcept {
|
||||
return m.entries.data;
|
||||
}
|
||||
template <typename T>
|
||||
gb_internal PtrSetEntry<T> const *begin(PtrSet<T> const &m) {
|
||||
gb_internal PtrSetEntry<T> const *begin(PtrSet<T> const &m) noexcept {
|
||||
return m.entries.data;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
gb_internal PtrSetEntry<T> *end(PtrSet<T> &m) {
|
||||
gb_internal PtrSetEntry<T> *end(PtrSet<T> &m) noexcept {
|
||||
return m.entries.data + m.entries.count;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
gb_internal PtrSetEntry<T> const *end(PtrSet<T> const &m) {
|
||||
gb_internal PtrSetEntry<T> const *end(PtrSet<T> const &m) noexcept {
|
||||
return m.entries.data + m.entries.count;
|
||||
}
|
||||
@@ -1,6 +1,13 @@
|
||||
struct StringHashKey {
|
||||
u32 hash;
|
||||
String string;
|
||||
|
||||
operator String() const noexcept {
|
||||
return this->string;
|
||||
}
|
||||
operator String const &() const noexcept {
|
||||
return this->string;
|
||||
}
|
||||
};
|
||||
|
||||
gb_internal gb_inline StringHashKey string_hash_string(String const &s) {
|
||||
@@ -283,11 +290,11 @@ gb_internal gb_inline void string_map_clear(StringMap<T> *h) {
|
||||
|
||||
|
||||
template <typename T>
|
||||
gb_internal StringMapEntry<T> *begin(StringMap<T> &m) {
|
||||
gb_internal StringMapEntry<T> *begin(StringMap<T> &m) noexcept {
|
||||
return m.entries.data;
|
||||
}
|
||||
template <typename T>
|
||||
gb_internal StringMapEntry<T> const *begin(StringMap<T> const &m) {
|
||||
gb_internal StringMapEntry<T> const *begin(StringMap<T> const &m) noexcept {
|
||||
return m.entries.data;
|
||||
}
|
||||
|
||||
@@ -298,6 +305,6 @@ gb_internal StringMapEntry<T> *end(StringMap<T> &m) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
gb_internal StringMapEntry<T> const *end(StringMap<T> const &m) {
|
||||
gb_internal StringMapEntry<T> const *end(StringMap<T> const &m) noexcept {
|
||||
return m.entries.data + m.entries.count;
|
||||
}
|
||||
@@ -2,6 +2,13 @@ struct StringSetEntry {
|
||||
u32 hash;
|
||||
MapIndex next;
|
||||
String value;
|
||||
|
||||
operator String const() const noexcept {
|
||||
return this->value;
|
||||
}
|
||||
operator String const &() const noexcept {
|
||||
return this->value;
|
||||
}
|
||||
};
|
||||
|
||||
struct StringSet {
|
||||
@@ -226,18 +233,18 @@ gb_internal gb_inline void string_set_clear(StringSet *s) {
|
||||
}
|
||||
|
||||
|
||||
gb_internal StringSetEntry *begin(StringSet &m) {
|
||||
gb_internal StringSetEntry *begin(StringSet &m) noexcept {
|
||||
return m.entries.data;
|
||||
}
|
||||
gb_internal StringSetEntry const *begin(StringSet const &m) {
|
||||
gb_internal StringSetEntry const *begin(StringSet const &m) noexcept {
|
||||
return m.entries.data;
|
||||
}
|
||||
|
||||
|
||||
gb_internal StringSetEntry *end(StringSet &m) {
|
||||
gb_internal StringSetEntry *end(StringSet &m) noexcept {
|
||||
return m.entries.data + m.entries.count;
|
||||
}
|
||||
|
||||
gb_internal StringSetEntry const *end(StringSet const &m) {
|
||||
gb_internal StringSetEntry const *end(StringSet const &m) noexcept {
|
||||
return m.entries.data + m.entries.count;
|
||||
}
|
||||
@@ -823,8 +823,7 @@ gb_internal bool type_ptr_set_exists(PtrSet<Type *> *s, Type *t) {
|
||||
|
||||
// TODO(bill, 2019-10-05): This is very slow and it's probably a lot
|
||||
// faster to cache types correctly
|
||||
for (auto const &entry : *s) {
|
||||
Type *f = entry.ptr;
|
||||
for (Type *f : *s) {
|
||||
if (are_types_identical(t, f)) {
|
||||
ptr_set_add(s, t);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user