mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
[277458] Multi-dimensional ArrayTypes in incorrect order
This commit is contained in:
parent
6fe483b67a
commit
02f5fce4c9
3 changed files with 49 additions and 4 deletions
|
@ -6314,4 +6314,48 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertTrue(t instanceof IEnumeration);
|
||||
}
|
||||
|
||||
|
||||
// /*Check that sizes are stored correctly in chains of IArrayType*/
|
||||
//int a[2][3] = {{1,2,3},{4,5,6}};
|
||||
//int b[3][2] = {{1,2},{3,4},{5,6}};
|
||||
//
|
||||
public void testBug277458() throws Exception {
|
||||
for(ParserLanguage lang : ParserLanguage.values()) {
|
||||
IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), lang);
|
||||
assertTrue(tu.isFrozen());
|
||||
//int a[2][3] = {{1,2,3},{4,5,6}};
|
||||
{
|
||||
IASTDeclaration d = tu.getDeclarations()[0];
|
||||
IBinding b = ((IASTSimpleDeclaration)d).getDeclarators()[0].getName().resolveBinding();
|
||||
IType t = ((IVariable)b).getType();
|
||||
assertTrue(t instanceof IArrayType);
|
||||
IArrayType at1 = (IArrayType)t;
|
||||
IASTExpression size1 = at1.getArraySizeExpression();
|
||||
assertTrue(at1.getType() instanceof IArrayType);
|
||||
IArrayType at2 = (IArrayType) at1.getType();
|
||||
IASTExpression size2 = at2.getArraySizeExpression();
|
||||
assertTrue(size1 instanceof IASTLiteralExpression);
|
||||
assertEquals(((IASTLiteralExpression)size1).getValue()[0], '2');
|
||||
assertTrue(size2 instanceof IASTLiteralExpression);
|
||||
assertEquals(((IASTLiteralExpression)size2).getValue()[0], '3');
|
||||
}
|
||||
//int b[3][2] = {{1,2},{3,4},{5,6}};
|
||||
{
|
||||
IASTDeclaration d = tu.getDeclarations()[1];
|
||||
IBinding b = ((IASTSimpleDeclaration)d).getDeclarators()[0].getName().resolveBinding();
|
||||
IType t = ((IVariable)b).getType();
|
||||
assertTrue(t instanceof IArrayType);
|
||||
IArrayType at1 = (IArrayType)t;
|
||||
IASTExpression size1 = at1.getArraySizeExpression();
|
||||
assertTrue(at1.getType() instanceof IArrayType);
|
||||
IArrayType at2 = (IArrayType) at1.getType();
|
||||
IASTExpression size2 = at2.getArraySizeExpression();
|
||||
assertTrue(size1 instanceof IASTLiteralExpression);
|
||||
assertEquals(((IASTLiteralExpression)size1).getValue()[0], '3');
|
||||
assertTrue(size2 instanceof IASTLiteralExpression);
|
||||
assertEquals(((IASTLiteralExpression)size2).getValue()[0], '2');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1438,10 +1438,10 @@ public class CVisitor extends ASTQueries {
|
|||
private static IType setupArrayChain(IASTDeclarator decl, IType lastType) {
|
||||
if (decl instanceof IASTArrayDeclarator) {
|
||||
IASTArrayModifier[] mods = ((IASTArrayDeclarator)decl).getArrayModifiers();
|
||||
for (IASTArrayModifier mod : mods) {
|
||||
for (int i = mods.length - 1; i >= 0; i--) {
|
||||
CArrayType arrayType = new CArrayType(lastType);
|
||||
if (mod instanceof ICASTArrayModifier) {
|
||||
arrayType.setModifier((ICASTArrayModifier)mod);
|
||||
if (mods[i] instanceof ICASTArrayModifier) {
|
||||
arrayType.setModifier((ICASTArrayModifier)mods[i]);
|
||||
}
|
||||
lastType= arrayType;
|
||||
}
|
||||
|
|
|
@ -1606,7 +1606,8 @@ public class CPPVisitor extends ASTQueries {
|
|||
|
||||
private static IType getArrayTypes(IType type, IASTArrayDeclarator declarator) {
|
||||
IASTArrayModifier[] mods = declarator.getArrayModifiers();
|
||||
for (IASTArrayModifier mod : mods) {
|
||||
for (int i = mods.length -1; i >= 0; i--) {
|
||||
IASTArrayModifier mod = mods[i];
|
||||
type = new CPPArrayType(type, mod.getConstantExpression());
|
||||
}
|
||||
return type;
|
||||
|
|
Loading…
Add table
Reference in a new issue