Skip to content

Commit 72066b1

Browse files
committed
Work on templates in the language
1 parent 9e8b891 commit 72066b1

File tree

9 files changed

+369
-114
lines changed

9 files changed

+369
-114
lines changed

parser/metac_expr_parser.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,12 @@ metac_expr_t* MetaCParser_ParseUnaryExpr(metac_parser_t* self)
13601360
isPrimaryExp = true;
13611361
result = MetaCParser_ParsePrimaryExpr(self, eflags);
13621362
}
1363+
else if (IsTypeToken(tokenType))
1364+
{
1365+
result = AllocNewExpr(expr_type);
1366+
result->TypeExp = MetaCParser_ParseTypeDecl(self, 0, 0);
1367+
result->Hash = CRC32C_VALUE(type_key, result->TypeExp->Hash);
1368+
}
13631369
else
13641370
{
13651371
if (tokenType != tok_eof && tokenType != tok_newline)
@@ -1397,17 +1403,22 @@ metac_expr_t* MetaCParser_ParseUnaryExpr(metac_parser_t* self)
13971403
}
13981404
#endif
13991405

1400-
expr_argument_t* MetaCParser_ParseArgumentList(metac_parser_t* self, parse_expr_flags_t flags)
1406+
expr_argument_list_t MetaCParser_ParseArgumentList(metac_parser_t* self, parse_expr_flags_t flags)
14011407
{
14021408
metac_location_t loc =
14031409
LocationFromToken(self, MetaCParser_PeekToken(self, 0));
14041410

1405-
metac_token_t* peekToken = MetaCParser_PeekToken(self, 1);
1406-
expr_argument_t* arguments = (expr_argument_t*) _emptyPointer;
1407-
expr_argument_t** nextArgument = &arguments;
1411+
metac_token_t* peekToken;
1412+
expr_argument_list_t arguments = {0};
1413+
expr_argument_t** nextArgument = &arguments.Arguments;
14081414
uint32_t nArguments = 0;
14091415
uint32_t hash = ~0;
14101416

1417+
METAC_NODE(arguments.Arguments) = emptyNode;
1418+
1419+
MetaCParser_Match(self, tok_lParen);
1420+
peekToken = MetaCParser_PeekToken(self, 1);
1421+
14111422
if (peekToken->TokenType == tok_rParen)
14121423
{
14131424
MetaCParser_Match(self, tok_rParen);
@@ -1445,19 +1456,21 @@ expr_argument_t* MetaCParser_ParseArgumentList(metac_parser_t* self, parse_expr_
14451456
break;
14461457
}
14471458
}
1459+
1460+
arguments.ArgumentCount = nArguments;
14481461
#ifndef OLD_PARSER
14491462
MetaCParser_PopExprStackBottom(self);
14501463
MetaCParser_PopOpStackBottom(self);
14511464
MetaCParser_PopOpenParens(self);
14521465
MetaCParser_PopFlags(self);
14531466
#endif
1454-
if (arguments != emptyPointer)
1467+
if (arguments.ArgumentCount != 0)
14551468
{
1456-
arguments->Hash = hash;
1469+
arguments.Hash = hash;
14571470

14581471
metac_token_t* rParen = MetaCParser_Match(self, tok_rParen);
14591472
MetaCLocation_Expand(&loc, LocationFromToken(self, rParen));
1460-
arguments->LocationIdx =
1473+
arguments.LocationIdx =
14611474
MetaCLocationStorage_Store(&self->LocationStorage, loc);
14621475
}
14631476

@@ -1542,7 +1555,7 @@ metac_expr_t* MetaCParser_ParseBinaryExpr(metac_parser_t* self,
15421555
{
15431556
expr_right = BinExpTypeFromTokenType(peekTokenType);
15441557
uint32_t opPrecedence = OpToPrecedence(expr_right);
1545-
metac_token_t* startTok = MetaCParser_Match(self, peekTokenType);
1558+
metac_token_t* startTok = (expr_right == expr_call ? peekToken : MetaCParser_Match(self, peekTokenType));
15461559
metac_location_t rhsLoc = LocationFromToken(self, startTok);
15471560
metac_expr_t* rhs;
15481561

@@ -1557,13 +1570,12 @@ metac_expr_t* MetaCParser_ParseBinaryExpr(metac_parser_t* self,
15571570
else if (expr_right == expr_template_instance
15581571
&& MetaCParser_PeekMatch(self, tok_lParen, 1))
15591572
{
1560-
MetaCParser_Match(self, tok_lParen);
15611573
goto LparseArgumentList;
15621574
}
15631575
else if (expr_right == expr_call)
15641576
{
15651577
LparseArgumentList:
1566-
rhs = (metac_expr_t*)MetaCParser_ParseArgumentList(self, expr_flags_call);
1578+
rhs = (metac_expr_t*)MetaCParser_ParseArgumentList(self, expr_flags_call).Arguments;
15671579
if ((metac_node_t)rhs != emptyPointer)
15681580
{
15691581
rhsIsArgs = true;
@@ -1630,7 +1642,7 @@ metac_expr_t* MetaCParser_ParseBinaryExpr(metac_parser_t* self,
16301642
return result;
16311643
}
16321644
#endif
1633-
static bool IsBinaryExp(metac_expr_kind_t kind)
1645+
bool IsBinaryExp(metac_expr_kind_t kind)
16341646
{
16351647
return ((kind >= FIRST_BINARY_EXP(TOK_SELF)) & (kind <= LAST_BINARY_EXP(TOK_SELF))
16361648
| (kind == expr_index)
@@ -2128,7 +2140,7 @@ metac_expr_t* MetaCParser_ParseExpr2(metac_parser_t* self, parse_expr_flags_t fl
21282140
MetaCParser_Match(self, tok_lParen);
21292141
op = expr_call;
21302142
opPrec = OpToPrecedence(op);
2131-
args = MetaCParser_ParseArgumentList(self, flags);
2143+
args = MetaCParser_ParseArgumentList(self, flags).Arguments;
21322144
MetaCParser_Match(self, tok_rParen);
21332145

21342146
if (opPrec > prec)

parser/metac_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
M(decl_type_functiontype) \
3535
M(decl_type_typeof) \
3636
M(decl_type_tuple) \
37+
M(decl_type_template_instance) \
3738
LAST_DECL_TYPE(M) \
3839
\
3940
M(decl_function) \

0 commit comments

Comments
 (0)