From 7b2913e7af42100a01f04f5d2a399c8e4bc771b6 Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Fri, 26 Apr 2019 11:45:45 -0400 Subject: [PATCH 1/2] Make macros syntax error instead of silently failing. Thanks @marcioAlmada via #61: --- src/macros.yay | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/macros.yay b/src/macros.yay index b527717..69315d2 100755 --- a/src/macros.yay +++ b/src/macros.yay @@ -2,6 +2,7 @@ $(macro) { declare { + $! // syntax error if no match $(repeat(either( chain( optional(buffer('static') as static), @@ -112,7 +113,7 @@ $(macro) { $(macro) { compile { - function $(llvmidentifier() as name) ($(optional(ls( + function $(llvmidentifier() as name) $! ($(optional(ls( T_VARIABLE as param, token(',') )) as params)) { @@ -134,6 +135,7 @@ $(macro) { $(macro :unsafe :recursive) { $(optional(buffer('unsigned')) as unsigned) compile { + $! $(repeat(either( chain(T_VARIABLE as result, token('='), either( chain(T_VARIABLE as nullcheck_var, token(T_IS_EQUAL), buffer('null')) as nullcheck, From 05dd8f454ad49d9d082d83289e2bdb758d98288e Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Fri, 26 Apr 2019 12:12:28 -0400 Subject: [PATCH 2/2] Add test and fix empty arg function calls --- src/macros.yay | 2 +- test/macro/cases/functtion_calls.phpt | 33 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 test/macro/cases/functtion_calls.phpt diff --git a/src/macros.yay b/src/macros.yay index 69315d2..4549a42 100755 --- a/src/macros.yay +++ b/src/macros.yay @@ -187,7 +187,7 @@ $(macro :unsafe :recursive) { chain(buffer('free'), T_VARIABLE as free_var, token(';')) as free, chain(buffer('memcpy'), T_VARIABLE as memcpy_dest, T_VARIABLE as memcpy_src, T_VARIABLE as memcpy_length, token(';')) as memcpy, chain(buffer('memset'), T_VARIABLE as memset_dest, T_LNUMBER as memset_value, T_VARIABLE as memset_length, token(';')) as memset, - chain(llvmidentifier() as voidcall_func, token('('), ls(T_VARIABLE as voidcall_arg, token(',')) as voidcall_args, token(')'), token(';')) as voidcall + chain(llvmidentifier() as voidcall_func, token('('), optional(ls(T_VARIABLE as voidcall_arg, token(',')) as voidcall_args), token(')'), token(';')) as voidcall )) as stmts) } } >> { diff --git a/test/macro/cases/functtion_calls.phpt b/test/macro/cases/functtion_calls.phpt new file mode 100755 index 0000000..3d7ea2c --- /dev/null +++ b/test/macro/cases/functtion_calls.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test function calls +--FILE-- + +--EXPECTF-- +context->builder->call( + $this->context->lookupFunction('bar') +); +$this->context->builder->call( + $this->context->lookupFunction('foo') , + $a +); +$a = $this->context->builder->call( + $this->context->lookupFunction('bar') +); +$b = $this->context->builder->call( + $this->context->lookupFunction('foo') , + $c +); + +?> \ No newline at end of file