Skip to content

Commit

Permalink
[compiler] Generated documentation for structs now contains name of b…
Browse files Browse the repository at this point in the history
…ase struct.
  • Loading branch information
travisdoor committed Feb 8, 2025
1 parent 60cc55e commit ee4ed47
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Compiler:
- Compile-time test run when '--run-tests' is used now outputs ANSI colored reports, this
might by disabled by passing '--no-color' argument to the compiler.
- Fix 'blc -init' to produce compilable 'src/main.bl'.
- Generated documentation for structs now contains name of base struct.

Modules:
- Add math module.
Expand Down
1 change: 1 addition & 0 deletions src/clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find . -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.h" \) -exec clang-format -i {} +
14 changes: 10 additions & 4 deletions src/docs.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,19 @@ void doc_type_enum(struct context *ctx, struct ast *type) {
}

void doc_type_struct(struct context *ctx, struct ast *type) {
if (!ctx->is_multi_return)
if (type->data.type_strct.is_union)
if (!ctx->is_multi_return) {
if (type->data.type_strct.is_union) {
fprintf(ctx->stream, "union {");
else
} else if (type->data.type_strct.base_type) {
struct ast *base_ident = type->data.type_strct.base_type->data.ref.ident;
const str_t base_name = base_ident ? base_ident->data.ident.id.str : make_str_from_c("UNKNOWN");
fprintf(ctx->stream, "struct #base " STR_FMT " {", STR_ARG(base_name));
} else {
fprintf(ctx->stream, "struct {");
else
}
} else {
fprintf(ctx->stream, "(");
}

ctx->indentation += 1;
ast_nodes_t *members = type->data.type_strct.members;
Expand Down
4 changes: 2 additions & 2 deletions src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ bool scan_char(struct context *ctx, struct token *tok) {
++ctx->c; // Eat backslash.
++tok->location.len;
tok->value_index = add_token_value(ctx, (union token_value){
.character = scan_specch(ctx, &tok->location.len),
});
.character = scan_specch(ctx, &tok->location.len),
});
break;
default:
tok->value_index = add_token_value(ctx, (union token_value){.character = *ctx->c});
Expand Down
4 changes: 0 additions & 4 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
TODO:

- 'blc --init' does not compile there is missing '#import "std/print".
- Documentation generated struct types miss base type.
- Add also link to source file on github.

- Use #run to mark function to be executed in compile time on the call side: '#run foo()'.
- Use #run to mark function executed only in compile time on the declaration side: 'foo :: fn () #run {}'.
- Consider #import and #load to be limited only to the file scope.
Expand Down

0 comments on commit ee4ed47

Please sign in to comment.