mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +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);
|
||||
} 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);
|
||||
}
|
||||
|
||||
/**
|
||||
[--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):
|
||||
#define OBJ_LIKE1 (1-1)
|
||||
|
|
|
@ -79,8 +79,44 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
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 length;
|
||||
|
||||
|
|
|
@ -3202,10 +3202,8 @@ abstract class BaseScanner implements IScanner {
|
|||
escaped = false;
|
||||
}
|
||||
bufferPos[bufferStackPos]= pos;
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected char[] handleFunctionStyleMacro(FunctionStyleMacro macro,
|
||||
boolean pushContext) {
|
||||
char[] buffer = bufferStack[bufferStackPos];
|
||||
|
@ -3278,24 +3276,31 @@ abstract class BaseScanner implements IScanner {
|
|||
}
|
||||
|
||||
char[][] arglist = macro.arglist;
|
||||
int currarg = -1;
|
||||
int currarg = 0;
|
||||
CharArrayObjectMap argmap = new CharArrayObjectMap(arglist.length);
|
||||
|
||||
boolean insideString = false;
|
||||
while (bufferPos[bufferStackPos] < limit) {
|
||||
skipOverWhiteSpace();
|
||||
|
||||
if( bufferPos[bufferStackPos] + 1 >= limit )
|
||||
if (bufferPos[bufferStackPos] + 1 >= limit)
|
||||
break;
|
||||
|
||||
if (buffer[++bufferPos[bufferStackPos]] == ')') {
|
||||
// end of macro
|
||||
break;
|
||||
} else if (buffer[bufferPos[bufferStackPos]] == ',') {
|
||||
if (currarg > 0 && argmap.size() <= currarg) {
|
||||
argmap.put(arglist[currarg], EMPTY_CHAR_ARRAY);
|
||||
}
|
||||
break; // end of macro
|
||||
}
|
||||
if (buffer[bufferPos[bufferStackPos]] == ',') {
|
||||
if (argmap.size() <= currarg) {
|
||||
argmap.put(arglist[currarg], EMPTY_CHAR_ARRAY);
|
||||
}
|
||||
currarg++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((++currarg >= arglist.length || arglist[currarg] == null)
|
||||
if ((currarg >= arglist.length || arglist[currarg] == null)
|
||||
&& !macro.hasVarArgs() && !macro.hasGCCVarArgs()) {
|
||||
// too many args and no variable argument
|
||||
handleProblem(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR,
|
||||
|
@ -3308,14 +3313,11 @@ abstract class BaseScanner implements IScanner {
|
|||
int argend = -1;
|
||||
if ((macro.hasGCCVarArgs() || macro.hasVarArgs())
|
||||
&& currarg == macro.getVarArgsPosition()) {
|
||||
--bufferPos[bufferStackPos]; // go back to first char of macro
|
||||
// args
|
||||
--bufferPos[bufferStackPos]; // go back to first char of macro arguments
|
||||
|
||||
// there are varargs and the other parms have been accounted
|
||||
// for,
|
||||
// the rest will replace __VA_ARGS__ or name where "name..." is
|
||||
// the
|
||||
// parm
|
||||
// there are varargs and the other parameters have been accounted
|
||||
// for, the rest will replace __VA_ARGS__ or name where
|
||||
// "name..." is the parameter
|
||||
do {
|
||||
if (buffer[bufferPos[bufferStackPos]] == '"') {
|
||||
if (insideString)
|
||||
|
@ -3331,8 +3333,9 @@ abstract class BaseScanner implements IScanner {
|
|||
}
|
||||
} while (++bufferPos[bufferStackPos] < limit);
|
||||
argend = bufferPos[bufferStackPos];
|
||||
} else
|
||||
} else {
|
||||
argend = skipOverMacroArg();
|
||||
}
|
||||
|
||||
// correct argend when reaching limit, (bug 179383)
|
||||
if (argend==limit) {
|
||||
|
|
Loading…
Add table
Reference in a new issue