aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-09-09 14:46:28 +0100
committergingerBill <bill@gingerbill.org>2018-09-09 14:46:28 +0100
commit4f3837f0e6dfcdb743f0d1399a4795088d15f664 (patch)
tree9bd9c2093b8fe9ebecb9e612eca8443bcb057291 /src/parser.cpp
parent76848e8807543cf1e3a6675dc404bbb0de392471 (diff)
Procedure inlining on call site
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 8476d4332..a4bc16116 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -1553,6 +1553,7 @@ Ast * parse_type (AstFile *f);
Ast * parse_call_expr (AstFile *f, Ast *operand);
Ast * parse_struct_field_list(AstFile *f, isize *name_count_);
Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_type_token);
+Ast *parse_unary_expr(AstFile *f, bool lhs);
Ast *convert_stmt_to_expr(AstFile *f, Ast *statement, String kind) {
@@ -1673,9 +1674,10 @@ Ast *parse_operand(AstFile *f, bool lhs) {
case Token_no_inline:
{
Token token = advance_token(f);
- Ast *expr = parse_operand(f, false);
- if (expr->kind != Ast_ProcLit) {
- syntax_error(expr, "%.*s must be followed by a procedure literal, got %.*s", LIT(token.string), LIT(ast_strings[expr->kind]));
+ Ast *expr = parse_unary_expr(f, false);
+ Ast *e = unparen_expr(expr);
+ if (e->kind != Ast_ProcLit && e->kind != Ast_CallExpr) {
+ syntax_error(expr, "%.*s must be followed by a procedure literal or call, got %.*s", LIT(token.string), LIT(ast_strings[expr->kind]));
return ast_bad_expr(f, token, f->curr_token);
}
ProcInlining pi = ProcInlining_none;
@@ -1685,11 +1687,19 @@ Ast *parse_operand(AstFile *f, bool lhs) {
pi = ProcInlining_no_inline;
}
if (pi != ProcInlining_none) {
- if (expr->ProcLit.inlining != ProcInlining_none &&
- expr->ProcLit.inlining != pi) {
- syntax_error(expr, "You cannot apply both 'inline' and 'no_inline' to a procedure literal");
+ if (e->kind == Ast_ProcLit) {
+ if (expr->ProcLit.inlining != ProcInlining_none &&
+ expr->ProcLit.inlining != pi) {
+ syntax_error(expr, "You cannot apply both 'inline' and 'no_inline' to a procedure literal");
+ }
+ expr->ProcLit.inlining = pi;
+ } else if (e->kind == Ast_CallExpr) {
+ if (expr->CallExpr.inlining != ProcInlining_none &&
+ expr->CallExpr.inlining != pi) {
+ syntax_error(expr, "You cannot apply both 'inline' and 'no_inline' to a procedure literal");
+ }
+ expr->CallExpr.inlining = pi;
}
- expr->ProcLit.inlining = pi;
}
return expr;
@@ -3657,7 +3667,9 @@ Ast *parse_stmt(AstFile *f) {
Token token = f->curr_token;
switch (token.kind) {
// Operands
- case Token_context: // Also allows for `context <-`
+ case Token_context: // Also allows for `context =`
+ case Token_inline:
+ case Token_no_inline:
case Token_Ident:
case Token_Integer:
case Token_Float: