mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 22:05:44 +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.setKind(IASTLiteralExpression.lk_char_constant);
|
||||||
literalExpression.setValue(t.getImage());
|
literalExpression.setValue(t.getImage());
|
||||||
((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t
|
((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t
|
||||||
.getEndOffset()
|
.getLength() );
|
||||||
- t.getOffset());
|
|
||||||
return literalExpression;
|
return literalExpression;
|
||||||
case IToken.tLPAREN:
|
case IToken.tLPAREN:
|
||||||
t = consume();
|
t = consume();
|
||||||
|
@ -1891,6 +1890,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTDeclarator d = null;
|
IASTDeclarator d = null;
|
||||||
if (numKnRCParms > 0) {
|
if (numKnRCParms > 0) {
|
||||||
ICASTKnRFunctionDeclarator functionDecltor = createKnRFunctionDeclarator();
|
ICASTKnRFunctionDeclarator functionDecltor = createKnRFunctionDeclarator();
|
||||||
|
parmDeclarations = removeNullDeclarations( parmDeclarations );
|
||||||
for (int i = 0; i < parmDeclarations.length; ++i) {
|
for (int i = 0; i < parmDeclarations.length; ++i) {
|
||||||
if (parmDeclarations[i] != null
|
if (parmDeclarations[i] != null
|
||||||
&& !(parmDeclarations[i] instanceof IASTProblemDeclaration)) {
|
&& !(parmDeclarations[i] instanceof IASTProblemDeclaration)) {
|
||||||
|
@ -1964,6 +1964,28 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
return d;
|
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() {
|
protected IASTArrayDeclarator createArrayDeclarator() {
|
||||||
return new CASTArrayDeclarator();
|
return new CASTArrayDeclarator();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,23 +50,6 @@ 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 )
|
||||||
|
@ -75,10 +58,8 @@ public class ImagedToken extends SimpleToken {
|
||||||
switch( getType() )
|
switch( getType() )
|
||||||
{
|
{
|
||||||
case IToken.tSTRING:
|
case IToken.tSTRING:
|
||||||
case IToken.tCHAR:
|
|
||||||
return s_length + 2;
|
return s_length + 2;
|
||||||
case IToken.tLSTRING:
|
case IToken.tLSTRING:
|
||||||
case IToken.tLCHAR:
|
|
||||||
return s_length + 3;
|
return s_length + 3;
|
||||||
default:
|
default:
|
||||||
return s_length;
|
return s_length;
|
||||||
|
|
Loading…
Add table
Reference in a new issue