[cmake-developers] [PATCH v2 0/2] Support for continue command

Gregor Jasny gjasny at googlemail.com
Thu Nov 6 15:20:14 EST 2014


On 04/11/14 21:21, Brad King wrote:
> On 11/04/2014 03:10 PM, Gregor Jasny wrote:
>> About the continue() outside of a block error: I added a test but I
>> have no idea how to enforce the desired behavior.
> 
> It's been a while since I looked at the relevant parts of the code
> but here is one approach that may work:
> 
> Find all call sites to cmMakefile::ExecuteCommand.  Teach them to
> check the resulting status argument for GetContinueInvoked.  If it
> is true for any call sites other than the loop implementations then
> it is an error.

I wonder if this will really work. Imaging the following:

foreach(...)
  if(...)
    continue()
  endif()
endforeach()

As you can see in the patch the if command detects the continue
invocation and aborts looping over the collected commands. It also
bounces the continue to the outer inStatus execution status.

IMHO what's needed is a in loop counter that counts how deep we are in a
loop construct. It gets incremented within every foreach or while loop.
Decremented with each endforeach or endwhile.

Additionally new function, macro or includes will push the counter on a
stack and reset it. I'd consider the following invalid:

function(foo)
 continue()
endfunction()

foreach(...)
  foo()
endforeach()

Do you have and idea how to achieve this? I thought about storing the
state in the cmExecutionStatus which gets pushed to the
cmMakefile::CallStack. But the call stack is surprisingly empty at the
continue() when I execute the following:

if (1)
  if (1)
    continue ()
  endif (1)
endif (1)

Another approach would be to hook into ExecuteCommand, but this misses
all the endFoos.

Thanks for your help,
Gregor


More information about the cmake-developers mailing list