mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Fixed Bug 84149 - a couple problems with getinp (example taken from monop)
Fixed offsets & lengths of char and string literals.
This commit is contained in:
parent
08e9d350ae
commit
cb6ce7f886
2 changed files with 24 additions and 21 deletions
|
@ -1106,8 +1106,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
literalExpression.setKind(IASTLiteralExpression.lk_char_constant);
|
||||
literalExpression.setValue(t.getImage());
|
||||
((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t
|
||||
.getEndOffset()
|
||||
- t.getOffset());
|
||||
.getLength() );
|
||||
return literalExpression;
|
||||
case IToken.tLPAREN:
|
||||
t = consume();
|
||||
|
@ -1891,6 +1890,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTDeclarator d = null;
|
||||
if (numKnRCParms > 0) {
|
||||
ICASTKnRFunctionDeclarator functionDecltor = createKnRFunctionDeclarator();
|
||||
parmDeclarations = removeNullDeclarations( parmDeclarations );
|
||||
for (int i = 0; i < parmDeclarations.length; ++i) {
|
||||
if (parmDeclarations[i] != null
|
||||
&& !(parmDeclarations[i] instanceof IASTProblemDeclaration)) {
|
||||
|
@ -1964,6 +1964,28 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parmDeclarations
|
||||
* @return
|
||||
*/
|
||||
private IASTDeclaration[] removeNullDeclarations(IASTDeclaration[] parmDeclarations) {
|
||||
int nullCount = 0;
|
||||
for( int i = 0; i < parmDeclarations.length; ++i )
|
||||
{
|
||||
if( parmDeclarations[i] == null )
|
||||
++nullCount;
|
||||
}
|
||||
if( nullCount == 0 ) return parmDeclarations;
|
||||
IASTDeclaration [] result = new IASTDeclaration[ parmDeclarations.length - nullCount ];
|
||||
int count = 0;
|
||||
for( int i = 0; i < parmDeclarations.length; ++i )
|
||||
{
|
||||
if( parmDeclarations[i] != null )
|
||||
result[count++] = parmDeclarations[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected IASTArrayDeclarator createArrayDeclarator() {
|
||||
return new CASTArrayDeclarator();
|
||||
}
|
||||
|
|
|
@ -50,23 +50,6 @@ public class ImagedToken extends SimpleToken {
|
|||
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() {
|
||||
if( getCharImage() == null )
|
||||
|
@ -75,10 +58,8 @@ public class ImagedToken extends SimpleToken {
|
|||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue