mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Patch for Devin Steffler.
Fixed 79787 - [Scanner] #error has extra \r character at the end Fixed 79490 - [Scanner] char constants not evaluated properly with #if
This commit is contained in:
parent
371b6dba53
commit
053748815b
4 changed files with 71 additions and 1 deletions
|
@ -2498,5 +2498,21 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
|
|||
writer.write("if(VAL > VAL) { /* Syntax error is here */\n}\n}\n"); //$NON-NLS-1$
|
||||
parse(writer.toString());
|
||||
}
|
||||
|
||||
public void testBug79787() throws Exception {
|
||||
try {
|
||||
parse("#error what?\r\n");
|
||||
} catch (ParserException pe) {
|
||||
// expected IProblem
|
||||
} finally {
|
||||
Iterator probs = callback.getProblems();
|
||||
assertTrue(probs.hasNext());
|
||||
Object ipo = probs.next();
|
||||
assertTrue(ipo instanceof IProblem);
|
||||
IProblem ip = (IProblem) ipo;
|
||||
assertEquals(ip.getArguments(), "what?");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2266,4 +2266,32 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
validateToken( IToken.tSEMI );
|
||||
validateEOF();
|
||||
}
|
||||
|
||||
public void testBug79490A() throws Exception {
|
||||
Writer writer = new StringWriter();
|
||||
writer.write("#define TEST 'n'\n"); //$NON-NLS-1$
|
||||
writer.write("#if TEST == 'y'\n"); //$NON-NLS-1$
|
||||
writer.write("#define TRUE 1\n"); //$NON-NLS-1$
|
||||
writer.write("#else\n"); //$NON-NLS-1$
|
||||
writer.write("#define FALSE 1\n"); //$NON-NLS-1$
|
||||
writer.write("#endif\n"); //$NON-NLS-1$
|
||||
initializeScanner( writer.toString() );
|
||||
validateEOF();
|
||||
validateDefinition("TEST", "'n'"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("FALSE", "1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public void testBug79490B() throws Exception {
|
||||
Writer writer = new StringWriter();
|
||||
writer.write("#define TEST 'y'\n"); //$NON-NLS-1$
|
||||
writer.write("#if TEST == 'y'\n"); //$NON-NLS-1$
|
||||
writer.write("#define TRUE 1\n"); //$NON-NLS-1$
|
||||
writer.write("#else\n"); //$NON-NLS-1$
|
||||
writer.write("#define FALSE 1\n"); //$NON-NLS-1$
|
||||
writer.write("#endif\n"); //$NON-NLS-1$
|
||||
initializeScanner( writer.toString() );
|
||||
validateEOF();
|
||||
validateDefinition("TEST", "'y'"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("TRUE", "1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
|
|
@ -254,6 +254,8 @@ public class ExpressionEvaluator {
|
|||
}
|
||||
handleProblem(IProblem.SCANNER_MISSING_R_PAREN, pos);
|
||||
throw new EvalException("missing )"); //$NON-NLS-1$
|
||||
case tCHAR:
|
||||
return getChar();
|
||||
default:
|
||||
handleProblem(IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR, pos);
|
||||
throw new EvalException("expression syntax error"); //$NON-NLS-1$
|
||||
|
@ -332,6 +334,21 @@ public class ExpressionEvaluator {
|
|||
return value;
|
||||
}
|
||||
|
||||
private long getChar() throws EvalException {
|
||||
long value = 0;
|
||||
|
||||
// if getting a character then make sure it's in '' otherwise leave it as 0
|
||||
if (bufferPos[bufferStackPos] - 1 >= 0 &&
|
||||
bufferPos[bufferStackPos] + 1 < bufferStack[bufferStackPos].length
|
||||
&& bufferStack[bufferStackPos][bufferPos[bufferStackPos] - 1] == '\''
|
||||
&& bufferStack[bufferStackPos][bufferPos[bufferStackPos] + 1] == '\'')
|
||||
value = bufferStack[bufferStackPos][bufferPos[bufferStackPos]];
|
||||
|
||||
if (tokenType != tEOF)
|
||||
nextToken();
|
||||
return value;
|
||||
}
|
||||
|
||||
private static char[] _defined = "defined".toCharArray(); //$NON-NLS-1$
|
||||
|
||||
private void nextToken() throws EvalException {
|
||||
|
@ -472,6 +489,11 @@ public class ExpressionEvaluator {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (len == 1) { // is a character
|
||||
tokenType = tCHAR;
|
||||
return;
|
||||
}
|
||||
|
||||
// undefined macro, assume 0
|
||||
tokenValue = 0;
|
||||
tokenType = tNUMBER;
|
||||
|
@ -878,6 +900,7 @@ public class ExpressionEvaluator {
|
|||
private static final int tQUESTION = 25;
|
||||
private static final int tCOLON = 26;
|
||||
private static final int t_defined = 27;
|
||||
private static final int tCHAR = 28;
|
||||
|
||||
private void pushContext(char[] buffer, Object data) {
|
||||
if (++bufferStackPos == bufferStack.length) {
|
||||
|
|
|
@ -1538,7 +1538,10 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
skipOverWhiteSpace();
|
||||
start = bufferPos[bufferStackPos] + 1;
|
||||
skipToNewLine();
|
||||
len = bufferPos[bufferStackPos] - start;
|
||||
if (bufferPos[bufferStackPos] - 1 > 0 && buffer[bufferPos[bufferStackPos] - 1] == '\r')
|
||||
len = bufferPos[bufferStackPos] - start - 1;
|
||||
else
|
||||
len = bufferPos[bufferStackPos] - start;
|
||||
handleProblem( IProblem.PREPROCESSOR_POUND_ERROR, start, CharArrayUtils.extract( buffer, start, len ));
|
||||
break;
|
||||
case ppEndif:
|
||||
|
|
Loading…
Add table
Reference in a new issue