mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 02:36:01 +02:00
Fix for 104014 by Sergey Prigogin, empty macro parameters.
This commit is contained in:
parent
d94962d1e8
commit
3871a214a0
4 changed files with 72 additions and 36 deletions
|
@ -101,22 +101,4 @@ public class AST2CSpecFailingTest extends AST2SpecBaseTest {
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
[--Start Example(C 6.10.3.5-7):
|
|
||||||
#define t(x,y,z) x ## y ## z
|
|
||||||
int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),
|
|
||||||
t(10,,), t(,11,), t(,,12), t(,,) };
|
|
||||||
--End Example]
|
|
||||||
*/
|
|
||||||
public void test6_10_3_5s7() throws Exception {
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
buffer.append("#define t(x,y,z) x ## y ## z\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),\n"); //$NON-NLS-1$
|
|
||||||
buffer.append("t(10,,), t(,11,), t(,,12), t(,,) };\n"); //$NON-NLS-1$
|
|
||||||
try {
|
|
||||||
parseCandCPP(buffer.toString(), true, 0);
|
|
||||||
assertTrue(false);
|
|
||||||
} catch (Exception e) {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1957,6 +1957,21 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
|
||||||
parseCandCPP(buffer.toString(), false, 0);
|
parseCandCPP(buffer.toString(), false, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
[--Start Example(C 6.10.3.5-7):
|
||||||
|
#define t(x,y,z) x ## y ## z
|
||||||
|
int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),
|
||||||
|
t(10,,), t(,11,), t(,,12), t(,,) };
|
||||||
|
--End Example]
|
||||||
|
*/
|
||||||
|
public void test6_10_3_5s7() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("#define t(x,y,z) x ## y ## z\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("t(10,,), t(,11,), t(,,12), t(,,) };\n"); //$NON-NLS-1$
|
||||||
|
parseCandCPP(buffer.toString(), true, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
[--Start Example(C 6.10.3.5-8):
|
[--Start Example(C 6.10.3.5-8):
|
||||||
#define OBJ_LIKE1 (1-1)
|
#define OBJ_LIKE1 (1-1)
|
||||||
|
|
|
@ -79,8 +79,44 @@ public class Scanner2Test extends BaseScanner2Test
|
||||||
assertEquals( callback.problems.size(), 0 );
|
assertEquals( callback.problems.size(), 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TableRow
|
public void testBug195610_1() throws Exception {
|
||||||
{
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("#define glue(x, y, z) x ## y ## z\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("glue(, b, c)\n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
initializeScanner(buffer.toString());
|
||||||
|
Callback callback = new Callback(ParserMode.QUICK_PARSE);
|
||||||
|
initializeScanner(buffer.toString(), ParserMode.QUICK_PARSE, callback);
|
||||||
|
validateIdentifier("bc"); //$NON-NLS-1$
|
||||||
|
assertEquals(callback.problems.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBug195610_2() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("#define glue(x, y, z) x ## y ## z\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("glue(a, , c)\n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
initializeScanner(buffer.toString());
|
||||||
|
Callback callback = new Callback(ParserMode.QUICK_PARSE);
|
||||||
|
initializeScanner(buffer.toString(), ParserMode.QUICK_PARSE, callback);
|
||||||
|
validateIdentifier("ac"); //$NON-NLS-1$
|
||||||
|
assertEquals(callback.problems.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBug195610_3() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("#define glue(x, y, z) x ## y ## z\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("glue(a, b, )\n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
initializeScanner(buffer.toString());
|
||||||
|
Callback callback = new Callback(ParserMode.QUICK_PARSE);
|
||||||
|
initializeScanner(buffer.toString(), ParserMode.QUICK_PARSE, callback);
|
||||||
|
validateIdentifier("ab"); //$NON-NLS-1$
|
||||||
|
assertEquals(callback.problems.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TableRow
|
||||||
|
{
|
||||||
private int[] values;
|
private int[] values;
|
||||||
private int length;
|
private int length;
|
||||||
|
|
||||||
|
|
|
@ -3202,10 +3202,8 @@ abstract class BaseScanner implements IScanner {
|
||||||
escaped = false;
|
escaped = false;
|
||||||
}
|
}
|
||||||
bufferPos[bufferStackPos]= pos;
|
bufferPos[bufferStackPos]= pos;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected char[] handleFunctionStyleMacro(FunctionStyleMacro macro,
|
protected char[] handleFunctionStyleMacro(FunctionStyleMacro macro,
|
||||||
boolean pushContext) {
|
boolean pushContext) {
|
||||||
char[] buffer = bufferStack[bufferStackPos];
|
char[] buffer = bufferStack[bufferStackPos];
|
||||||
|
@ -3278,24 +3276,31 @@ abstract class BaseScanner implements IScanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
char[][] arglist = macro.arglist;
|
char[][] arglist = macro.arglist;
|
||||||
int currarg = -1;
|
int currarg = 0;
|
||||||
CharArrayObjectMap argmap = new CharArrayObjectMap(arglist.length);
|
CharArrayObjectMap argmap = new CharArrayObjectMap(arglist.length);
|
||||||
|
|
||||||
boolean insideString = false;
|
boolean insideString = false;
|
||||||
while (bufferPos[bufferStackPos] < limit) {
|
while (bufferPos[bufferStackPos] < limit) {
|
||||||
skipOverWhiteSpace();
|
skipOverWhiteSpace();
|
||||||
|
|
||||||
if( bufferPos[bufferStackPos] + 1 >= limit )
|
if (bufferPos[bufferStackPos] + 1 >= limit)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (buffer[++bufferPos[bufferStackPos]] == ')') {
|
if (buffer[++bufferPos[bufferStackPos]] == ')') {
|
||||||
// end of macro
|
if (currarg > 0 && argmap.size() <= currarg) {
|
||||||
break;
|
argmap.put(arglist[currarg], EMPTY_CHAR_ARRAY);
|
||||||
} else if (buffer[bufferPos[bufferStackPos]] == ',') {
|
}
|
||||||
|
break; // end of macro
|
||||||
|
}
|
||||||
|
if (buffer[bufferPos[bufferStackPos]] == ',') {
|
||||||
|
if (argmap.size() <= currarg) {
|
||||||
|
argmap.put(arglist[currarg], EMPTY_CHAR_ARRAY);
|
||||||
|
}
|
||||||
|
currarg++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((++currarg >= arglist.length || arglist[currarg] == null)
|
if ((currarg >= arglist.length || arglist[currarg] == null)
|
||||||
&& !macro.hasVarArgs() && !macro.hasGCCVarArgs()) {
|
&& !macro.hasVarArgs() && !macro.hasGCCVarArgs()) {
|
||||||
// too many args and no variable argument
|
// too many args and no variable argument
|
||||||
handleProblem(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR,
|
handleProblem(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR,
|
||||||
|
@ -3308,14 +3313,11 @@ abstract class BaseScanner implements IScanner {
|
||||||
int argend = -1;
|
int argend = -1;
|
||||||
if ((macro.hasGCCVarArgs() || macro.hasVarArgs())
|
if ((macro.hasGCCVarArgs() || macro.hasVarArgs())
|
||||||
&& currarg == macro.getVarArgsPosition()) {
|
&& currarg == macro.getVarArgsPosition()) {
|
||||||
--bufferPos[bufferStackPos]; // go back to first char of macro
|
--bufferPos[bufferStackPos]; // go back to first char of macro arguments
|
||||||
// args
|
|
||||||
|
|
||||||
// there are varargs and the other parms have been accounted
|
// there are varargs and the other parameters have been accounted
|
||||||
// for,
|
// for, the rest will replace __VA_ARGS__ or name where
|
||||||
// the rest will replace __VA_ARGS__ or name where "name..." is
|
// "name..." is the parameter
|
||||||
// the
|
|
||||||
// parm
|
|
||||||
do {
|
do {
|
||||||
if (buffer[bufferPos[bufferStackPos]] == '"') {
|
if (buffer[bufferPos[bufferStackPos]] == '"') {
|
||||||
if (insideString)
|
if (insideString)
|
||||||
|
@ -3331,8 +3333,9 @@ abstract class BaseScanner implements IScanner {
|
||||||
}
|
}
|
||||||
} while (++bufferPos[bufferStackPos] < limit);
|
} while (++bufferPos[bufferStackPos] < limit);
|
||||||
argend = bufferPos[bufferStackPos];
|
argend = bufferPos[bufferStackPos];
|
||||||
} else
|
} else {
|
||||||
argend = skipOverMacroArg();
|
argend = skipOverMacroArg();
|
||||||
|
}
|
||||||
|
|
||||||
// correct argend when reaching limit, (bug 179383)
|
// correct argend when reaching limit, (bug 179383)
|
||||||
if (argend==limit) {
|
if (argend==limit) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue