"GOT", but the "O" is a cute, smiling sun Index | Thread

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: Detect objective c function prototypes
To:
Tom Jones <thj@freebsd.org>
Cc:
gameoftrees@openbsd.org
Date:
Tue, 18 Oct 2022 11:00:41 +0200

Download raw body.

On Thu, Sep 29, 2022 at 10:37:33AM +0100, Tom Jones wrote:
> When searching for function prototypes pick up on objective-c class and
> object methods. 
> 
> Add tests for both.
> 
> 
> - Tom

Yes, this seems fine to me. ok stsp@

> >From c198c15288b1ff9ef990ba7e327897f2a7a5788e Mon Sep 17 00:00:00 2001
> From: Tom Jones <thj@freebsd.org>
> Date: Thu, 29 Sep 2022 11:32:27 +0200
> Subject: [PATCH] Detect objective-c class function and methods
> 
> ---
>  lib/diff_output.c        |  3 ++-
>  test/expect126.diff      | 11 +++++++++++
>  test/expect127.diff      | 11 +++++++++++
>  test/test126.left-p.txt  | 29 +++++++++++++++++++++++++++++
>  test/test126.right-p.txt | 31 +++++++++++++++++++++++++++++++
>  test/test127.left-p.txt  | 29 +++++++++++++++++++++++++++++
>  test/test127.right-p.txt | 29 +++++++++++++++++++++++++++++
>  7 files changed, 142 insertions(+), 1 deletion(-)
>  create mode 100644 test/expect126.diff
>  create mode 100644 test/expect127.diff
>  create mode 100644 test/test126.left-p.txt
>  create mode 100644 test/test126.right-p.txt
>  create mode 100644 test/test127.left-p.txt
>  create mode 100644 test/test127.right-p.txt
> 
> diff --git a/lib/diff_output.c b/lib/diff_output.c
> index bc44a51..1c4cf1d 100644
> --- a/lib/diff_output.c
> +++ b/lib/diff_output.c
> @@ -262,7 +262,8 @@ diff_output_trailing_newline_msg(struct diff_output_info *outinfo, FILE *dest,
>  static bool
>  is_function_prototype(unsigned char ch)
>  {
> -	return (isalpha(ch) || ch == '_' || ch == '$');
> +	return (isalpha(ch) || ch == '_' || ch == '$' ||
> +		ch == '-' || ch == '+');
>  }
>  
>  #define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0)
> diff --git a/test/expect126.diff b/test/expect126.diff
> new file mode 100644
> index 0000000..1dd88d6
> --- /dev/null
> +++ b/test/expect126.diff
> @@ -0,0 +1,11 @@
> +--- test126.left-p.txt
> ++++ test126.right-p.txt
> +@@ -25,5 +25,7 @@ + (BOOL) isEdible:(NSString *)mushroom
> + 
> + + (BOOL) isEdible:(NSString *)mushroom
> + {
> +-	return TRUE;
> ++	/* With a solid guide book (such as Phillips 2006) assume we can't eat
> ++	 * the fungus */
> ++	return FALSE;
> + }
> diff --git a/test/expect127.diff b/test/expect127.diff
> new file mode 100644
> index 0000000..56ddbf9
> --- /dev/null
> +++ b/test/expect127.diff
> @@ -0,0 +1,11 @@
> +--- test127.left-p.txt
> ++++ test127.right-p.txt
> +@@ -18,7 +18,7 @@ - (long) readOffset:(FILE*)file
> + 		return offset;
> + 	} else {
> + 		int offset;
> +-		fread(&offset, sizeof(int), 1, file);
> ++		fread(&offset-1, sizeof(int), 1, file);
> + 		return offset;
> + 	}
> + }
> diff --git a/test/test126.left-p.txt b/test/test126.left-p.txt
> new file mode 100644
> index 0000000..7b4c50c
> --- /dev/null
> +++ b/test/test126.left-p.txt
> @@ -0,0 +1,29 @@
> +static void
> +doSomethingThenPrintHello(int test)
> +{
> +	test = test << 4;
> +	if (test % 8 == 6) {
> +		return;
> +	}
> +
> +	print("goodbye\n");
> +}
> +
> +
> +- (long) readOffset:(FILE*)file
> +{
> +	if( version >= 11){
> +		long offset;
> +		fread(&offset, sizeof(long), 1, file);
> +		return offset;
> +	} else {
> +		int offset;
> +		fread(&offset, sizeof(int), 1, file);
> +		return offset;
> +	}
> +}
> +
> ++ (BOOL) isEdible:(NSString *)mushroom
> +{
> +	return TRUE;
> +}
> diff --git a/test/test126.right-p.txt b/test/test126.right-p.txt
> new file mode 100644
> index 0000000..37a9a76
> --- /dev/null
> +++ b/test/test126.right-p.txt
> @@ -0,0 +1,31 @@
> +static void
> +doSomethingThenPrintHello(int test)
> +{
> +	test = test << 4;
> +	if (test % 8 == 6) {
> +		return;
> +	}
> +
> +	print("goodbye\n");
> +}
> +
> +
> +- (long) readOffset:(FILE*)file
> +{
> +	if( version >= 11){
> +		long offset;
> +		fread(&offset, sizeof(long), 1, file);
> +		return offset;
> +	} else {
> +		int offset;
> +		fread(&offset, sizeof(int), 1, file);
> +		return offset;
> +	}
> +}
> +
> ++ (BOOL) isEdible:(NSString *)mushroom
> +{
> +	/* With a solid guide book (such as Phillips 2006) assume we can't eat
> +	 * the fungus */
> +	return FALSE;
> +}
> diff --git a/test/test127.left-p.txt b/test/test127.left-p.txt
> new file mode 100644
> index 0000000..7b4c50c
> --- /dev/null
> +++ b/test/test127.left-p.txt
> @@ -0,0 +1,29 @@
> +static void
> +doSomethingThenPrintHello(int test)
> +{
> +	test = test << 4;
> +	if (test % 8 == 6) {
> +		return;
> +	}
> +
> +	print("goodbye\n");
> +}
> +
> +
> +- (long) readOffset:(FILE*)file
> +{
> +	if( version >= 11){
> +		long offset;
> +		fread(&offset, sizeof(long), 1, file);
> +		return offset;
> +	} else {
> +		int offset;
> +		fread(&offset, sizeof(int), 1, file);
> +		return offset;
> +	}
> +}
> +
> ++ (BOOL) isEdible:(NSString *)mushroom
> +{
> +	return TRUE;
> +}
> diff --git a/test/test127.right-p.txt b/test/test127.right-p.txt
> new file mode 100644
> index 0000000..06c3e9b
> --- /dev/null
> +++ b/test/test127.right-p.txt
> @@ -0,0 +1,29 @@
> +static void
> +doSomethingThenPrintHello(int test)
> +{
> +	test = test << 4;
> +	if (test % 8 == 6) {
> +		return;
> +	}
> +
> +	print("goodbye\n");
> +}
> +
> +
> +- (long) readOffset:(FILE*)file
> +{
> +	if( version >= 11){
> +		long offset;
> +		fread(&offset, sizeof(long), 1, file);
> +		return offset;
> +	} else {
> +		int offset;
> +		fread(&offset-1, sizeof(int), 1, file);
> +		return offset;
> +	}
> +}
> +
> ++ (BOOL) isEdible:(NSString *)mushroom
> +{
> +	return TRUE;
> +}
> -- 
> 2.35.1
>