mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 15:25:49 +02:00
Patch for Devin Steffler.
Bug 86870 [Offsets] simple #if/#define example seems flaky with offset/length
This commit is contained in:
parent
98fa5f404a
commit
4f2422d695
2 changed files with 59 additions and 9 deletions
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
|
@ -1510,6 +1511,54 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest {
|
|||
assertTrue(name.resolveBinding() instanceof IVariable);
|
||||
}
|
||||
|
||||
public void testBug86870() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("#if VERSION == 1\r\n"); //$NON-NLS-1$
|
||||
buffer.append("#define INCFILE \"vers1.h\"\r\n"); //$NON-NLS-1$
|
||||
buffer.append("#elif VERSION == 2\r\n"); //$NON-NLS-1$
|
||||
buffer.append("#define INCFILE \"vers2.h\" /* and so on */\r\n"); //$NON-NLS-1$
|
||||
buffer.append("#else\r\n"); //$NON-NLS-1$
|
||||
buffer.append("#define INCFILE \"versN.h\"\r\n"); //$NON-NLS-1$
|
||||
buffer.append("#endif\r\n"); //$NON-NLS-1$
|
||||
|
||||
String code = buffer.toString();
|
||||
int offset1 = code.indexOf( "#if VERSION == 1" ); //$NON-NLS-1$
|
||||
int length = "#if VERSION == 1".length(); //$NON-NLS-1$
|
||||
IASTNode node = parse( code, ParserLanguage.C, offset1, length );
|
||||
assertNotNull(node);
|
||||
assertEquals( ((ASTNode)node).getLength(), length);
|
||||
|
||||
offset1 = code.indexOf( "#elif VERSION == 2" ); //$NON-NLS-1$
|
||||
length = "#elif VERSION == 2".length(); //$NON-NLS-1$
|
||||
node = parse( code, ParserLanguage.C, offset1, length );
|
||||
assertNotNull(node);
|
||||
assertEquals( ((ASTNode)node).getLength(), length);
|
||||
|
||||
offset1 = code.indexOf( "#else" ); //$NON-NLS-1$
|
||||
length = "#else".length(); //$NON-NLS-1$
|
||||
node = parse( code, ParserLanguage.C, offset1, length );
|
||||
assertNotNull(node);
|
||||
assertEquals( ((ASTNode)node).getLength(), length);
|
||||
|
||||
offset1 = code.indexOf( "#define INCFILE \"versN.h\"" ); //$NON-NLS-1$
|
||||
length = "#define INCFILE \"versN.h\"".length(); //$NON-NLS-1$
|
||||
node = parse( code, ParserLanguage.C, offset1, length );
|
||||
assertNotNull(node);
|
||||
assertEquals( ((ASTNode)node).getLength(), length);
|
||||
|
||||
offset1 = code.indexOf( "INCFILE \"versN.h\"" ); //$NON-NLS-1$
|
||||
length = "INCFILE".length(); //$NON-NLS-1$
|
||||
node = parse( code, ParserLanguage.C, offset1, length );
|
||||
assertNotNull(node);
|
||||
assertEquals( ((ASTNode)node).getLength(), length);
|
||||
|
||||
offset1 = code.indexOf( "#endif" ); //$NON-NLS-1$
|
||||
length = "#endif".length(); //$NON-NLS-1$
|
||||
node = parse( code, ParserLanguage.C, offset1, length );
|
||||
assertNotNull(node);
|
||||
assertEquals( ((ASTNode)node).getLength(), length);
|
||||
}
|
||||
|
||||
public void testBug87179() throws Exception
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
|
|
@ -2583,6 +2583,9 @@ abstract class BaseScanner implements IScanner {
|
|||
handleCompletionOnExpression(CharArrayUtils.extract(
|
||||
buffer, start, len));
|
||||
branchState(BRANCH_IF);
|
||||
|
||||
processIf(pos, pos + start + len, true); // fix 86870, process IF before skipping the condition and only process it once
|
||||
|
||||
if (expressionEvaluator.evaluate(buffer, start, len,
|
||||
definitions,
|
||||
getLineNumber(bufferPos[bufferStackPos]),
|
||||
|
@ -2590,9 +2593,7 @@ abstract class BaseScanner implements IScanner {
|
|||
skipOverConditionalCode(true);
|
||||
if (isLimitReached())
|
||||
handleInvalidCompletion();
|
||||
processIf(pos, bufferPos[bufferStackPos], true);
|
||||
}
|
||||
processIf(pos, bufferPos[bufferStackPos], false);
|
||||
return;
|
||||
case ppElse:
|
||||
case ppElif:
|
||||
|
@ -3406,11 +3407,11 @@ abstract class BaseScanner implements IScanner {
|
|||
skipToNewLine();
|
||||
if (checkelse && nesting == 0) {
|
||||
processElse(startPos,
|
||||
bufferPos[bufferStackPos] + 1, true);
|
||||
bufferPos[bufferStackPos], true);
|
||||
return;
|
||||
}
|
||||
processElse(startPos,
|
||||
bufferPos[bufferStackPos] + 1, false);
|
||||
bufferPos[bufferStackPos], false);
|
||||
} else {
|
||||
//problem, ignore this one.
|
||||
handleProblem(
|
||||
|
@ -3436,15 +3437,15 @@ abstract class BaseScanner implements IScanner {
|
|||
getLineNumber(bufferPos[bufferStackPos]),
|
||||
getCurrentFilename()) != 0) {
|
||||
// condition passed, we're good
|
||||
processElsif(start,
|
||||
processElsif(startPos,
|
||||
bufferPos[bufferStackPos], true);
|
||||
return;
|
||||
}
|
||||
processElsif(start,
|
||||
processElsif(startPos,
|
||||
bufferPos[bufferStackPos], false);
|
||||
} else {
|
||||
skipToNewLine();
|
||||
processElsif(start,
|
||||
processElsif(startPos,
|
||||
bufferPos[bufferStackPos], false);
|
||||
}
|
||||
} else {
|
||||
|
@ -3890,7 +3891,7 @@ abstract class BaseScanner implements IScanner {
|
|||
break;
|
||||
} else if (!escaped && bufferPos[bufferStackPos] < limit
|
||||
&& buffer[bufferPos[bufferStackPos] + 1] == '\n') {
|
||||
bufferPos[bufferStackPos]++;
|
||||
// bufferPos[bufferStackPos]++; // Do not want to skip past the \r
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue