theos / logos

Preprocessor that simplifies Objective-C hooking.
https://theos.dev/docs/logos
Other
205 stars 34 forks source link

Add check for %group's within %hook's #93

Closed L1ghtmann closed 1 year ago

L1ghtmann commented 1 year ago

What does this implement/fix? Explain your changes.

See title

Does this close any currently open issues?

I believe this will resolve #45

Any relevant logs, error output, etc?

For the following code (as well as the code provided in the issue mentioned above):

%hook ClassToBeHooked
%group someThing
-(void)thing{
}
%end
%end

%ctor {
    %init(someThing);
}

Previously: successful preprocess Now: Tweak.xm:<line>: error: %group does not make sense inside a hook

Any other comments?

For

%group someThing2
%hook ClassToBeHooked2
-(void)thing2{
}
%end
%end

%group someThing
%hook ClassToBeHooked
-(void)thing{
}
%end
%end

%ctor {
    %init(someThing2);
    %init(someThing);
}

the nestingstack is shown to be:

nestingstack: group:59
nestingstack: group:59 hook:60
nestingstack: group:59 hook:60
nestingstack: group:59
nestingstack:
nestingstack: group:66
nestingstack: group:66 hook:67
nestingstack: group:66 hook:67
nestingstack: group:66

Based on this, it seems like the nestingstack array is cleaned up as items are %end'ed. Assuming this is correct, earlier hooks shouldn't interfere with the logic used to determine an open hook's location relative to the group in question. These assumptions may be incorrect, however, in which case this can be put on ice until a more thorough impl is thought up. It appears to work as intended in my testing though.

Where has this been tested?

Operating System:

Linux (WSL)

Platform:

Target Platform:

Toolchain Version:

SDK Version:

PoomSmart commented 1 year ago

Good find. Before we may merge this though, @uroboro it will be wise to add test cases for logos.pl - I tagged you because I remember you have that somewhere.