1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 08:45:44 +02:00

Fixed a few incorrect locations/offsets.

This commit is contained in:
John Camelon 2005-01-27 16:55:20 +00:00
parent 493b29d4e4
commit 9592a5366f
4 changed files with 40 additions and 7 deletions

View file

@ -25,7 +25,8 @@ public interface IASTUnaryExpression extends IASTExpression {
public static final int op_sizeof = 8; public static final int op_sizeof = 8;
public static final int op_postFixIncr = 9; public static final int op_postFixIncr = 9;
public static final int op_postFixDecr = 10; public static final int op_postFixDecr = 10;
public static final int op_last = op_postFixDecr; public static final int op_bracketedPrimary = 11;
public static final int op_last = op_bracketedPrimary;
public int getOperator(); public int getOperator();
public void setOperator( int value ); public void setOperator( int value );

View file

@ -1124,8 +1124,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
t = consume(); t = consume();
//TODO - do we need to return a wrapper? //TODO - do we need to return a wrapper?
IASTExpression lhs = expression(); IASTExpression lhs = expression();
consume(IToken.tRPAREN); int finalOffset = consume(IToken.tRPAREN).getEndOffset();
return lhs; return buildUnaryExpression( IASTUnaryExpression.op_bracketedPrimary, lhs, t.getOffset(), finalOffset );
case IToken.tIDENTIFIER: case IToken.tIDENTIFIER:
int startingOffset = LA(1).getOffset(); int startingOffset = LA(1).getOffset();
@ -1694,6 +1694,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
d.setInitializer(i); d.setInitializer(i);
i.setParent(d); i.setParent(d);
i.setPropertyInParent(IASTDeclarator.INITIALIZER); i.setPropertyInParent(IASTDeclarator.INITIALIZER);
((ASTNode)d).setLength( calculateEndOffset( i ) - ((ASTNode)d).getOffset() );
} }
return d; return d;
} finally { } finally {

View file

@ -1675,13 +1675,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (templateIdScopes.size() > 0) { if (templateIdScopes.size() > 0) {
templateIdScopes.push(IToken.tLPAREN); templateIdScopes.push(IToken.tLPAREN);
} }
//TODO We need to wrap this
IASTExpression lhs = expression(); IASTExpression lhs = expression();
consume(IToken.tRPAREN).getEndOffset(); int finalOffset = consume(IToken.tRPAREN).getEndOffset();
if (templateIdScopes.size() > 0) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
} }
return lhs; return buildUnaryExpression( IASTUnaryExpression.op_bracketedPrimary, lhs, t.getOffset(), finalOffset );
case IToken.tIDENTIFIER: case IToken.tIDENTIFIER:
case IToken.tCOLONCOLON: case IToken.tCOLONCOLON:
case IToken.t_operator: case IToken.t_operator:
@ -3317,6 +3316,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
d.setInitializer(initializer); d.setInitializer(initializer);
initializer.setParent(d); initializer.setParent(d);
initializer.setPropertyInParent(IASTDeclarator.INITIALIZER); initializer.setPropertyInParent(IASTDeclarator.INITIALIZER);
((ASTNode)d).setLength( calculateEndOffset( initializer ) - ((ASTNode)d).getOffset() );
} }
return d; return d;

View file

@ -10,6 +10,8 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.token; package org.eclipse.cdt.internal.core.parser.token;
import org.eclipse.cdt.core.parser.IToken;
/** /**
* @author johnc * @author johnc
@ -47,10 +49,39 @@ public class ImagedToken extends SimpleToken {
{ {
this.image = image; this.image = image;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.token.SimpleToken#getOffset()
*/
public int getOffset() {
int s_val = super.getOffset();
switch( getType() )
{
case IToken.tSTRING:
case IToken.tCHAR:
return s_val;
case IToken.tLSTRING:
case IToken.tLCHAR:
return s_val - 1;
default:
return s_val;
}
}
public int getLength() { public int getLength() {
if( getCharImage() == null ) if( getCharImage() == null )
return 0; return 0;
return getCharImage().length; int s_length = getCharImage().length;
switch( getType() )
{
case IToken.tSTRING:
case IToken.tCHAR:
return s_length + 2;
case IToken.tLSTRING:
case IToken.tLCHAR:
return s_length + 3;
default:
return s_length;
}
} }
} }