engine/source/preprocessorlib/pp_parser.c
/**
 * Handles conditional directives.
 * @param directive the type of conditional directive
 */
Handles conditional directives.
@param directive the type of conditional directive
Handles conditional directives . @param directive the type of conditional directive
HRESULT pp_parser_conditional(pp_parser *self, PP_TOKEN_TYPE directive)
{
    int result;
    switch(directive)
    {
    case PP_TOKEN_IF:
    case PP_TOKEN_IFDEF:
    case PP_TOKEN_IFNDEF:
        if(self->ctx->num_conditionals++ > 32)
        {
            return pp_error(self, "too many levels of nested conditional directives");
        }
        self->ctx->conditionals.all <<= 2; 
        if(self->ctx->conditionals.others > (self->ctx->conditionals.others & 0x5555555555555555ll))
        {
            self->ctx->conditionals.top = cs_false;
            break;
        }
        if(FAILED(pp_parser_eval_conditional(self, directive, &result)))
        {
            return E_FAIL;
        }
        self->ctx->conditionals.top = result ? cs_true : cs_false;
        break;
    case PP_TOKEN_ELIF:
        if(self->ctx->conditionals.top == cs_none)
        {
            return pp_error(self, "stray #elif");
        }
        if(self->ctx->conditionals.top == cs_done || self->ctx->conditionals.top == cs_true)
        {
            self->ctx->conditionals.top = cs_done;
        }
        else if(self->ctx->conditionals.others == (self->ctx->conditionals.others & 0x5555555555555555ll))
        {
            self->ctx->conditionals.top = cs_true;
            if(FAILED(pp_parser_eval_conditional(self, directive, &result)))
            {
                return E_FAIL;
            }
            self->ctx->conditionals.top = result ? cs_true : cs_false;
        }
        break;
    case PP_TOKEN_ELSE:
        if(self->ctx->conditionals.top == cs_none)
        {
            return pp_error(self, "stray #else");
        }
        self->ctx->conditionals.top = (self->ctx->conditionals.top == cs_false) ? cs_true : cs_done;
        break;
    case PP_TOKEN_ENDIF:
        if(self->ctx->conditionals.top == cs_none || self->ctx->num_conditionals-- < 0)
        {
            return pp_error(self, "stray #endif");
        }
        self->ctx->conditionals.all >>= 2; 
        break;
    default:
        return pp_error(self, "unknown conditional directive type (ID=%d)", directive);
    }
    return S_OK;
}
HRESULT pp_parser_conditional ( pp_parser * self , PP_TOKEN_TYPE directive ) { int result ; switch ( directive ) { case PP_TOKEN_IF : case PP_TOKEN_IFDEF : case PP_TOKEN_IFNDEF : if ( self -> ctx -> num_conditionals ++ > 32 ) { return pp_error ( self , " " ) ; } self -> ctx -> conditionals . all <<= 2 ; if ( self -> ctx -> conditionals . others > ( self -> ctx -> conditionals . others & 0x5555555555555555ll ) ) { self -> ctx -> conditionals . top = cs_false ; break ; } if ( FAILED ( pp_parser_eval_conditional ( self , directive , & result ) ) ) { return E_FAIL ; } self -> ctx -> conditionals . top = result ? cs_true : cs_false ; break ; case PP_TOKEN_ELIF : if ( self -> ctx -> conditionals . top == cs_none ) { return pp_error ( self , " " ) ; } if ( self -> ctx -> conditionals . top == cs_done || self -> ctx -> conditionals . top == cs_true ) { self -> ctx -> conditionals . top = cs_done ; } else if ( self -> ctx -> conditionals . others == ( self -> ctx -> conditionals . others & 0x5555555555555555ll ) ) { self -> ctx -> conditionals . top = cs_true ; if ( FAILED ( pp_parser_eval_conditional ( self , directive , & result ) ) ) { return E_FAIL ; } self -> ctx -> conditionals . top = result ? cs_true : cs_false ; } break ; case PP_TOKEN_ELSE : if ( self -> ctx -> conditionals . top == cs_none ) { return pp_error ( self , " " ) ; } self -> ctx -> conditionals . top = ( self -> ctx -> conditionals . top == cs_false ) ? cs_true : cs_done ; break ; case PP_TOKEN_ENDIF : if ( self -> ctx -> conditionals . top == cs_none || self -> ctx -> num_conditionals -- < 0 ) { return pp_error ( self , " " ) ; } self -> ctx -> conditionals . all >>= 2 ; break ; default : return pp_error ( self , " " , directive ) ; } return S_OK ; }
Handles conditional directives.
Handles conditional directives .
// push a new conditional state onto the stack // unconditionally enable parsing long enough to parse the condition // pop a conditional state from the stack