mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-24 00:17:54 +00:00
Improve odin doc string printing (Fixes #2246)
This commit is contained in:
+10
-14
@@ -49,10 +49,9 @@ gb_internal GB_COMPARE_PROC(cmp_entities_for_printing) {
|
||||
int ox = print_entity_kind_ordering[x->kind];
|
||||
int oy = print_entity_kind_ordering[y->kind];
|
||||
res = ox - oy;
|
||||
if (res != 0) {
|
||||
return res;
|
||||
if (res == 0) {
|
||||
res = string_compare(x->token.string, y->token.string);
|
||||
}
|
||||
res = string_compare(x->token.string, y->token.string);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -230,6 +229,12 @@ gb_internal void print_doc_package(CheckerInfo *info, AstPackage *pkg) {
|
||||
// Fine
|
||||
break;
|
||||
}
|
||||
if (e->pkg != pkg) {
|
||||
continue;
|
||||
}
|
||||
if (!is_entity_exported(e)) {
|
||||
continue;
|
||||
}
|
||||
array_add(&entities, e);
|
||||
}
|
||||
gb_sort_array(entities.data, entities.count, cmp_entities_for_printing);
|
||||
@@ -237,16 +242,7 @@ gb_internal void print_doc_package(CheckerInfo *info, AstPackage *pkg) {
|
||||
bool show_docs = (build_context.cmd_doc_flags & CmdDocFlag_Short) == 0;
|
||||
|
||||
EntityKind curr_entity_kind = Entity_Invalid;
|
||||
for_array(i, entities) {
|
||||
Entity *e = entities[i];
|
||||
if (e->pkg != pkg) {
|
||||
continue;
|
||||
}
|
||||
if (!is_entity_exported(e)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for (Entity *e : entities) {
|
||||
if (curr_entity_kind != e->kind) {
|
||||
if (curr_entity_kind != Entity_Invalid) {
|
||||
print_doc_line(0, "");
|
||||
@@ -287,7 +283,7 @@ gb_internal void print_doc_package(CheckerInfo *info, AstPackage *pkg) {
|
||||
print_doc_expr(init_expr);
|
||||
}
|
||||
|
||||
gb_printf(";\n");
|
||||
gb_printf("\n");
|
||||
|
||||
if (show_docs) {
|
||||
print_doc_comment_group_string(3, docs);
|
||||
|
||||
+16
-35
@@ -106,42 +106,23 @@ gb_internal void string_to_lower(String *s) {
|
||||
}
|
||||
}
|
||||
|
||||
gb_internal int string_compare(String const &x, String const &y) {
|
||||
if (x.len != y.len || x.text != y.text) {
|
||||
isize n, fast, offset, curr_block;
|
||||
isize *la, *lb;
|
||||
isize pos;
|
||||
|
||||
n = gb_min(x.len, y.len);
|
||||
|
||||
fast = n/gb_size_of(isize) + 1;
|
||||
offset = (fast-1)*gb_size_of(isize);
|
||||
curr_block = 0;
|
||||
if (n <= gb_size_of(isize)) {
|
||||
fast = 0;
|
||||
}
|
||||
|
||||
la = cast(isize *)x.text;
|
||||
lb = cast(isize *)y.text;
|
||||
|
||||
for (; curr_block < fast; curr_block++) {
|
||||
if (la[curr_block] ^ lb[curr_block]) {
|
||||
for (pos = curr_block*gb_size_of(isize); pos < n; pos++) {
|
||||
if (x[pos] ^ y[pos]) {
|
||||
return cast(int)x[pos] - cast(int)y[pos];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (; offset < n; offset++) {
|
||||
if (x[offset] ^ y[offset]) {
|
||||
return cast(int)x[offset] - cast(int)y[offset];
|
||||
}
|
||||
}
|
||||
return cast(int)(x.len - y.len);
|
||||
gb_internal int string_compare(String const &a, String const &b) {
|
||||
if (a.text == b.text) {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
if (a.text == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
if (b.text == nullptr) {
|
||||
return +1;
|
||||
}
|
||||
|
||||
uintptr n = gb_min(a.len, b.len);
|
||||
int res = memcmp(a.text, b.text, n);
|
||||
if (res == 0) {
|
||||
res = cast(int)(a.len - b.len);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
gb_internal isize string_index_byte(String const &s, u8 x) {
|
||||
|
||||
Reference in New Issue
Block a user