Find out if a function argument is part of a function call

Well, I think this is almost impossible. But nonetheless: is it possible to know inside a method call if the method was called as part of a function call?

Example (and my actual function call):

HDMExpressionSQLSelectBuilder *sb = [[[HDMExpressionSQLSelectBuilder alloc] init] autorelease]; [sb orNestedWhere:[sb where:@"wheraCoumnB" equals:@"whereBEqualValue"], [sb where:@"wheraCoumnB" equals:@"sth"], nil]; 

Two things happen here:

  • Arguments are evaluated in any order (in what order is not specified in the C standard, and it changes between compilers and Settings)
  • Although this should be obvious to every programmer: Internal functions are evaluated before

Now I want to know, for example, inside this method call ...

  [sb where:@"wheraCoumnB" equals:@"whereBEqualValue"] 

.. that it was called as part of a function argument.

Possible? Black magic?

Before you come and say that I am doing it wrong, and I have to correct my code: I claim that I have one of the rare cases when it makes sense to know such a thing. I am writing a query builder, and this will greatly facilitate the use of nested conditions. Otherwise, I would need to make a stupid nestedAndBegin and later nestedAndEnd to implement brackets, etc. It would be inconvenient in this case, my query builder is tree-based, and I would not want to do this (unlike the string query collectors that are required, you need to put the node for the logical expression in place).

Update

So this is not surprisingly impossible. For those who are interested in how I worked on this for my specific problem: I made sure that all function calls are deferred, so the function calls of my query builder put the method call object with the function arguments in the call list, At that time it does not execute which any method code. Each call object has a sequence identifier with an auto-capture identifier, so I know when the function was evaluated. Now in nestedAnd functions, etc. (So ​​those functions that my question was about), I check if the sequence identifier of the stored call objects matches the index of the function call argument. If not, this is the right time to change them.

Then, the syntax check and the step of constructing the query is delayed until the user actually calls the query () method (or ast () to get the expression tree).

+6
source share
1 answer

No, there is no (practical) way to do this.

Theoretically, you can add code to your method, which reads debugging characters from your binary, checks the link register and then uses this information to determine the call site, download the source code from another place, and computes the mapping, analyzes the source code and calculates how you describe.

+3
source

Source: https://habr.com/ru/post/949036/


All Articles