Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion base/auxillary/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Builder builder_open( char const* path )
return result;
}

result.Buffer = strbuilder_make_reserve( _ctx->Allocator_Temp, _ctx->InitSize_BuilderBuffer );
Context* ctx = get_context();
GEN_ASSERT_NOT_NULL(ctx);
result.Buffer = strbuilder_make_reserve( ctx->Allocator_Temp, ctx->InitSize_BuilderBuffer );

// log_fmt("$Builder - Opened file: %s\n", result.File.filename );
return result;
Expand Down
13 changes: 7 additions & 6 deletions base/auxillary/builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ Builder builder_open ( char const* path );
void builder_pad_lines ( Builder* builder, s32 num );
void builder_print ( Builder* builder, Code code );
void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va );
void builder_print_fmt ( Builder* builder, char const* fmt, ... ) {
void builder_write ( Builder* builder );

forceinline void builder_print_fmt ( Builder* builder, char const* fmt, ... ) {
va_list va;
va_start( va, fmt );
builder_print_fmt_va( builder, fmt, va );
va_end( va );
}
void builder_write( Builder* builder );

struct Builder
{
Expand All @@ -56,10 +57,10 @@ struct Builder
};

#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
void builder_pad_lines( Builder& builder, s32 num ) { return builder_pad_lines(& builder, num); }
void builder_print ( Builder& builder, Code code ) { return builder_print(& builder, code); }
void builder_write ( Builder& builder ) { return builder_write(& builder ); }
void builder_print_fmt( Builder& builder, char const* fmt, ...) {
forceinline void builder_pad_lines( Builder& builder, s32 num ) { return builder_pad_lines(& builder, num); }
forceinline void builder_print ( Builder& builder, Code code ) { return builder_print(& builder, code); }
forceinline void builder_write ( Builder& builder ) { return builder_write(& builder ); }
forceinline void builder_print_fmt( Builder& builder, char const* fmt, ...) {
va_list va;
va_start( va, fmt );
builder_print_fmt_va( & builder, fmt, va );
Expand Down
4 changes: 2 additions & 2 deletions base/auxillary/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Code scan_file( char const* path )
GEN_FATAL("scan_file: %s is empty", path );
}

StrBuilder str = strbuilder_make_reserve( _ctx->Allocator_Temp, fsize );
StrBuilder str = strbuilder_make_reserve( get_context()->Allocator_Temp, fsize );
file_read( & file, str, fsize );
strbuilder_get_header(str)->Length = fsize;

Expand Down Expand Up @@ -117,7 +117,7 @@ Code scan_file( char const* path )
}

CodeBody parse_file( const char* path ) {
FileContents file = file_read_contents( _ctx->Allocator_Temp, true, path );
FileContents file = file_read_contents( get_context()->Allocator_Temp, true, path );
Str content = { (char const*)file.data, file.size };
CodeBody code = parse_global_body( content );
log_fmt("\nParsed: %s\n", path);
Expand Down
25 changes: 22 additions & 3 deletions base/components/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Str code_debug_str(Code self)
case CT_Execution:
case CT_Comment:
case CT_PlatformAttributes:
case CT_Preprocess_Define:
case CT_Preprocess_Include:
case CT_Preprocess_Pragma:
case CT_Preprocess_If:
Expand All @@ -52,6 +51,11 @@ Str code_debug_str(Code self)
strbuilder_append_fmt( result, "\n\tContent: %S", self->Content );
break;

case CT_Preprocess_Define:
// TODO(ED): Needs implementaton
log_failure("code_debug_str: NOT IMPLEMENTED for CT_Preprocess_Define");
break;

case CT_Class:
case CT_Struct:
if ( self->Prev )
Expand Down Expand Up @@ -259,6 +263,11 @@ Str code_debug_str(Code self)
strbuilder_append_fmt( result, "\n\tValue : %S", self->Value ? strbuilder_to_str( code_to_strbuilder(self->Value)) : txt("Null") );
break;

case CT_Parameters_Define:
// TODO(ED): Needs implementaton
log_failure("code_debug_str: NOT IMPLEMENTED for CT_Parameters_Define");
break;

case CT_Specifiers:
{
strbuilder_append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
Expand Down Expand Up @@ -497,6 +506,10 @@ void code_to_strbuilder_ptr( Code self, StrBuilder* result )
params_to_strbuilder_ref(cast(CodeParams, self), result );
break;

case CT_Parameters_Define:
define_params_to_strbuilder_ref(cast(CodeDefineParams, self), result);
break;

case CT_Preprocess_Define:
define_to_strbuilder_ref(cast(CodeDefine, self), result );
break;
Expand Down Expand Up @@ -987,11 +1000,17 @@ bool code_is_equal( Code self, Code other )
return true;
}

case CT_Parameters_Define:
{
// TODO(ED): Needs implementaton
log_failure("code_is_equal: NOT IMPLEMENTED for CT_Parameters_Define");
return false;
}

case CT_Preprocess_Define:
{
check_member_str( Name );
check_member_content( Content );

check_member_content( Body->Content );
return true;
}

Expand Down
11 changes: 8 additions & 3 deletions base/components/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct AST_Constructor;
// struct AST_BaseClass;
struct AST_Class;
struct AST_Define;
struct AST_DefineParams;
struct AST_Destructor;
struct AST_Enum;
struct AST_Exec;
Expand Down Expand Up @@ -98,6 +99,7 @@ typedef AST_Comment* CodeComment;
typedef AST_Class* CodeClass;
typedef AST_Constructor* CodeConstructor;
typedef AST_Define* CodeDefine;
typedef AST_DefineParams* CodeDefineParams;
typedef AST_Destructor* CodeDestructor;
typedef AST_Enum* CodeEnum;
typedef AST_Exec* CodeExec;
Expand All @@ -120,6 +122,7 @@ struct CodeComment;
struct CodeClass;
struct CodeConstructor;
struct CodeDefine;
struct CodeDefineParams;
struct CodeDestructor;
struct CodeEnum;
struct CodeExec;
Expand Down Expand Up @@ -305,6 +308,7 @@ struct Code
operator CodeClass() const;
operator CodeConstructor() const;
operator CodeDefine() const;
operator CodeDefineParams() const;
operator CodeDestructor() const;
operator CodeExec() const;
operator CodeEnum() const;
Expand Down Expand Up @@ -365,14 +369,15 @@ int AST_ArrSpecs_Cap =

/*
Simple AST POD with functionality to seralize into C++ syntax.
TODO(Ed): Eventually haven't a transparent AST like this will longer be viable once statements & expressions are in (most likely....)
*/
struct AST
{
union {
struct
{
Code InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
Code Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
Code Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable // TODO(Ed): Parameters can have attributes
Code Specs; // Destructor, Function, Operator, Typename, Variable
union {
Code InitializerList; // Constructor
Expand All @@ -384,12 +389,12 @@ struct AST
union {
Code Macro; // Parameter
Code BitfieldSize; // Variable (Class/Struct Data Member)
Code Params; // Constructor, Function, Operator, Template, Typename
Code Params; // Constructor, Define, Function, Operator, Template, Typename
Code UnderlyingTypeMacro; // Enum
};
union {
Code ArrExpr; // Typename
Code Body; // Class, Constructor, Destructor, Enum, Friend, Function, Namespace, Struct, Union
Code Body; // Class, Constructor, Define, Destructor, Enum, Friend, Function, Namespace, Struct, Union
Code Declaration; // Friend, Template
Code Value; // Parameter, Variable
};
Expand Down
32 changes: 28 additions & 4 deletions base/components/ast_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ struct AST_Body
};
static_assert( sizeof(AST_Body) == sizeof(AST), "ERROR: AST_Body is not the same size as AST");

// TODO(Ed): Support chaining attributes (Use parameter linkage pattern)
struct AST_Attributes
{
union {
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
StrCached Content;
};
StrCached Name;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
Expand Down Expand Up @@ -146,9 +147,15 @@ struct AST_Define
{
union {
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
StrCached Content;
struct
{
char _PAD_PROPERTIES_ [ sizeof(AST*) * 4 ];
CodeDefineParams Params;
Code Body; // Should be completely serialized for now to a: StrCached Content.
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 1 ];
};
};
StrCached Name;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
Expand All @@ -158,6 +165,22 @@ struct AST_Define
};
static_assert( sizeof(AST_Define) == sizeof(AST), "ERROR: AST_Define is not the same size as AST");

struct AST_DefineParams
{
union {
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
};
StrCached Name;
CodeDefineParams Last;
CodeDefineParams Next;
Token* Tok;
Code Parent;
CodeType Type;
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
s32 NumEntries;
};
static_assert( sizeof(AST_DefineParams) == sizeof(AST), "ERROR: AST_DefineParams is not the same size as AST");

struct AST_Destructor
{
union {
Expand Down Expand Up @@ -660,6 +683,7 @@ struct AST_Params
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct
{
// TODO(Ed): Support attributes for parameters (Some prefix macros can be converted to that...)
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
CodeTypename ValueType;
Code Macro;
Expand All @@ -668,7 +692,7 @@ struct AST_Params
// char _PAD_PROPERTIES_3_[sizeof( AST* )];
};
};
StrCached Name;
StrCached Name;
CodeParams Last;
CodeParams Next;
Token* Tok;
Expand Down
Loading