@@ -598,42 +598,39 @@ void PopulateTemporaryAggregateScope(metac_sema_state_t* self,
598598 AllocateAggregateScopeAndFields (& self -> TempAlloc , nFields );
599599
600600 metac_type_aggregate_field_t * fields = scopeAndFields .Fields ;
601-
602- // ??? do we want to the the parent like this?
603- // scopeAndFields.Scope->Parent = self->CurrentScope;
604- // or do we want the aggregate scope to exist in isolation ...
605- // I think we want it in isolation.
601+ decl_field_t * aggField = agg -> Fields ;
606602
607603 tmpSemaAgg -> Scope = scopeAndFields .Scope ;
608604 tmpSemaAgg -> Fields = fields ;
609605 tmpSemaAgg -> FieldCount = nFields ;
610- decl_field_t * aggField = agg -> Fields ;
611606
612607 MetaCSemantic_MountScope (self , tmpSemaAgg -> Scope );
613608
614609 for (uint32_t i = 0 ; i < nFields ; i ++ )
615610 {
616611 metac_type_aggregate_field_t * semaField = & fields [i ];
617- metac_identifier_ptr_t fieldName = aggField -> Field -> VarIdentifier ;
618- // ??? should we Register this identifier in the semanticIdentifierTable
619- // and using a pointer to that in the sema node?
612+ metac_identifier_ptr_t parserFieldName = aggField -> Field -> VarIdentifier ;
613+ metac_identifier_ptr_t semaFieldName =
614+ MetaCIdentifierTable_CopyIdentifier (self -> ParserIdentifierTable ,
615+ & self -> SemanticIdentifierTable ,
616+ parserFieldName );
617+ scope_insert_error_t inserted ;
620618
621619 uint32_t declNodePtr = 42 ;
622620 semaField -> Header .Kind = node_decl_field ;
623621
624- semaField -> Identifier = fieldName ;
625- // placeholder while we don't have hash-table for decl_node pointers
622+ semaField -> Identifier = semaFieldName ;
626623 semaField -> Index = cast (uint16_t ) i ;
627- semaField -> Type .v = TYPE_INDEX_V (type_index_unknown , declNodePtr );
628- //metac_sema_identifier_t
629- // semaId = MetaCSemantic_RegisterIdentifier(agg->Fields[i].Field.VarIdentifier);
630- scope_insert_error_t inserted =
631- MetaCSemantic_RegisterInScope (self , fieldName ,
624+ semaField -> Type .v = TYPE_INDEX_V (type_index_unknown , 0 );
625+
626+ inserted =
627+ MetaCSemantic_RegisterInScope (self , semaFieldName ,
632628 cast (metac_node_t )semaField );
629+
633630 if (inserted != success )
634631 {
635632 SemanticError (0 , "%s could not be inserted" ,
636- IdentifierPtrToCharPtr (self -> ParserIdentifierTable , fieldName ));
633+ IdentifierPtrToCharPtr (self -> ParserIdentifierTable , parserFieldName ));
637634 }
638635
639636 aggField = aggField -> Next ;
@@ -968,9 +965,16 @@ metac_type_index_t TypeArraySemantic(metac_sema_state_t* self,
968965 MetaCSemantic_doExprSemantic (self , arrayType -> Dim , 0 )
969966 );
970967
968+ uint32_t dimValue = cast (uint32_t ) - 1 ;
969+
971970 if (METAC_NODE (dim ) != emptyNode )
972971 {
973- if (dim -> Kind != expr_signed_integer )
972+ if (dim -> Kind == expr_unknown_value )
973+ {
974+ // this is essentially allowd b/c of templates.
975+ // TODO we might have to do something more here, maybe?
976+ }
977+ else if (dim -> Kind != expr_signed_integer )
974978 {
975979 xprintf ("Array dimension should eval to integer but it is: %s\n" ,
976980 MetaCExprKind_toChars (dim -> Kind ));
@@ -979,9 +983,11 @@ metac_type_index_t TypeArraySemantic(metac_sema_state_t* self,
979983 return invalidTypeIndex ;
980984 }
981985 }
982- uint32_t dimValue = (
983- METAC_NODE (dim ) != emptyNode ?
984- (uint32_t )dim -> ValueU64 : -1 );
986+
987+ if (dim -> Kind == expr_signed_integer )
988+ {
989+ dimValue = cast (int32_t )dim -> ValueI64 ;
990+ }
985991
986992 result =
987993 MetaCSemantic_GetArrayTypeOf (self , elementType , dimValue );
@@ -1160,67 +1166,76 @@ metac_type_index_t MetaCSemantic_TypeSemantic(metac_sema_state_t* self,
11601166 else if (IsAggregateTypeDecl (type -> Kind ))
11611167 {
11621168 STACK_ARENA_ARRAY (metac_type_aggregate_field_t , tmpFields , 128 , & self -> TempAlloc )
1163-
1164- decl_type_struct_t * agg = (decl_type_struct_t * ) type ;
1169+ metac_scope_owner_kind_t ownerKind = scope_owner_unknown ;
1170+ decl_type_struct_t * agg = cast (decl_type_struct_t * ) type ;
11651171 metac_type_aggregate_t tmpSemaAggMem = {(metac_decl_kind_t )0 };
11661172 metac_type_aggregate_t * tmpSemaAgg = & tmpSemaAggMem ;
11671173 metac_scope_t tmpTemplateScope = {0 };
11681174
11691175
11701176 if (type -> Kind == decl_type_struct )
1177+ {
11711178 typeKind = type_struct ;
1179+ ownerKind = scope_owner_struct ;
1180+ }
11721181 else if (type -> Kind == decl_type_union )
1182+ {
11731183 typeKind = type_union ;
1184+ }
11741185 else
1186+ {
11751187 assert (0 );
1176-
1188+ }
1189+
11771190 ARENA_ARRAY_ENSURE_SIZE (tmpFields , agg -> FieldCount );
11781191
11791192 tmpSemaAgg -> Header .Kind = agg -> Kind ;
11801193 tmpSemaAgg -> Identifier = agg -> Identifier ;
11811194 tmpSemaAgg -> Fields = tmpFields ;
11821195 tmpSemaAgg -> FieldCount = agg -> FieldCount ;
11831196
1184- PopulateTemporaryAggregateScope (self , tmpSemaAgg , agg );
1185- MetaCSemantic_MountScope (self , tmpSemaAgg -> Scope );
11861197
11871198 if (agg -> ParameterCount != 0 )
11881199 {
11891200 uint32_t parameterCount = agg -> ParameterCount ;
11901201 decl_parameter_t * param = agg -> Parameters ;
11911202 U32 (tmpTemplateScope .ScopeFlags ) |= scope_flag_temporary ;
1203+ tmpTemplateScope .Owner .v = SCOPE_OWNER_V (scope_owner_template , 0 );
1204+ MetaCScopeTable_InitN (& tmpTemplateScope .ScopeTable , agg -> ParameterCount , & self -> TempAlloc );
1205+
11921206 MetaCSemantic_PushTemporaryScope (self , & tmpTemplateScope );
11931207
11941208 for (uint32_t paramIdx = 0 ; paramIdx < parameterCount ; paramIdx ++ )
11951209 {
1210+ scope_insert_error_t inserted ;
11961211 metac_identifier_ptr_t paramIdent = param -> Parameter -> VarIdentifier ;
11971212 metac_location_ptr_t locIdx = param -> Parameter -> LocationIdx ;
11981213 metac_expr_t placeholderExpr ;
11991214 metac_sema_expr_t * placeholder = AllocNewSemaExpr (self , & placeholderExpr );
1200-
1215+ // we need to register the parser Identifier in the semantic table for resolution.
1216+ metac_identifier_ptr_t semaId =
1217+ MetaCIdentifierTable_CopyIdentifier (self -> ParserIdentifierTable , & self -> SemanticIdentifierTable , paramIdent );
1218+
12011219 placeholder -> Kind = expr_unknown_value ;
12021220 placeholder -> TypeIndex = MetaCSemantic_TypeSemantic (self , param -> Parameter -> VarType );
12031221 METAC_NODE (placeholder -> Expr ) = emptyNode ;
12041222 placeholder -> LocationIdx = locIdx ;
12051223
1206-
1207- MetaCSemantic_RegisterInScope (self , paramIdent , METAC_NODE (placeholder ));
1224+ inserted = MetaCSemantic_RegisterInScope (self , semaId , METAC_NODE (placeholder ));
12081225
12091226 param = param -> Next ;
12101227 }
12111228 }
1229+
1230+ PopulateTemporaryAggregateScope (self , tmpSemaAgg , agg );
1231+ MetaCSemantic_MountScope (self , tmpSemaAgg -> Scope );
1232+
12121233
12131234 switch (typeKind )
12141235 {
12151236 case type_struct :
12161237 {
1217- uint32_t hash ;
12181238 MetaCSemantic_ComputeStructLayout (self , agg , tmpSemaAgg );
1219-
1220- if (agg -> ParameterCount != 0 )
1221- {
1222- MetaCSemantic_PopTemporaryScope (self );
1223- }
12241239 tmpSemaAgg -> Header .Hash = AggregateHash (tmpSemaAgg );
12251240
12261241 result =
@@ -1252,6 +1267,10 @@ metac_type_index_t MetaCSemantic_TypeSemantic(metac_sema_state_t* self,
12521267 }
12531268
12541269 MetaCSemantic_UnmountScope (self );
1270+ if (agg -> ParameterCount != 0 )
1271+ {
1272+ MetaCSemantic_PopTemporaryScope (self );
1273+ }
12551274 }
12561275 else if (IsPointerType (type -> Kind ))
12571276 {
@@ -1334,8 +1353,9 @@ metac_type_index_t MetaCSemantic_TypeSemantic(metac_sema_state_t* self,
13341353 metac_scope_t tmpScope = {scope_flag_temporary };
13351354 MetaCSemantic_PushTemporaryScope (self , & tmpScope );
13361355
1337- for (metac_expr_t * e = args -> Expr ; METAC_NODE (args ) != emptyNode ; args = args -> Next , e = args -> Expr )
1356+ for (; METAC_NODE (args ) != emptyNode ; args = args -> Next )
13381357 {
1358+ metac_expr_t * e = args -> Expr ;
13391359 ARENA_ARRAY_ADD (semaArguments , MetaCSemantic_doExprSemantic (self , e , 0 ));
13401360 }
13411361
@@ -1355,7 +1375,7 @@ metac_type_index_t MetaCSemantic_TypeSemantic(metac_sema_state_t* self,
13551375 header ,
13561376 zeroIdx ,
13571377 symbol ,
1358- arguments ,
1378+ tInst -> Arguments , // we may need to copy the args here?
13591379 nArguments ,
13601380 };
13611381 result = MetaCTypeTable_GetOrEmptyTemplateType (& self -> TemplateTypeTable , & key );
@@ -1366,7 +1386,7 @@ metac_type_index_t MetaCSemantic_TypeSemantic(metac_sema_state_t* self,
13661386 }
13671387
13681388 }
1369-
1389+ MetaCSemantic_PopTemporaryScope ( self );
13701390 }
13711391 else if (type -> Kind == decl_type )
13721392 {
@@ -1665,7 +1685,9 @@ bool MetaCSemantic_ComputeStructLayout(metac_sema_state_t* self,
16651685 semaField < onePastLast ;
16661686 semaField ++ )
16671687 {
1668- semaField -> Identifier = declField -> Field -> VarIdentifier ;
1688+ semaField -> Identifier =
1689+ MetaCIdentifierTable_CopyIdentifier (
1690+ self -> ParserIdentifierTable , & self -> SemanticIdentifierTable , declField -> Field -> VarIdentifier );
16691691 semaField -> Header .Kind = node_decl_field ;
16701692
16711693 semaField -> Type =
0 commit comments