4

I'm attempting to remove goto statement inside Mach7, because goto is not allowed in constexpr function:

#define MatchQ(s) {                                                            \
        XTL_MATCH_PREAMBULA(s)                                                 \
        enum { __base_counter = XTL_COUNTER };                                 \
        typedef mch::unified_switch<source_type> switch_traits;                \
        XTL_PRELOADABLE_LOCAL_STATIC(XTL_CPP0X_TYPENAME switch_traits::static_data_type,static_data,match_uid_type,XTL_EMPTY()); \
        XTL_CPP0X_TYPENAME switch_traits::local_data_type  local_data;         \
        bool processed = false;                                       \
        size_t jump_target = switch_traits::choose(subject_ptr,static_data,local_data); \
        XTL_CONCAT(ReMatch,__LINE__):                                          \
        switch (jump_target)                                                   \
        {                                                                      \
            XTL_NON_REDUNDANCY_ONLY(default:)                                  \
            { XTL_REDUNDANCY_ONLY(try){{                                       \
            if (switch_traits::on_default(jump_target,local_data,static_data)) \
                goto XTL_CONCAT(ReMatch,__LINE__);                             \
            XTL_SUBCLAUSE_FIRST

The codes above use goto here: goto XTL_CONCAT(ReMatch,__LINE__);, which is possible to jump to upside of switch statement.

How to replace goto here with something else?

5
  • 1
    Might enclosing the lines starting from XTL_CONCAT(ReMatch,LINE): all the way till the end of the closing bracket of switch with "while(true){", and then replacing "goto" statements with "break/continue" be a solution? Commented Feb 27, 2019 at 4:03
  • @ozlsn I have tried it before posting this question, but failed somehow, lemme gcc -E to dig into it. Commented Feb 27, 2019 at 4:31
  • XTL_REDUNDANCY_ONLY may set up another loop which a "continue;" would cycle through. We'd have to see all the macros. Commented Feb 27, 2019 at 4:33
  • 1
    Why do you use such complex macro's? Can't you use regular functions instead? Commented Feb 27, 2019 at 7:46
  • @JVApen I'm not the author of this pattern-matching library. So I cannot answer this question before get familiar enough with this library Commented Feb 27, 2019 at 7:49

1 Answer 1

0

with the help of @ozlsn and gcc -E, the replacement is done. persuade codes:

while(true)
{
    bool continue_flag = false;
    switch(var)
    {
        default:
            if(something)
                continue_flag = true;
                break;
        // do something
        OtherCases:
            // do something
    }
    if (!contine_flag)
        break;
}

full commit here: https://github.com/FirstLoveLife/Mach7/commit/3db24a337a7643018ed9e12ac95f53f9a036251c

Here is a related QA: Using continue in a switch statement

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.