2023-08-28 20:46:50 -07:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
2023-08-21 17:30:13 -07:00
|
|
|
#pragma once
|
2023-08-21 20:02:20 -07:00
|
|
|
#include "interface.hpp"
|
2023-08-28 20:46:50 -07:00
|
|
|
#endif
|
2023-08-21 17:30:13 -07:00
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
void AST::append( AST* other )
|
|
|
|
{
|
|
|
|
if ( other->Parent )
|
|
|
|
other = other->duplicate();
|
|
|
|
|
|
|
|
other->Parent = this;
|
|
|
|
|
|
|
|
if ( Front == nullptr )
|
|
|
|
{
|
|
|
|
Front = other;
|
|
|
|
Back = other;
|
|
|
|
|
|
|
|
NumEntries++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST*
|
|
|
|
Current = Back;
|
|
|
|
Current->Next = other;
|
|
|
|
other->Prev = Current;
|
|
|
|
Back = other;
|
|
|
|
NumEntries++;
|
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
Code& AST::entry( u32 idx )
|
|
|
|
{
|
|
|
|
AST** current = & Front;
|
|
|
|
while ( idx >= 0 && current != nullptr )
|
|
|
|
{
|
|
|
|
if ( idx == 0 )
|
|
|
|
return * rcast( Code*, current);
|
|
|
|
|
|
|
|
current = & ( * current )->Next;
|
|
|
|
idx--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return * rcast( Code*, current);
|
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
bool AST::has_entries()
|
|
|
|
{
|
2024-10-24 22:04:17 -07:00
|
|
|
return NumEntries > 0;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
char const* AST::type_str()
|
|
|
|
{
|
|
|
|
return ECode::to_str( Type );
|
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
AST::operator Code()
|
|
|
|
{
|
|
|
|
return { this };
|
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
Code& Code::operator ++()
|
|
|
|
{
|
|
|
|
if ( ast )
|
|
|
|
ast = ast->Next;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
void CodeClass::add_interface( CodeType type )
|
|
|
|
{
|
2023-09-06 00:06:30 -07:00
|
|
|
CodeType possible_slot = ast->ParentType;
|
|
|
|
if ( possible_slot.ast )
|
2023-08-03 08:01:43 -07:00
|
|
|
{
|
2023-09-06 00:06:30 -07:00
|
|
|
// Were adding an interface to parent type, so we need to make sure the parent type is public.
|
|
|
|
ast->ParentAccess = AccessSpec::Public;
|
|
|
|
// If your planning on adding a proper parent,
|
|
|
|
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( possible_slot.ast != nullptr )
|
|
|
|
{
|
|
|
|
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
|
2023-09-06 00:06:30 -07:00
|
|
|
possible_slot.ast = type.ast;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
void CodeParam::append( CodeParam other )
|
|
|
|
{
|
|
|
|
AST* self = (AST*) ast;
|
|
|
|
AST* entry = (AST*) other.ast;
|
|
|
|
|
|
|
|
if ( entry->Parent )
|
|
|
|
entry = entry->duplicate();
|
|
|
|
|
|
|
|
entry->Parent = self;
|
|
|
|
|
|
|
|
if ( self->Last == nullptr )
|
|
|
|
{
|
|
|
|
self->Last = entry;
|
|
|
|
self->Next = entry;
|
|
|
|
self->NumEntries++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->Last->Next = entry;
|
|
|
|
self->Last = entry;
|
|
|
|
self->NumEntries++;
|
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
CodeParam CodeParam::get( s32 idx )
|
|
|
|
{
|
|
|
|
CodeParam param = *this;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ( ! ++ param )
|
|
|
|
return { nullptr };
|
|
|
|
|
2024-10-25 02:01:37 -07:00
|
|
|
param = { (AST_Param*) param.raw()->Next };
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
while ( --idx );
|
|
|
|
|
2024-10-25 02:01:37 -07:00
|
|
|
return param;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
bool CodeParam::has_entries()
|
|
|
|
{
|
|
|
|
return ast->NumEntries > 0;
|
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
CodeParam& CodeParam::operator ++()
|
|
|
|
{
|
|
|
|
ast = ast->Next.ast;
|
|
|
|
return * this;
|
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
void CodeStruct::add_interface( CodeType type )
|
|
|
|
{
|
2023-09-06 00:06:30 -07:00
|
|
|
CodeType possible_slot = ast->ParentType;
|
|
|
|
if ( possible_slot.ast )
|
|
|
|
{
|
|
|
|
// Were adding an interface to parent type, so we need to make sure the parent type is public.
|
|
|
|
ast->ParentAccess = AccessSpec::Public;
|
|
|
|
// If your planning on adding a proper parent,
|
|
|
|
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( possible_slot.ast != nullptr )
|
2023-08-03 08:01:43 -07:00
|
|
|
{
|
2023-09-06 00:06:30 -07:00
|
|
|
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
|
2023-09-06 00:06:30 -07:00
|
|
|
possible_slot.ast = type.ast;
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-03 08:01:43 -07:00
|
|
|
CodeBody def_body( CodeT type )
|
|
|
|
{
|
|
|
|
switch ( type )
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
case Class_Body:
|
|
|
|
case Enum_Body:
|
|
|
|
case Export_Body:
|
|
|
|
case Extern_Linkage:
|
|
|
|
case Function_Body:
|
|
|
|
case Global_Body:
|
|
|
|
case Namespace_Body:
|
|
|
|
case Struct_Body:
|
|
|
|
case Union_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
log_failure( "def_body: Invalid type %s", (char const*)ECode::to_str(type) );
|
|
|
|
return (CodeBody)Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Type = type;
|
|
|
|
return (CodeBody)result;
|
|
|
|
}
|
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2024-10-27 15:58:37 -07:00
|
|
|
StrC token_fmt_impl( ssize num, ... )
|
2023-08-03 08:01:43 -07:00
|
|
|
{
|
|
|
|
local_persist thread_local
|
|
|
|
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
|
|
|
mem_set( buf, 0, GEN_PRINTF_MAXLEN );
|
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num );
|
2024-10-27 15:58:37 -07:00
|
|
|
ssize result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
|
2023-08-03 08:01:43 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return { result, buf };
|
|
|
|
}
|