mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
fix expansion of macros used as parameters to function-like macros
This commit is contained in:
parent
4761007499
commit
ee74068fe8
2 changed files with 33 additions and 2 deletions
|
@ -2191,4 +2191,35 @@ public class Scanner2Test extends BaseScanner2Test
|
||||||
|
|
||||||
validateEOF();
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2641,10 +2641,10 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
char [] expansion = null;
|
char [] expansion = null;
|
||||||
if( expObject instanceof FunctionStyleMacro ){
|
if( expObject instanceof FunctionStyleMacro ){
|
||||||
FunctionStyleMacro expMacro = (FunctionStyleMacro) expObject;
|
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;
|
bufferPos[bufferStackPos] += end - start + 1;
|
||||||
expansion = handleFunctionStyleMacro( expMacro, false );
|
expansion = handleFunctionStyleMacro( expMacro, false );
|
||||||
end = bufferPos[bufferStackPos];
|
end = bufferPos[bufferStackPos] + start;
|
||||||
popContext();
|
popContext();
|
||||||
} else if (expObject instanceof ObjectStyleMacro) {
|
} else if (expObject instanceof ObjectStyleMacro) {
|
||||||
ObjectStyleMacro expMacro = (ObjectStyleMacro)expObject;
|
ObjectStyleMacro expMacro = (ObjectStyleMacro)expObject;
|
||||||
|
|
Loading…
Add table
Reference in a new issue