1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +02:00

don't expand function-like macros is they aren't followed by a (

This commit is contained in:
Andrew Niefer 2004-10-20 18:30:11 +00:00
parent f479e84d8f
commit 96930791c6
2 changed files with 20 additions and 6 deletions

View file

@ -2005,6 +2005,17 @@ public class Scanner2Test extends BaseScanner2Test
assertEquals( 0, callback.problems.size() );
}
public void testUnExpandedFunctionMacro() throws Exception{
Writer writer = new StringWriter();
writer.write( "#define foo( a ) #a \n"); //$NON-NLS-1$
writer.write( "foo( 1 ) foo \n"); //$NON-NLS-1$
initializeScanner( writer.toString() );
validateString( "1" ); //$NON-NLS-1$
validateIdentifier( "foo" ); //$NON-NLS-1$
validateEOF();
}
public void testBug39688A() throws Exception { // test valid IProblems
Writer writer = new StringWriter();
writer.write("#define decl1(type, ... \\\n ) type var;\n"); //$NON-NLS-1$

View file

@ -939,8 +939,10 @@ public class Scanner2 implements IScanner, IScannerData {
Object expObject = definitions.get(buffer, start, len);
if (expObject != null && !isLimitReached() && shouldExpandMacro( (IMacro) expObject)) {
boolean expanding = true;
if (expObject instanceof FunctionStyleMacro) {
handleFunctionStyleMacro((FunctionStyleMacro)expObject, true);
if( handleFunctionStyleMacro((FunctionStyleMacro)expObject, true) == null )
expanding = false;
} else if (expObject instanceof ObjectStyleMacro) {
ObjectStyleMacro expMacro = (ObjectStyleMacro)expObject;
char[] expText = expMacro.expansion;
@ -959,7 +961,8 @@ public class Scanner2 implements IScanner, IScannerData {
if (expText.length > 0)
pushContext(expText);
}
return new MacroExpansionToken();
if( expanding )
return new MacroExpansionToken();
}
@ -2506,10 +2509,10 @@ public class Scanner2 implements IScanner, IScannerData {
idx = indexOfNextNonWhiteSpace( bufferStack[stackpPos], bufferPos[stackpPos], bufferLimit[stackpPos] );
if( idx >= bufferLimit[stackpPos] ) continue;
if( idx > 0 && bufferStack[stackpPos][idx] == '(' ) break;
return emptyCharArray;
return null;
}
if( idx == -1 )
return emptyCharArray;
return null;
MacroData data = (MacroData) bufferData[stackpPos+1];
for( int i = bufferStackPos; i > stackpPos; i-- )
@ -2520,11 +2523,11 @@ public class Scanner2 implements IScanner, IScannerData {
limit = bufferLimit[bufferStackPos];
start = data.startOffset;
} else {
return emptyCharArray;
return null;
}
}
if( buffer[bufferPos[bufferStackPos]] != '(' )
return emptyCharArray;
return null;
char[][] arglist = macro.arglist;
int currarg = -1;