mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixed Bug 80978 - [Parser2] C Parser doesnt handle variable length arrays
This commit is contained in:
parent
3d65d89fd7
commit
2c4cc97119
4 changed files with 37 additions and 4 deletions
|
@ -1415,14 +1415,24 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
{
|
{
|
||||||
StringBuffer buffer =new StringBuffer( "const int x = 10;\n"); //$NON-NLS-1$
|
StringBuffer buffer =new StringBuffer( "const int x = 10;\n"); //$NON-NLS-1$
|
||||||
buffer.append( "int y [ const static x ];"); //$NON-NLS-1$
|
buffer.append( "int y [ const static x ];"); //$NON-NLS-1$
|
||||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
|
ICASTArrayModifier mod = (ICASTArrayModifier) ((IASTArrayDeclarator)((IASTSimpleDeclaration) parse( buffer.toString(), ParserLanguage.C ).getDeclarations()[1]).getDeclarators()[0]).getArrayModifiers()[0];
|
||||||
IASTDeclaration [] declarations = tu.getDeclarations();
|
|
||||||
IASTSimpleDeclaration y = (IASTSimpleDeclaration) declarations[1];
|
|
||||||
ICASTArrayModifier mod = (ICASTArrayModifier) ((IASTArrayDeclarator)y.getDeclarators()[0]).getArrayModifiers()[0];
|
|
||||||
assertTrue( mod.isConst() );
|
assertTrue( mod.isConst() );
|
||||||
assertTrue( mod.isStatic() );
|
assertTrue( mod.isStatic() );
|
||||||
assertFalse( mod.isRestrict() );
|
assertFalse( mod.isRestrict() );
|
||||||
assertFalse( mod.isVolatile() );
|
assertFalse( mod.isVolatile() );
|
||||||
|
assertFalse( mod.isVariableSized() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBug80978() throws Exception
|
||||||
|
{
|
||||||
|
StringBuffer buffer =new StringBuffer(); //$NON-NLS-1$
|
||||||
|
buffer.append( "int y ( int [ const *] );"); //$NON-NLS-1$
|
||||||
|
ICASTArrayModifier mod = (ICASTArrayModifier)((IASTArrayDeclarator)((IASTFunctionDeclarator) ((IASTSimpleDeclaration) parse( buffer.toString(), ParserLanguage.C ).getDeclarations()[0]).getDeclarators()[0]).getParameters()[0].getDeclarator() ).getArrayModifiers()[0];
|
||||||
|
assertTrue( mod.isConst() );
|
||||||
|
assertTrue( mod.isVariableSized() );
|
||||||
|
assertFalse( mod.isStatic() );
|
||||||
|
assertFalse( mod.isRestrict() );
|
||||||
|
assertFalse( mod.isVolatile() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,4 +25,6 @@ public interface ICASTArrayModifier extends IASTArrayModifier {
|
||||||
public void setVolatile( boolean value );
|
public void setVolatile( boolean value );
|
||||||
public void setRestrict( boolean value );
|
public void setRestrict( boolean value );
|
||||||
public void setStatic( boolean value );
|
public void setStatic( boolean value );
|
||||||
|
public boolean isVariableSized();
|
||||||
|
public void setVariableSized( boolean value );
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class CASTModifiedArrayModifier extends CASTArrayModifier implements
|
||||||
private boolean isRestrict;
|
private boolean isRestrict;
|
||||||
private boolean isStatic;
|
private boolean isStatic;
|
||||||
private boolean isConst;
|
private boolean isConst;
|
||||||
|
private boolean varSized;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#isConst()
|
* @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#isConst()
|
||||||
|
@ -78,4 +79,18 @@ public class CASTModifiedArrayModifier extends CASTArrayModifier implements
|
||||||
this.isStatic = value;
|
this.isStatic = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#isVariableSized()
|
||||||
|
*/
|
||||||
|
public boolean isVariableSized() {
|
||||||
|
return varSized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#setVariableSized(boolean)
|
||||||
|
*/
|
||||||
|
public void setVariableSized(boolean value) {
|
||||||
|
varSized = value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1780,6 +1780,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
boolean isConst = false;
|
boolean isConst = false;
|
||||||
boolean isRestrict = false;
|
boolean isRestrict = false;
|
||||||
boolean isVolatile = false;
|
boolean isVolatile = false;
|
||||||
|
boolean isVarSized = false;
|
||||||
|
|
||||||
outerLoop: do {
|
outerLoop: do {
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
|
@ -1799,6 +1800,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
isRestrict = true;
|
isRestrict = true;
|
||||||
consume();
|
consume();
|
||||||
break;
|
break;
|
||||||
|
case IToken.tSTAR:
|
||||||
|
isVarSized = true;
|
||||||
|
consume();
|
||||||
|
//deliberate fall through
|
||||||
default:
|
default:
|
||||||
break outerLoop;
|
break outerLoop;
|
||||||
}
|
}
|
||||||
|
@ -1824,6 +1829,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
temp.setConst( isConst );
|
temp.setConst( isConst );
|
||||||
temp.setVolatile( isVolatile );
|
temp.setVolatile( isVolatile );
|
||||||
temp.setRestrict(isRestrict);
|
temp.setRestrict(isRestrict);
|
||||||
|
temp.setVariableSized(isVarSized );
|
||||||
arrayMod = temp;
|
arrayMod = temp;
|
||||||
}
|
}
|
||||||
((ASTNode)arrayMod).setOffset( startOffset );
|
((ASTNode)arrayMod).setOffset( startOffset );
|
||||||
|
|
Loading…
Add table
Reference in a new issue