mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-22 10:48:02 +00:00
diff: Detect Objective-C methods
When searching back for function definitions, consider lines starting with '+' and '-', this allows us to pick up Objective-C methods as well as C style function definitions. Reviewed by: bapt Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34202
This commit is contained in:
parent
3ca204c97a
commit
8f79bd9b85
|
@ -396,8 +396,8 @@ file name and time in the context or unified diff header.
|
|||
With unified and context diffs, show with each change
|
||||
the first 40 characters of the last line before the context beginning
|
||||
with a letter, an underscore or a dollar sign.
|
||||
For C source code following standard layout conventions, this will
|
||||
show the prototype of the function the change applies to.
|
||||
For C and Objective-C source code following standard layout conventions, this
|
||||
will show the prototype of the function the change applies to.
|
||||
.It Fl T -initial-tab
|
||||
Print a tab rather than a space before the rest of the line for the
|
||||
normal, context or unified output formats.
|
||||
|
|
|
@ -1419,7 +1419,8 @@ match_function(const long *f, int pos, FILE *fp)
|
|||
strlcpy(lastbuf, buf, sizeof(lastbuf));
|
||||
lastmatchline = pos;
|
||||
return (lastbuf);
|
||||
} else if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') {
|
||||
} else if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$'
|
||||
|| buf[0] == '-' || buf[0] == '+') {
|
||||
if (begins_with(buf, "private:")) {
|
||||
if (!state)
|
||||
state = " (private)";
|
||||
|
|
|
@ -27,7 +27,14 @@ ${PACKAGE}FILES+= \
|
|||
header_ns.out \
|
||||
ifdef.out \
|
||||
group-format.out \
|
||||
strip_o.out
|
||||
strip_o.out \
|
||||
functionname.in \
|
||||
functionname_c.in \
|
||||
functionname_c.out \
|
||||
functionname_objcclassm.in \
|
||||
functionname_objcclassm.out \
|
||||
functionname_objcm.in \
|
||||
functionname_objcm.out
|
||||
|
||||
NETBSD_ATF_TESTS_SH+= netbsd_diff_test
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ atf_test_case label
|
|||
atf_test_case report_identical
|
||||
atf_test_case non_regular_file
|
||||
atf_test_case binary
|
||||
atf_test_case functionname
|
||||
|
||||
simple_body()
|
||||
{
|
||||
|
@ -278,6 +279,23 @@ binary_body()
|
|||
atf_check -o inline:"176c\nx\n.\n" -s exit:1 diff -ae A B
|
||||
}
|
||||
|
||||
functionname_body()
|
||||
{
|
||||
atf_check -o empty -x "which diff"
|
||||
|
||||
atf_check -o file:$(atf_get_srcdir)/functionname_c.out -s exit:1 \
|
||||
diff -u -p -L functionname.in -L functionname_c.in \
|
||||
"$(atf_get_srcdir)/functionname.in" "$(atf_get_srcdir)/functionname_c.in"
|
||||
|
||||
atf_check -o file:$(atf_get_srcdir)/functionname_objcm.out -s exit:1 \
|
||||
diff -u -p -L functionname.in -L functionname_objcm.in \
|
||||
"$(atf_get_srcdir)/functionname.in" "$(atf_get_srcdir)/functionname_objcm.in"
|
||||
|
||||
atf_check -o file:$(atf_get_srcdir)/functionname_objcclassm.out -s exit:1 \
|
||||
diff -u -p -L functionname.in -L functionname_objcclassm.in \
|
||||
"$(atf_get_srcdir)/functionname.in" "$(atf_get_srcdir)/functionname_objcclassm.in"
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case simple
|
||||
|
@ -299,4 +317,5 @@ atf_init_test_cases()
|
|||
atf_add_test_case report_identical
|
||||
atf_add_test_case non_regular_file
|
||||
atf_add_test_case binary
|
||||
atf_add_test_case functionname
|
||||
}
|
||||
|
|
29
usr.bin/diff/tests/functionname.in
Normal file
29
usr.bin/diff/tests/functionname.in
Normal file
|
@ -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;
|
||||
}
|
29
usr.bin/diff/tests/functionname_c.in
Normal file
29
usr.bin/diff/tests/functionname_c.in
Normal file
|
@ -0,0 +1,29 @@
|
|||
static void
|
||||
doSomethingThenPrintHello(int test)
|
||||
{
|
||||
test = test << 4;
|
||||
if (test % 8 == 6) {
|
||||
return;
|
||||
}
|
||||
|
||||
print("hello\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;
|
||||
}
|
11
usr.bin/diff/tests/functionname_c.out
Normal file
11
usr.bin/diff/tests/functionname_c.out
Normal file
|
@ -0,0 +1,11 @@
|
|||
--- functionname.in
|
||||
+++ functionname_c.in
|
||||
@@ -6,7 +6,7 @@ doSomethingThenPrintHello(int test)
|
||||
return;
|
||||
}
|
||||
|
||||
- print("goodbye\n");
|
||||
+ print("hello\n");
|
||||
}
|
||||
|
||||
|
31
usr.bin/diff/tests/functionname_objcclassm.in
Normal file
31
usr.bin/diff/tests/functionname_objcclassm.in
Normal file
|
@ -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;
|
||||
}
|
11
usr.bin/diff/tests/functionname_objcclassm.out
Normal file
11
usr.bin/diff/tests/functionname_objcclassm.out
Normal file
|
@ -0,0 +1,11 @@
|
|||
--- functionname.in
|
||||
+++ functionname_objcclassm.in
|
||||
@@ -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;
|
||||
}
|
29
usr.bin/diff/tests/functionname_objcm.in
Normal file
29
usr.bin/diff/tests/functionname_objcm.in
Normal file
|
@ -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;
|
||||
}
|
11
usr.bin/diff/tests/functionname_objcm.out
Normal file
11
usr.bin/diff/tests/functionname_objcm.out
Normal file
|
@ -0,0 +1,11 @@
|
|||
--- functionname.in
|
||||
+++ functionname_objcm.in
|
||||
@@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue