1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

fix expansion of macros used as parameters to function-like macros

This commit is contained in:
Andrew Niefer 2004-10-21 21:25:41 +00:00
parent 4761007499
commit ee74068fe8
2 changed files with 33 additions and 2 deletions

View file

@ -2191,4 +2191,35 @@ public class Scanner2Test extends BaseScanner2Test
validateEOF();
}
public void testMacroArgumentExpansion() throws Exception {
Writer writer = new StringWriter();
writer.write( "#define g_return( expr ) ( expr ) \n" ); //$NON-NLS-1$
writer.write( "#define ETH( obj ) ( CHECK( (obj), boo ) ) \n" ); //$NON-NLS-1$
writer.write( "#define CHECK CHECK_INSTANCE \n" ); //$NON-NLS-1$
writer.write( "#define CHECK_INSTANCE( instance, type ) (foo((instance), (type))) \n" ); //$NON-NLS-1$
writer.write( "g_return( ETH(ooga) ) \n" ); //$NON-NLS-1$
initializeScanner( writer.toString() );
validateToken( IToken.tLPAREN );
validateToken( IToken.tLPAREN );
validateToken( IToken.tLPAREN );
validateIdentifier( "foo" ); //$NON-NLS-1$
validateToken( IToken.tLPAREN );
validateToken( IToken.tLPAREN );
validateToken( IToken.tLPAREN );
validateIdentifier( "ooga" ); //$NON-NLS-1$
validateToken( IToken.tRPAREN );
validateToken( IToken.tRPAREN );
validateToken( IToken.tCOMMA );
validateToken( IToken.tLPAREN );
validateIdentifier( "boo" ); //$NON-NLS-1$
validateToken( IToken.tRPAREN );
validateToken( IToken.tRPAREN );
validateToken( IToken.tRPAREN );
validateToken( IToken.tRPAREN );
validateToken( IToken.tRPAREN );
}
}

View file

@ -2641,10 +2641,10 @@ public class Scanner2 implements IScanner, IScannerData {
char [] expansion = null;
if( expObject instanceof FunctionStyleMacro ){
FunctionStyleMacro expMacro = (FunctionStyleMacro) expObject;
pushContext( ( start == 0 ) ? arg : CharArrayUtils.extract( arg, start, arg.length - start + 1 ) );
pushContext( ( start == 0 ) ? arg : CharArrayUtils.extract( arg, start, arg.length - start ) );
bufferPos[bufferStackPos] += end - start + 1;
expansion = handleFunctionStyleMacro( expMacro, false );
end = bufferPos[bufferStackPos];
end = bufferPos[bufferStackPos] + start;
popContext();
} else if (expObject instanceof ObjectStyleMacro) {
ObjectStyleMacro expMacro = (ObjectStyleMacro)expObject;