dependency impl compiles for C11 library (doing components next)

This commit is contained in:
2024-12-08 20:00:16 -05:00
parent 65c3fabc52
commit 12e31276eb
12 changed files with 194 additions and 10 deletions

View File

@ -384,7 +384,10 @@ struct AST
ModuleFlag ModuleFlags;
union {
b32 IsFunction; // Used by typedef to not serialize the name field.
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
struct {
b16 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
ETypenameTag TypeTag; // Used by typename to keep track of explicitly declared tags for the identifier (enum, struct, union)
};
Operator Op;
AccessSpec ParentAccess;
s32 NumEntries;

View File

@ -1017,6 +1017,7 @@ struct AST_Type
static_assert( sizeof(AST_Type) == sizeof(AST), "ERROR: AST_Type is not the same size as AST");
#endif
// TODO(Ed): Add support for preserving the typename's keyword qualifier (struct, class, enum, etc), mostly needed for C.
struct AST_Typename
{
union {
@ -1039,7 +1040,10 @@ struct AST_Typename
Code Parent;
CodeType Type;
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
b32 IsParamPack;
struct {
b16 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
ETypenameTag TypeTag; // Used by typename to keep track of explicitly declared tags for the identifier (enum, struct, union)
};
};
static_assert( sizeof(AST_Typename) == sizeof(AST), "ERROR: AST_Type is not the same size as AST");

View File

@ -1194,6 +1194,16 @@ void typename_to_string_ref(CodeTypename self, String* result )
if ( self->Attributes )
string_append_fmt( result, "%S ", attributes_to_string(self->Attributes) );
switch ( self->TypeTag )
{
case Tag_Class : string_append_strc( result, txt("class ")); break;
case Tag_Enum : string_append_strc( result, txt("enum ")); break;
case Tag_Struct : string_append_strc( result, txt("struct ")); break;
case Tag_Union : string_append_strc( result, txt("union ")); break;
default:
break;
}
if ( self->Specs )
string_append_fmt( result, "%SC %S", self->Name, specifiers_to_string(self->Specs) );
else

View File

@ -138,6 +138,7 @@ struct Opts_def_template { ModuleFlag mflags; };
CodeTemplate def_template( CodeParam params, Code definition, Opts_def_template opts GEN_PARAM_DEFAULT );
struct Opts_def_type {
ETypenameTag type_tag;
Code arrayexpr;
CodeSpecifiers specifiers;
CodeAttributes attributes;

View File

@ -1303,6 +1303,8 @@ CodeTypename def_type( StrC name, Opts_def_type p )
if ( arrayexpr )
result->ArrExpr = arrayexpr;
result->TypeTag = p.type_tag;
return result;
}

View File

@ -4523,9 +4523,11 @@ CodeTypename parse_type( bool from_template, bool* typedef_is_function )
Token context_tok = prevtok;
Specifier specs_found[ 16 ] { Spec_NumSpecifiers };
s32 NumSpecifiers = 0;
s32 NumSpecifiers = 0;
Token name = { nullptr, 0, Tok_Invalid };
Token name= { nullptr, 0, Tok_Invalid };
ETypenameTag tag = Tag_None;
// Attributes are assumed to be before the type signature
CodeAttributes attributes = parse_attributes();
@ -4568,6 +4570,14 @@ CodeTypename parse_type( bool from_template, bool* typedef_is_function )
else if ( currtok.Type == Tok_Decl_Class || currtok.Type == Tok_Decl_Enum || currtok.Type == Tok_Decl_Struct
|| currtok.Type == Tok_Decl_Union )
{
switch (currtok.Type) {
case Tok_Decl_Class : tag = Tag_Class; break;
case Tok_Decl_Enum : tag = Tag_Enum; break;
case Tok_Decl_Struct : tag = Tag_Struct; break;
case Tok_Decl_Union : tag = Tag_Union; break;
default:
break;
}
eat( currtok.Type );
// <Attributes> <Specifiers> <class, enum, struct, union>
@ -4950,6 +4960,8 @@ else if ( currtok.Type == Tok_DeclType )
if ( params )
result->Params = params;
result->TypeTag = tag;
pop(& Context);
return result;
}

View File

@ -123,3 +123,15 @@ enum EPreprocessCond : u32
EPreprocessCond_SizeDef = GEN_U32_MAX,
};
static_assert( size_of(EPreprocessCond) == size_of(u32), "EPreprocessCond not u32 size" );
enum ETypenameTag : u16
{
Tag_None,
Tag_Class,
Tag_Enum,
Tag_Struct,
Tag_Union,
Tag_UnderlyingType = GEN_U16_MAX,
};
static_assert( size_of(ETypenameTag) == size_of(u16), "ETypenameTag is not u16 size");

View File

@ -24,7 +24,7 @@ u8 adt_make_branch( ADT_Node* node, AllocatorInfo backing, char const* name, b32
node->type = type;
node->name = name;
node->parent = parent;
node->nodes = array_init<ADT_Node>( backing );
node->nodes = array_init(ADT_Node, backing );
if ( ! node->nodes )
return EADT_ERROR_OUT_OF_MEMORY;

View File

@ -349,7 +349,7 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
return result;
}
CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
CodeBody gen_etoktype( char const* etok_path, char const* attr_path, bool use_c_definition = false )
{
char scratch_mem[kilobytes(16)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );