45 #include "char.h"
46
47 static int match_oplist(int op, ...)
48 {
49 va_list args;
50 int nextop;
51
52 va_start(args, op);
53 do {
54 nextop = va_arg(args, int);
55 } while (nextop != 0 && nextop != op);
56 va_end(args);
57
58 return nextop != 0;
59 }
60
61 static struct token *comma_expression(struct token *, struct expression **);
62
63 struct token *parens_expression(struct token *token, struct expression **expr, const char *where)
64 {
65 token = expect(token, '(', where);
66 if (match_op(token, '{')) {
67 struct expression *e = alloc_expression(token->pos, EXPR_STATEMENT);
68 struct statement *stmt = alloc_statement(token->pos, STMT_COMPOUND);
69 *expr = e;
70 e->statement = stmt;
71 start_symbol_scope(e->pos);
72 token = compound_statement(token->next, stmt);
73 end_symbol_scope();
74 token = expect(token, '}', "at end of statement expression");
75 } else
76 token = parse_expression(token, expr);
77 return expect(token, ')', where);
78 }
79
80 /*
81 * Handle __func__, __FUNCTION__ and __PRETTY_FUNCTION__ token
82 * conversion
83 */
84 static struct symbol *handle_func(struct token *token)
85 {
86 struct ident *ident = token->ident;
87 struct symbol *decl, *array;
88 struct string *string;
89 int len;
90
91 if (ident != &__func___ident &&
92 ident != &__FUNCTION___ident &&
93 ident != &__PRETTY_FUNCTION___ident)
94 return NULL;
95
96 if (!current_fn || !current_fn->ident)
|
45 #include "char.h"
46
47 static int match_oplist(int op, ...)
48 {
49 va_list args;
50 int nextop;
51
52 va_start(args, op);
53 do {
54 nextop = va_arg(args, int);
55 } while (nextop != 0 && nextop != op);
56 va_end(args);
57
58 return nextop != 0;
59 }
60
61 static struct token *comma_expression(struct token *, struct expression **);
62
63 struct token *parens_expression(struct token *token, struct expression **expr, const char *where)
64 {
65 struct token *p;
66
67 token = expect(token, '(', where);
68 p = token;
69 if (match_op(token, '{')) {
70 struct expression *e = alloc_expression(token->pos, EXPR_STATEMENT);
71 struct statement *stmt = alloc_statement(token->pos, STMT_COMPOUND);
72 *expr = e;
73 e->statement = stmt;
74 start_symbol_scope(e->pos);
75 token = compound_statement(token->next, stmt);
76 end_symbol_scope();
77 token = expect(token, '}', "at end of statement expression");
78 } else
79 token = parse_expression(token, expr);
80
81 if (token == p)
82 sparse_error(token->pos, "an expression is expected before ')'");
83 return expect(token, ')', where);
84 }
85
86 /*
87 * Handle __func__, __FUNCTION__ and __PRETTY_FUNCTION__ token
88 * conversion
89 */
90 static struct symbol *handle_func(struct token *token)
91 {
92 struct ident *ident = token->ident;
93 struct symbol *decl, *array;
94 struct string *string;
95 int len;
96
97 if (ident != &__func___ident &&
98 ident != &__FUNCTION___ident &&
99 ident != &__PRETTY_FUNCTION___ident)
100 return NULL;
101
102 if (!current_fn || !current_fn->ident)
|