1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 03:53:21 +02:00
John Camelon 2004-05-13 19:40:39 +00:00
parent c70cea46dc
commit b1157be81c
4 changed files with 27 additions and 9 deletions

View file

@ -1562,4 +1562,20 @@ public class ScannerTestCase extends BaseScannerTest
validateEOF();
assertFalse( callback.problems.isEmpty() );
}
public void testBug61968() throws Exception
{
Writer writer = new StringWriter();
writer.write( "unsigned int ui = 2172748163; //ok \n" ); //$NON-NLS-1$
writer.write( "int big = 999999999999999;//ok \n" ); //$NON-NLS-1$
writer.write( "void main() { \n" ); //$NON-NLS-1$
writer.write( "caller(4); //ok\n" ); //$NON-NLS-1$
writer.write( "caller(2172748163);//causes java.lang.NumberFormatException \n" ); //$NON-NLS-1$
writer.write( "caller(999999999999999); //also causes NumberFormatException \n" ); //$NON-NLS-1$
writer.write( "}\n" ); //$NON-NLS-1$
Callback callback = new Callback(ParserMode.QUICK_PARSE);
initializeScanner( writer.toString(), ParserMode.QUICK_PARSE, callback );
fullyTokenize();
assertTrue( callback.problems.isEmpty() );
}
}

View file

@ -25,9 +25,9 @@ public class IntegerExpansionToken extends SimpleExpansionToken implements INume
* @param value
* @param stack
*/
public IntegerExpansionToken(int tokenType, int value, ContextStack stack) {
public IntegerExpansionToken(int tokenType, long l, ContextStack stack) {
super( tokenType, stack );
this.value = value;
this.value = l;
}

View file

@ -25,9 +25,9 @@ public class IntegerToken extends SimpleToken implements INumericToken {
* @param value
* @param stack
*/
public IntegerToken(int tokenType, int value, ContextStack stack) {
public IntegerToken(int tokenType, long l, ContextStack stack) {
super( tokenType, stack );
this.value = value;
this.value = l;
}
/* (non-Javadoc)

View file

@ -19,21 +19,23 @@ import org.eclipse.cdt.internal.core.parser.scanner.IScannerData;
*/
public class TokenFactory {
static final String MAX_LONG_STRING = Long.toString( Long.MAX_VALUE );
static final String MAX_HEX_LONG_STRING = "0x" + Long.toString( Long.MAX_VALUE, 16 ); //$NON-NLS-1$
public static IToken createIntegerToken( String value, IScannerData scannerData )
{
if( value.length() > 15 )
if( value.compareTo( MAX_LONG_STRING ) > 0 )
return createUniquelyImagedToken( IToken.tINTEGER, value, scannerData );
if( scannerData.getContextStack().getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION )
return new IntegerExpansionToken( IToken.tINTEGER, Integer.parseInt(value ), scannerData.getContextStack() );
return new IntegerExpansionToken( IToken.tINTEGER, Long.parseLong(value ), scannerData.getContextStack() );
return new IntegerToken( IToken.tINTEGER, Integer.parseInt( value ), scannerData.getContextStack() );
return new IntegerToken( IToken.tINTEGER, Long.parseLong( value ), scannerData.getContextStack() );
}
public static IToken createHexadecimalIntegerToken( String value, IScannerData scannerData )
{
if( value.length() > 15 )
if( value.compareTo( MAX_HEX_LONG_STRING ) > 0 )
return createUniquelyImagedToken( IToken.tHEXINT, value, scannerData );
if( scannerData.getContextStack().getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION )
return new HexIntegerExpansionToken( IToken.tHEXINT, value, scannerData.getContextStack() );