Skip to content

Commit 4b413db

Browse files
committed
Cleaner. Better.
1 parent 80679fd commit 4b413db

File tree

6 files changed

+54
-46
lines changed

6 files changed

+54
-46
lines changed

parser/metac_parser.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,15 +1776,16 @@ metac_decl_t* MetaCParser_ParseDecl(metac_parser_t* self, metac_decl_t* parent)
17761776

17771777
decl_type_t* type = 0;
17781778

1779-
#if !defined(NO_PREPROCESSOR) && 0
1780-
decl_preproc_t* preProcDecl = AllocNewDecl(decl_preproc, &result);
1781-
preProcDecl->DirectiveKind = pp_invalid;
1779+
#if !defined(NO_PREPROCESSOR)
1780+
// decl_preproc_t* preProcDecl = AllocNewDecl(decl_preproc, &result);
1781+
// preProcDecl->DirectiveKind = pp_invalid;
17821782

17831783
if (MetaCParser_PeekMatch(self, tok_hash, 1))
17841784
{
17851785
metac_preprocessor_directive_t dirc =
17861786
MetaCParser_ParsePreprocDirective(self, self->Preprocessor);
1787-
preProcDecl->DirectiveKind = dirc;
1787+
// preProcDecl->DirectiveKind = dirc;
1788+
result = cast(metac_decl_t*) emptyNode;
17881789

17891790
if (dirc == pp_include)
17901791
{
@@ -1794,7 +1795,7 @@ metac_decl_t* MetaCParser_ParseDecl(metac_parser_t* self, metac_decl_t* parent)
17941795
{
17951796
metac_preprocessor_define_ptr_t definePtr =
17961797
MetaCPreProcessor_ParseDefine(self->Preprocessor, self);
1797-
preProcDecl->DefinePtr = definePtr;
1798+
// preProcDecl->DefinePtr = definePtr;
17981799
}
17991800
else if (dirc == pp_ifdef)
18001801
{

repl/repl.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,41 +84,41 @@ static inline int TranslateIdentifiers(metac_node_t node, void* ctx)
8484
{
8585
case decl_variable:
8686
{
87-
decl_variable_t* var = (decl_variable_t*) node;
87+
decl_variable_t* var = cast(decl_variable_t*) node;
8888
if (var->VarIdentifier.v && var->VarIdentifier.v != empty_identifier.v)
8989
TranslateIdentifier(DstTable, SrcTable, &var->VarIdentifier);
9090
} break;
9191
case decl_function:
9292
{
93-
decl_function_t* func = (decl_function_t*) node;
93+
decl_function_t* func = cast(decl_function_t*) node;
9494
if (func->Identifier.v != empty_identifier.v)
9595
TranslateIdentifier(DstTable, SrcTable, &func->Identifier);
9696
} break;
9797
case decl_type:
9898
{
99-
decl_type_t* type = (decl_type_t*) node;
99+
decl_type_t* type = cast(decl_type_t*) node;
100100
if (type->TypeIdentifier.v && type->TypeIdentifier.v != empty_identifier.v)
101101
TranslateIdentifier(DstTable, SrcTable, &type->TypeIdentifier);
102102
} break;
103103
case decl_type_typedef:
104104
{
105-
decl_type_typedef_t* typedef_ = (decl_type_typedef_t*) node;
105+
decl_type_typedef_t* typedef_ = cast(decl_type_typedef_t*) node;
106106
if (typedef_->Identifier.v != empty_identifier.v)
107107
{
108108
TranslateIdentifier(DstTable, SrcTable, &typedef_->Identifier);
109109
}
110110
} break;
111111
case decl_type_struct:
112112
{
113-
decl_type_struct_t* struct_ = (decl_type_struct_t*) node;
113+
decl_type_struct_t* struct_ = cast(decl_type_struct_t*) node;
114114
if (struct_->BaseIdentifier.v != empty_identifier.v)
115115
TranslateIdentifier(DstTable, SrcTable, &struct_->BaseIdentifier);
116116
if (struct_->Identifier.v != empty_identifier.v)
117117
TranslateIdentifier(DstTable, SrcTable, &struct_->Identifier);
118118
} break;
119119
case decl_type_enum:
120120
{
121-
decl_type_enum_t* enum_ = (decl_type_enum_t*) node;
121+
decl_type_enum_t* enum_ = cast(decl_type_enum_t*) node;
122122
if (enum_->Identifier.v != empty_identifier.v)
123123
{
124124
TranslateIdentifier(DstTable, SrcTable, &enum_->Identifier);
@@ -127,7 +127,7 @@ static inline int TranslateIdentifiers(metac_node_t node, void* ctx)
127127
/*
128128
case decl_type_functiontype:
129129
{
130-
decl_type_functiontype_t* funcionType = (decl_type_functiontype_t*) node;
130+
decl_type_functiontype_t* funcionType = cast(decl_type_functiontype_t*) node;
131131
if (funcionType->Identifier.v != empty_identifier.v)
132132
{
133133
TranslateIdentifier(DstTable, SrcTable, &enum_->Identifier);
@@ -136,7 +136,7 @@ static inline int TranslateIdentifiers(metac_node_t node, void* ctx)
136136
*/
137137
case decl_enum_member:
138138
{
139-
decl_enum_member_t* enumMember = (decl_enum_member_t*) node;
139+
decl_enum_member_t* enumMember = cast(decl_enum_member_t*) node;
140140
if (enumMember->Name.v != empty_identifier.v)
141141
{
142142
TranslateIdentifier(DstTable, SrcTable, &enumMember->Name);
@@ -225,7 +225,7 @@ static inline int Presemantic(metac_node_t node, void* ctx)
225225

226226
if (node->Kind == node_decl_type_typedef)
227227
{
228-
decl_type_typedef_t* typedef_ = (decl_type_typedef_t*) node;
228+
decl_type_typedef_t* typedef_ = cast(decl_type_typedef_t*) node;
229229
metac_identifier_ptr_t typedefId = typedef_->Identifier;
230230

231231
metac_type_index_t typeIndex =
@@ -261,7 +261,7 @@ void SeeIdentifier(const char* idStr, uint32_t key, repl_state_t* replCtx)
261261

262262
void AddIdentifierToCompletion(repl_state_t* self, const char* idString)
263263
{
264-
uint32_t len = (uint32_t) strlen(idString);
264+
uint32_t len = cast(uint32_t) strlen(idString);
265265
uint32_t hash = crc32c(~0, idString, len);
266266
uint32_t key = IDENTIFIER_KEY(hash, len);
267267
SeeIdentifier(idString, key, self);
@@ -300,7 +300,7 @@ void Presemantic_(repl_state_t* self)
300300
#if 1
301301
{
302302
identifier_callback_t cb;
303-
cb.Ctx = (void*)self;
303+
cb.Ctx = cast(void*)self;
304304
cb.FuncP = cast(identifier_cb_t)&SeeIdentifier;
305305
tmpLpp.Parser.IdentifierCallbacks[0] = cb;
306306
tmpLpp.Parser.IdentifierCallbacksCount = 1;
@@ -352,22 +352,22 @@ void Presemantic_(repl_state_t* self)
352352

353353
if (decl->Kind == decl_type_typedef)
354354
{
355-
decl_type_typedef_t* typedef_ = (decl_type_typedef_t*) decl;
355+
decl_type_typedef_t* typedef_ = cast(decl_type_typedef_t*) decl;
356356
if (typedef_->Type->Kind == decl_type_struct)
357357
{
358-
decl_type_struct_t* structPtr = (decl_type_struct_t*)typedef_->Type;
358+
decl_type_struct_t* structPtr = cast(decl_type_struct_t*)typedef_->Type;
359359
if (structPtr->Identifier.v == empty_identifier.v)
360360
{
361361
printIdentifier = typedef_->Identifier;
362362
}
363-
decl = (metac_decl_t*)typedef_->Type;
363+
decl = cast(metac_decl_t*)typedef_->Type;
364364
}
365365
}
366366

367367
if (decl->Kind == decl_type_struct)
368368
{
369369
const char* structNameStr = 0;
370-
decl_type_struct_t* struct_ = (decl_type_struct_t*) decl;
370+
decl_type_struct_t* struct_ = cast(decl_type_struct_t*) decl;
371371
metac_printer_t printer;
372372

373373
MetaCPrinter_Init(&printer,
@@ -389,7 +389,7 @@ void Presemantic_(repl_state_t* self)
389389
&& printIdentifier.v != empty_identifier.v
390390
&& 0 == strcmp("metac_compiler_t", structNameStr))
391391
{
392-
compilerStruct = (metac_type_aggregate_t*)
392+
compilerStruct = cast(metac_type_aggregate_t*)
393393
MetaCSemantic_doDeclSemantic(&self->SemanticState, struct_);
394394
// xprintf("compilerStruct: %s\n",
395395
// MetaCPrinter_PrintSemaNode(&printer, &self->SemanticState, cast(metac_node_t)compilerStruct));
@@ -701,20 +701,20 @@ bool Repl_Loop(repl_state_t* repl, repl_ui_context_t* context)
701701
uint32_t estimatedTokenCount = (((sz / 4) + 128) & ~127);
702702
if (fileLexer->TokenCapacity < estimatedTokenCount)
703703
{
704-
fileLexer->Tokens = (metac_token_t*)
704+
fileLexer->Tokens = cast(metac_token_t*)
705705
malloc(sizeof(metac_token_t) * estimatedTokenCount);
706706
fileLexer->TokenCount = 0;
707707
fileLexer->TokenCapacity = estimatedTokenCount;
708-
fileLexer->Tokens = (metac_token_t*)
708+
fileLexer->Tokens = cast(metac_token_t*)
709709
malloc(sizeof(metac_token_t) * estimatedTokenCount);
710710

711-
fileLexer->LocationStorage.Locations = (metac_location_t*)
711+
fileLexer->LocationStorage.Locations = cast(metac_location_t*)
712712
malloc(sizeof(metac_location_t) * estimatedTokenCount);
713713
fileLexer->LocationStorage.LocationSize = 0;
714714
fileLexer->LocationStorage.LocationCapacity = estimatedTokenCount;
715715
}
716-
repl->SrcBuffer = (char*)calloc(1, sz + 4);
717-
repl->FreePtr = (void*)repl->SrcBuffer;
716+
repl->SrcBuffer = cast(char*)calloc(1, sz + 4);
717+
repl->FreePtr = cast(void*)repl->SrcBuffer;
718718
repl->SrcBufferLength = sz;
719719
fread((void*)repl->SrcBuffer, 1, sz, fd);
720720
repl->ParseMode = repl_mode_lex_file;
@@ -896,7 +896,7 @@ bool Repl_Loop(repl_state_t* repl, repl_ui_context_t* context)
896896

897897
if (repl->ParseMode != repl_mode_lex_file)
898898
{
899-
repl->SrcBuffer = (char*)repl->Line;
899+
repl->SrcBuffer = cast(char*)repl->Line;
900900
repl->SrcBufferLength = line_length;
901901
}
902902

@@ -1415,7 +1415,7 @@ void Repl_Fiber(void)
14151415

14161416
{
14171417
identifier_callback_t cb;
1418-
cb.Ctx = (void*)repl;
1418+
cb.Ctx = cast(void*)repl;
14191419
cb.FuncP = cast(identifier_cb_t)&SeeIdentifier;
14201420
repl->LPP.Parser.IdentifierCallbacks[0] = cb;
14211421
repl->LPP.Parser.IdentifierCallbacksCount = 1;
@@ -1437,7 +1437,7 @@ void Repl_Fiber(void)
14371437
while (Repl_Loop(repl, uiContext) != false)
14381438
{
14391439
#ifndef NO_FIBERS
1440-
task_t* replTask = (task_t*)(GET_CO()->arg);
1440+
task_t* replTask = cast(task_t*)(GET_CO()->arg);
14411441
YIELD(ReplYield);
14421442
#endif
14431443
}

semantic/metac_expr_semantic.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ void ResolveIdentifierToExp(metac_sema_state_t* self,
438438

439439
if (node->Kind == (metac_node_kind_t)expr_identifier)
440440
{
441-
xfprintf(stderr, "we should not be retured an identifier\n");
441+
xfprintf(stderr, "we should not be returned an identifier\n");
442442
}
443443
else if (node->Kind == node_decl_variable ||
444444
node->Kind == node_decl_parameter)
@@ -471,7 +471,7 @@ void ResolveIdentifierToExp(metac_sema_state_t* self,
471471
result->TypeExp.v =
472472
TYPE_INDEX_V(type_index_struct, StructIndex(self, t_agg));
473473
result->TypeIndex.v = TYPE_INDEX_V(type_index_basic, type_type);
474-
// hash = t_agg->Hash; ? where is hash
474+
hash = t_agg->Header.Hash;
475475
}
476476
else if (node->Kind == node_decl_type_typedef)
477477
{
@@ -480,7 +480,7 @@ void ResolveIdentifierToExp(metac_sema_state_t* self,
480480
result->TypeExp.v =
481481
TYPE_INDEX_V(type_index_typedef, TypedefIndex(self, t_def));
482482
result->TypeIndex.v = TYPE_INDEX_V(type_index_basic, type_type);
483-
// hash = t_def->Hash; // where is hash
483+
hash = t_def->Header.Hash;
484484
}
485485
else if (node->Kind == node_decl_function)
486486
{
@@ -930,9 +930,10 @@ metac_sema_expr_t* MetaCSemantic_doExprSemantic_(metac_sema_state_t* self,
930930
hash = CRC32C_VALUE(hash, E1->Hash);
931931

932932
if (result->E1->Kind == expr_unknown_value)
933+
{
933934
result->Kind = expr_unknown_value;
935+
}
934936

935-
//result->Kind = expr_paren;
936937
result->TypeIndex = E1->TypeIndex;
937938
result->E1 = E1;
938939
} break;
@@ -953,22 +954,29 @@ metac_sema_expr_t* MetaCSemantic_doExprSemantic_(metac_sema_state_t* self,
953954
if (castType.v == 0 || castExp->Kind == expr_unknown_value)
954955
result->Kind = expr_unknown_value;
955956
} break;
957+
956958
#define CASE(M) \
957959
case M:
960+
958961
FOREACH_BIN_ARITH_EXP(CASE)
959962
case expr_ternary:
960963
if (result->E1->Kind == expr_unknown_value || result->E2->Kind == expr_unknown_value)
964+
{
961965
result->Kind = expr_unknown_value;
966+
}
962967

963968
result->TypeIndex =
964969
MetaCSemantic_CommonSubtype(self, result->E1->TypeIndex, result->E2->TypeIndex);
965970
break;
971+
966972
FOREACH_BIN_ARITH_ASSIGN_EXP(CASE)
967973
if (result->E1->Kind == expr_unknown_value)
968974
result->Kind = expr_unknown_value;
969975
result->TypeIndex = result->E1->TypeIndex;
970976
break;
977+
971978
#undef CASE
979+
972980
case expr_index:
973981
result = MetaCSemantic_doIndexSemantic(self, expr);
974982
break;
@@ -1224,12 +1232,12 @@ metac_sema_expr_t* MetaCSemantic_doExprSemantic_(metac_sema_state_t* self,
12241232
}
12251233
}
12261234
// type ptrs can also be binary expressions
1227-
else if (expr->TypeExp->TypeKind == type_ptr)
1235+
else if (typeExpr->TypeKind == type_ptr)
12281236
{
12291237

12301238
}
12311239
// and so can type-arrays
1232-
else if (expr->TypeExp->TypeKind == type_array)
1240+
else if (typeExpr->TypeKind == type_array)
12331241
{
12341242

12351243
}

semantic/metac_type_semantic.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ void MetaCSemantic_ComputeEnumValues(metac_sema_state_t* self,
786786
inject code;
787787
self->AllowOverride = oldAllowOverride;
788788
}
789-
*/
789+
*/
790790
// Set the currentScope to be an override scope
791791
// Since we are inserting members
792792
bool oldAllowOverride = self->CurrentScope->ScopeTable.AllowOverride;
@@ -1190,7 +1190,7 @@ metac_type_index_t MetaCSemantic_TypeSemantic(metac_sema_state_t* self,
11901190
decl_parameter_t* param = agg->Parameters;
11911191
U32(tmpTemplateScope.ScopeFlags) |= scope_flag_temporary;
11921192
MetaCSemantic_PushTemporaryScope(self, &tmpTemplateScope);
1193-
1193+
11941194
for(uint32_t paramIdx = 0; paramIdx < parameterCount; paramIdx++)
11951195
{
11961196
metac_identifier_ptr_t paramIdent = param->Parameter->VarIdentifier;
@@ -1374,8 +1374,8 @@ metac_type_index_t MetaCSemantic_TypeSemantic(metac_sema_state_t* self,
13741374
{
13751375
assert(!"Only identifier types and template types are expected to be resovled here");
13761376
}
1377-
xprintf("MetaCNodeKind_toChars: %s\n", MetaCNodeKind_toChars((metac_node_kind_t)type->Kind));
1378-
xprintf("TypeIdentifier: %s\n", IdentifierPtrToCharPtr(self->ParserIdentifierTable, type->TypeIdentifier));
1377+
// xprintf("MetaCNodeKind_toChars: %s\n", MetaCNodeKind_toChars((metac_node_kind_t)type->Kind));
1378+
// xprintf("TypeIdentifier: %s\n", IdentifierPtrToCharPtr(self->ParserIdentifierTable, type->TypeIdentifier));
13791379
LtryAgian: {}
13801380
metac_node_t node =
13811381
MetaCSemantic_LookupIdentifier(self, type->TypeIdentifier);
@@ -1405,15 +1405,14 @@ LtryAgian: {}
14051405
#endif
14061406
aco_t* me = (aco_t*)CurrentFiber();
14071407
task_t* task = CurrentTask();
1408-
printf("Yield!\n");
1408+
14091409
metac_semantic_waiter_t* meWaiter = &self->Waiters.Waiters[INC(self->Waiters.WaiterCount)];
14101410
meWaiter->FuncHash = CRC32C_S("MetaCSemantic_LookupIdentifier");
14111411
meWaiter->NodeHash = CRC32C_VALUE(~0, type->TypeIdentifier);
14121412
meWaiter->Continuation = me;
14131413
U32(task->TaskFlags) |= Task_Waiting;
14141414
U32(task->TaskFlags) &= (~Task_Running);
14151415
YIELD(WaitOnResolve);
1416-
printf("Trying agian after yielding\n");
14171416
goto LtryAgian;
14181417
#else
14191418
printf("No fiber support ... cannot deal with deferred lookup\n");
@@ -1652,7 +1651,8 @@ bool MetaCSemantic_ComputeStructLayout(metac_sema_state_t* self,
16521651
{
16531652
bool result = true;
16541653

1655-
assert(self->CurrentScope == semaAgg->Scope || ((self->CurrentScope->ScopeFlags & scope_flag_temporary) && self->CurrentScope->Parent == semaAgg->Scope) );
1654+
assert(self->CurrentScope == semaAgg->Scope ||
1655+
((self->CurrentScope->ScopeFlags & scope_flag_temporary) && self->CurrentScope->Parent == semaAgg->Scope) );
16561656
// make sure the scope is mounted.
16571657
assert(semaAgg->Fields && semaAgg->Fields != emptyPointer);
16581658

utils/identifier_hash.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ void print_case_for(const char* id)
1010
uint32_t len = strlen(id);
1111
uint32_t crc32 =
1212
crc32c(~0, id, len);
13-
uint32_t identifier_hash =
14-
( IDENTIFIER_KEY( crc32, len ) );
13+
uint32_t identifier_hash = IDENTIFIER_KEY(crc32, len);
1514
printf("bool Is%s(metac_token_t token)", id);
1615
printf("{\n");
17-
printf(" return (token->identifierHash == 0x%x) &&\n",
16+
printf(" return (token->IdentifierHash == 0x%x) &&\n",
1817
identifier_hash);
1918
printf(" && (!memcmp(identifier, \"%s\", %u) )\n", id, len);
2019
printf("}\n\n");

utils/metac_count_token_length.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int main(int argc, char* argv[])
1515

1616
void CountTokenLengths()
1717
{
18-
uint32_t token_len[10] = {0};
18+
uint32_t token_len[16] = {0};
1919

2020
#define TOK_SELF(TOK) \
2121
TOK

0 commit comments

Comments
 (0)