3rdparty/bgfx/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp
//
// Do all token-pasting related combining of two pasted tokens when getting a
// stream of tokens from a replacement list. Degenerates to no processing if a
// replacement list is not the source of the token stream.
//
Do all token-pasting related combining of two pasted tokens when getting a
stream of tokens from a replacement list. Degenerates to no processing if a
replacement list is not the source of the token stream.
Do all token - pasting related combining of two pasted tokens when getting a stream of tokens from a replacement list . Degenerates to no processing if a replacement list is not the source of the token stream .
int TPpContext::tokenPaste(int token, TPpToken& ppToken)
{
    if (token == PpAtomPaste) {
        parseContext.ppError(ppToken.loc, "unexpected location", "##", "");
        return scanToken(&ppToken);
    }
    int resultToken = token; 
    while (peekPasting()) {
        TPpToken pastedPpToken;
        token = scanToken(&pastedPpToken);
        assert(token == PpAtomPaste);
        if (endOfReplacementList()) {
            parseContext.ppError(ppToken.loc, "unexpected location; end of replacement list", "##", "");
            break;
        }
        token = scanToken(&pastedPpToken);
        if (token == tMarkerInput::marker) {
            parseContext.ppError(ppToken.loc, "unexpected location; end of argument", "##", "");
            break;
        }
        switch (resultToken) {
        case PpAtomIdentifier:
            break;
        case '=':
        case '!':
        case '-':
        case '~':
        case '+':
        case '*':
        case '/':
        case '%':
        case '<':
        case '>':
        case '|':
        case '^':
        case '&':
        case PpAtomRight:
        case PpAtomLeft:
        case PpAtomAnd:
        case PpAtomOr:
        case PpAtomXor:
            strcpy(ppToken.name, atomStrings.getString(resultToken));
            strcpy(pastedPpToken.name, atomStrings.getString(token));
            break;
        default:
            parseContext.ppError(ppToken.loc, "not supported for these tokens", "##", "");
            return resultToken;
        }
        if (strlen(ppToken.name) + strlen(pastedPpToken.name) > MaxTokenLength) {
            parseContext.ppError(ppToken.loc, "combined tokens are too long", "##", "");
            return resultToken;
        }
        strncat(ppToken.name, pastedPpToken.name, MaxTokenLength - strlen(ppToken.name));
        if (resultToken != PpAtomIdentifier) {
            int newToken = atomStrings.getAtom(ppToken.name);
            if (newToken > 0)
                resultToken = newToken;
            else
                parseContext.ppError(ppToken.loc, "combined token is invalid", "##", "");
        }
    }
    return resultToken;
}
int TPpContext :: tokenPaste ( int token , TPpToken & ppToken ) { if ( token == PpAtomPaste ) { parseContext . ppError ( ppToken . loc , " " , " " , " " ) ; return scanToken ( & ppToken ) ; } int resultToken = token ; while ( peekPasting ( ) ) { TPpToken pastedPpToken ; token = scanToken ( & pastedPpToken ) ; assert ( token == PpAtomPaste ) ; if ( endOfReplacementList ( ) ) { parseContext . ppError ( ppToken . loc , " " , " " , " " ) ; break ; } token = scanToken ( & pastedPpToken ) ; if ( token == tMarkerInput :: marker ) { parseContext . ppError ( ppToken . loc , " " , " " , " " ) ; break ; } switch ( resultToken ) { case PpAtomIdentifier : break ; case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case PpAtomRight : case PpAtomLeft : case PpAtomAnd : case PpAtomOr : case PpAtomXor : strcpy ( ppToken . name , atomStrings . getString ( resultToken ) ) ; strcpy ( pastedPpToken . name , atomStrings . getString ( token ) ) ; break ; default : parseContext . ppError ( ppToken . loc , " " , " " , " " ) ; return resultToken ; } if ( strlen ( ppToken . name ) + strlen ( pastedPpToken . name ) > MaxTokenLength ) { parseContext . ppError ( ppToken . loc , " " , " " , " " ) ; return resultToken ; } strncat ( ppToken . name , pastedPpToken . name , MaxTokenLength - strlen ( ppToken . name ) ) ; if ( resultToken != PpAtomIdentifier ) { int newToken = atomStrings . getAtom ( ppToken . name ) ; if ( newToken > 0 ) resultToken = newToken ; else parseContext . ppError ( ppToken . loc , " " , " " , " " ) ; } } return resultToken ; }
Do all token-pasting related combining of two pasted tokens when getting a
stream of tokens from a replacement list.
Do all token - pasting related combining of two pasted tokens when getting a stream of tokens from a replacement list .
// starting with ## is illegal, skip to next token // "foo" pasted with "35" is an identifier, not a number // ## can be chained, process all in the chain at once // next token has to be ## // This covers end of macro expansion // get the token after the ## // This covers end of argument expansion // get the token text // already have the correct text in token.names // combine the tokens // correct the kind of token we are making, if needed (identifiers stay identifiers)