mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixed Bug 71839 [Parser] Parser in infinite loop (ExpressionParser.errorHandling())
This commit is contained in:
parent
f110584379
commit
b9768b37d5
2 changed files with 26 additions and 46 deletions
|
@ -558,7 +558,7 @@ public class Scanner2Test extends BaseScanner2Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIfs()
|
public void testIfs() throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -601,34 +601,24 @@ public class Scanner2Test extends BaseScanner2Test
|
||||||
fail(EXCEPTION_THROWN + e.toString());
|
fail(EXCEPTION_THROWN + e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
Callback callback = new Callback( ParserMode.QUICK_PARSE );
|
||||||
{
|
initializeScanner(
|
||||||
initializeScanner(
|
"#ifndef FIVE \n" + //$NON-NLS-1$
|
||||||
"#ifndef FIVE \n" + //$NON-NLS-1$
|
"#define FIVE 5\n" + //$NON-NLS-1$
|
||||||
"#define FIVE 5\n" + //$NON-NLS-1$
|
"#endif \n" + //$NON-NLS-1$
|
||||||
"#endif \n" + //$NON-NLS-1$
|
"#ifndef TEN\n" + //$NON-NLS-1$
|
||||||
"#ifndef TEN\n" + //$NON-NLS-1$
|
"#define TEN 2 * FIVE\n" + //$NON-NLS-1$
|
||||||
"#define TEN 2 * FIVE\n" + //$NON-NLS-1$
|
"#endif\n" + //$NON-NLS-1$
|
||||||
"#endif\n" + //$NON-NLS-1$
|
"#if TEN != 10\n" + //$NON-NLS-1$
|
||||||
"#if TEN != 10\n" + //$NON-NLS-1$
|
"#define MISTAKE 1\n" + //$NON-NLS-1$
|
||||||
"#define MISTAKE 1\n" + //$NON-NLS-1$
|
"#error Five does not equal 10\n" + //$NON-NLS-1$
|
||||||
"#error Five does not equal 10\n" + //$NON-NLS-1$
|
"#endif\n", ParserMode.QUICK_PARSE, callback); //$NON-NLS-1$
|
||||||
"#endif\n"); //$NON-NLS-1$
|
scanner.addDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
scanner.addDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$
|
validateEOF();
|
||||||
validateEOF();
|
validateDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
fail(EXPECTED_FAILURE);
|
validateDefinition("TEN", "2 * FIVE"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
validateDefinition("MISTAKE", "1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
catch (ScannerException se)
|
assertFalse( callback.problems.isEmpty() );
|
||||||
{
|
|
||||||
validateBalance(1);
|
|
||||||
validateDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
validateDefinition("TEN", "2 * FIVE"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
validateDefinition("MISTAKE", "1"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
fail(EXCEPTION_THROWN + e.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -669,22 +659,8 @@ public class Scanner2Test extends BaseScanner2Test
|
||||||
fail(EXCEPTION_THROWN + e.toString());
|
fail(EXCEPTION_THROWN + e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
initializeScanner("#if ! 0\n#error Correct!\n#endif"); //$NON-NLS-1$
|
||||||
{
|
validateEOF();
|
||||||
initializeScanner("#if ! 0\n#error Correct!\n#endif"); //$NON-NLS-1$
|
|
||||||
scanner.nextToken();
|
|
||||||
fail(EXPECTED_FAILURE);
|
|
||||||
}
|
|
||||||
catch (ScannerException se)
|
|
||||||
{
|
|
||||||
validateBalance(1);
|
|
||||||
// TODO define problems
|
|
||||||
//assertEquals( se.getProblem().getID(), IProblem.PREPROCESSOR_POUND_ERROR);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
fail(EXCEPTION_THROWN + e.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPreprocessorMacros()
|
public void testPreprocessorMacros()
|
||||||
|
|
|
@ -1294,7 +1294,11 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
handleInvalidCompletion();
|
handleInvalidCompletion();
|
||||||
return;
|
return;
|
||||||
case ppError:
|
case ppError:
|
||||||
throw new ScannerException(null);
|
start = bufferPos[bufferStackPos];
|
||||||
|
skipToNewLine();
|
||||||
|
len = bufferPos[bufferStackPos] - start;
|
||||||
|
handleProblem( IProblem.PREPROCESSOR_POUND_ERROR, start, CharArrayUtils.extract( buffer, start, len ));
|
||||||
|
break;
|
||||||
case ppEndif:
|
case ppEndif:
|
||||||
if( !branchState( BRANCH_END ) )
|
if( !branchState( BRANCH_END ) )
|
||||||
handleProblem( IProblem.PREPROCESSOR_UNBALANCE_CONDITION, start, ppKeywords.findKey( buffer, start, len ) );
|
handleProblem( IProblem.PREPROCESSOR_UNBALANCE_CONDITION, start, ppKeywords.findKey( buffer, start, len ) );
|
||||||
|
|
Loading…
Add table
Reference in a new issue