mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix to headergen. Updated module name store.
This commit is contained in:
@@ -1154,8 +1154,13 @@ Module *compiler_find_or_create_module(Path *module_name, const char **parameter
|
||||
const char *scratch_buffer_interned(void)
|
||||
{
|
||||
TokenType type = TOKEN_INVALID_TOKEN;
|
||||
return scratch_buffer_interned_as(&type);
|
||||
}
|
||||
|
||||
const char *scratch_buffer_interned_as(TokenType* type)
|
||||
{
|
||||
return symtab_add(scratch_buffer.str, scratch_buffer.len,
|
||||
fnv1a(scratch_buffer.str, scratch_buffer.len), &type);
|
||||
fnv1a(scratch_buffer.str, scratch_buffer.len), type);
|
||||
}
|
||||
|
||||
File *compile_and_invoke(const char *file, const char *args)
|
||||
|
||||
@@ -2408,6 +2408,7 @@ DeclId decltable_get(DeclTable *table, const char *name);
|
||||
void decltable_set(DeclTable *table, Decl *decl);
|
||||
|
||||
const char *scratch_buffer_interned(void);
|
||||
const char *scratch_buffer_interned_as(TokenType *type);
|
||||
|
||||
const char *symtab_preset(const char *data, TokenType type);
|
||||
const char *symtab_add(const char *symbol, uint32_t len, uint32_t fnv1hash, TokenType *type);
|
||||
|
||||
@@ -98,12 +98,11 @@ bool context_set_module_from_filename(ParseContext *context)
|
||||
|
||||
bool context_set_module(ParseContext *context, Path *path, const char **generic_parameters)
|
||||
{
|
||||
// Note that we allow the illegal name for now, to be able to parse further.
|
||||
|
||||
if (!str_has_no_uppercase(path->module))
|
||||
{
|
||||
RETURN_PRINT_ERROR_AT(false, path, "A module name may not have any uppercase characters.");
|
||||
}
|
||||
|
||||
return create_module_or_check_name(context->unit, path, generic_parameters);
|
||||
}
|
||||
|
||||
@@ -263,6 +262,7 @@ ERR:
|
||||
decl_poison(old);
|
||||
}
|
||||
|
||||
|
||||
bool unit_add_import(CompilationUnit *unit, Path *path, bool private_import)
|
||||
{
|
||||
DEBUG_LOG("SEMA: Add import of '%s'.", path->module);
|
||||
|
||||
@@ -41,7 +41,6 @@ static void header_print_type(FILE *file, Type *type)
|
||||
return;
|
||||
}
|
||||
assert(!type_is_optional(type));
|
||||
type = type_flatten_no_export(type);
|
||||
switch (type->type_kind)
|
||||
{
|
||||
case CT_TYPES:
|
||||
@@ -502,12 +501,11 @@ RETRY:
|
||||
Type *underlying_type = decl->enums.type_info->type->canonical;
|
||||
if (underlying_type == type_cint->canonical)
|
||||
{
|
||||
PRINTF("typedef enum %s__ %s;\n", decl_get_extname(decl), decl_get_extname(decl));
|
||||
PRINTF("enum %s__\n{\n", decl_get_extname(decl));
|
||||
PRINTF("typedef enum %s__\n{\n", decl_get_extname(decl));
|
||||
FOREACH_BEGIN(Decl *enum_member, decl->enums.values)
|
||||
PRINTF("\t %s_%s,\n", decl_get_extname(decl), enum_member->name);
|
||||
FOREACH_END();
|
||||
PRINTF("};\n");
|
||||
PRINTF("} %s;\n", decl_get_extname(decl));
|
||||
return;
|
||||
}
|
||||
PRINTF("typedef ");
|
||||
|
||||
@@ -34,6 +34,7 @@ const char *module_create_object_file_name(Module *module)
|
||||
return scratch_buffer_to_string();
|
||||
}
|
||||
|
||||
|
||||
Path *path_create_from_string(const char *string, uint32_t len, SourceSpan span)
|
||||
{
|
||||
assert(string);
|
||||
|
||||
@@ -335,36 +335,29 @@ bool parse_path_prefix(ParseContext *c, Path** path_ref)
|
||||
*path_ref = NULL;
|
||||
if (!tok_is(c, TOKEN_IDENT) || peek(c) != TOKEN_SCOPE) return true;
|
||||
|
||||
char *scratch_ptr = scratch_buffer.str;
|
||||
uint32_t offset = 0;
|
||||
|
||||
Path *path = CALLOCS(Path);
|
||||
path->span = c->span;
|
||||
unsigned len = (unsigned)strlen(symstr(c));
|
||||
memcpy(scratch_ptr, symstr(c), len);
|
||||
offset += len;
|
||||
scratch_buffer_clear();
|
||||
scratch_buffer_append(symstr(c));
|
||||
SourceSpan last_loc = c->span;
|
||||
advance(c);
|
||||
advance(c);
|
||||
while (tok_is(c, TOKEN_IDENT) && peek(c) == TOKEN_SCOPE)
|
||||
{
|
||||
last_loc = c->span;
|
||||
scratch_ptr[offset++] = ':';
|
||||
scratch_ptr[offset++] = ':';
|
||||
len = c->data.lex_len;
|
||||
memcpy(scratch_ptr + offset, symstr(c), len);
|
||||
offset += len;
|
||||
scratch_buffer_append("::");
|
||||
scratch_buffer_append_len(symstr(c), c->data.lex_len);
|
||||
advance(c); advance(c);
|
||||
}
|
||||
|
||||
TokenType type = TOKEN_IDENT;
|
||||
path->span = extend_span_with_token(path->span, last_loc);
|
||||
path->module = symtab_add(scratch_ptr, offset, fnv1a(scratch_ptr, offset), &type);
|
||||
path->module = scratch_buffer_interned_as(&type);
|
||||
if (type != TOKEN_IDENT)
|
||||
{
|
||||
RETURN_PRINT_ERROR_AT(false, path, "A module name was expected here.");
|
||||
}
|
||||
path->len = offset;
|
||||
path->len = scratch_buffer.len;
|
||||
*path_ref = path;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -992,6 +992,7 @@ static void sema_recursively_import(Type *type)
|
||||
FOREACH_BEGIN(Decl *param, decl->enums.parameters)
|
||||
sema_recursively_import(param->type);
|
||||
FOREACH_END();
|
||||
return;
|
||||
case DECL_TYPEDEF:
|
||||
sema_recursively_import(type->canonical);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user