mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
bug 73492 - [Scanner] Improper offset for particular IProblem
This commit is contained in:
parent
ca9852bf78
commit
14bbb07c98
3 changed files with 38 additions and 3 deletions
|
@ -1828,4 +1828,27 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
validateToken( IToken.t_true );
|
||||
validateToken( IToken.t_false);
|
||||
}
|
||||
|
||||
public void testBug73492() throws Exception{
|
||||
String code = "#define PTR void *\n" + //$NON-NLS-1$
|
||||
"PTR;\n"; //$NON-NLS-1$
|
||||
|
||||
int offset = code.indexOf("PTR;"); //$NON-NLS-1$
|
||||
initializeScanner( code );
|
||||
|
||||
IToken t = scanner.nextToken();
|
||||
assertEquals( t.getType(), IToken.t_void );
|
||||
assertEquals( t.getOffset(), offset );
|
||||
assertEquals( t.getLineNumber(), 2 );
|
||||
|
||||
t = scanner.nextToken();
|
||||
assertEquals( t.getType(), IToken.tSTAR );
|
||||
assertEquals( t.getOffset(), offset );
|
||||
assertEquals( t.getLineNumber(), 2 );
|
||||
|
||||
t = scanner.nextToken();
|
||||
assertEquals( t.getType(), IToken.tSEMI );
|
||||
assertEquals( t.getOffset(), offset + 3 );
|
||||
assertEquals( t.getLineNumber(), 2 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -842,6 +842,15 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
* @return
|
||||
*/
|
||||
private IToken newToken( int signal ) {
|
||||
if( bufferData[bufferStackPos] instanceof IMacro )
|
||||
{
|
||||
int mostRelevant;
|
||||
for( mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant )
|
||||
if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader )
|
||||
break;
|
||||
int endOffset = bufferPos[mostRelevant] - ((IMacro)bufferData[bufferStackPos]).getName().length + SimpleToken.getCharImage( signal ).length + 1;
|
||||
return new SimpleToken( signal, endOffset, getCurrentFilename(), getLineNumber( bufferPos[mostRelevant] + 1));
|
||||
}
|
||||
return new SimpleToken(signal, bufferPos[bufferStackPos] + 1 , getCurrentFilename(), getLineNumber( bufferPos[bufferStackPos] + 1) );
|
||||
}
|
||||
|
||||
|
@ -853,7 +862,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
for( mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant )
|
||||
if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader )
|
||||
break;
|
||||
return new ImagedExpansionToken( signal, buffer, bufferPos[mostRelevant], ((IMacro)bufferData[bufferStackPos]).getName().length, getCurrentFilename(), getLineNumber( bufferPos[bufferStackPos] + 1));
|
||||
return new ImagedExpansionToken( signal, buffer, bufferPos[mostRelevant], ((IMacro)bufferData[bufferStackPos]).getName().length, getCurrentFilename(), getLineNumber( bufferPos[mostRelevant] + 1));
|
||||
}
|
||||
IToken i = new ImagedToken(signal, buffer, bufferPos[bufferStackPos] + 1 , getCurrentFilename(), getLineNumber( bufferPos[bufferStackPos] + 1));
|
||||
if( buffer != null && buffer.length == 0 )
|
||||
|
|
|
@ -315,11 +315,14 @@ public class SimpleToken extends AbstractToken implements IToken {
|
|||
// do nothing
|
||||
}
|
||||
|
||||
public char[] getCharImage() {
|
||||
return getCharImage( getType() );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IToken#getCharImage()
|
||||
*/
|
||||
public char[] getCharImage() {
|
||||
switch ( getType() ) {
|
||||
static public char[] getCharImage( int type ){
|
||||
switch ( type ) {
|
||||
case IToken.tCOLONCOLON : return Keywords.cpCOLONCOLON;
|
||||
case IToken.tCOLON : return Keywords.cpCOLON;
|
||||
case IToken.tSEMI : return Keywords.cpSEMI;
|
||||
|
|
Loading…
Add table
Reference in a new issue