1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Type computation for modified array types, bug 257334.

This commit is contained in:
Markus Schorn 2008-12-03 09:50:36 +00:00
parent 130514d961
commit dfb6a300d1
2 changed files with 23 additions and 19 deletions

View file

@ -1660,22 +1660,22 @@ public class AST2Tests extends AST2BaseTest {
// int a[restrict];
// char * b[][];
// const char * const c[][][];
// char* d[const][];
public void testArrayTypes() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C);
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
.getDeclarations()[0];
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTName name_a = decl.getDeclarators()[0].getName();
IVariable a = (IVariable) decl.getDeclarators()[0].getName()
.resolveBinding();
IVariable a = (IVariable) decl.getDeclarators()[0].getName().resolveBinding();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
IASTName name_b = decl.getDeclarators()[0].getName();
IVariable b = (IVariable) decl.getDeclarators()[0].getName()
.resolveBinding();
IVariable b = (IVariable) decl.getDeclarators()[0].getName().resolveBinding();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
IASTName name_c = decl.getDeclarators()[0].getName();
IVariable c = (IVariable) decl.getDeclarators()[0].getName()
.resolveBinding();
IVariable c = (IVariable) decl.getDeclarators()[0].getName().resolveBinding();
decl = (IASTSimpleDeclaration) tu.getDeclarations()[3];
IASTName name_d = decl.getDeclarators()[0].getName();
IVariable d = (IVariable) decl.getDeclarators()[0].getName().resolveBinding();
IType t_a_1 = a.getType();
assertTrue(t_a_1 instanceof ICArrayType);
@ -1694,6 +1694,16 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(t_b_4 instanceof IBasicType);
assertEquals(((IBasicType) t_b_4).getType(), IBasicType.t_char);
t_b_1 = d.getType();
assertTrue(t_b_1 instanceof IArrayType);
t_b_2 = ((IArrayType) t_b_1).getType();
assertTrue(t_b_2 instanceof IArrayType);
t_b_3 = ((IArrayType) t_b_2).getType();
assertTrue(t_b_3 instanceof IPointerType);
t_b_4 = ((IPointerType) t_b_3).getType();
assertTrue(t_b_4 instanceof IBasicType);
assertEquals(((IBasicType) t_b_4).getType(), IBasicType.t_char);
IType t_c_1 = c.getType();
assertTrue(t_c_1 instanceof IArrayType);
IType t_c_2 = ((IArrayType) t_c_1).getType();

View file

@ -1918,20 +1918,14 @@ public class CVisitor {
*/
private static IType setupArrayChain(IASTDeclarator decl, IType lastType) {
if (decl instanceof IASTArrayDeclarator) {
int i=0;
IASTArrayModifier[] mods = ((IASTArrayDeclarator)decl).getArrayModifiers();
CArrayType arrayType = new CArrayType(lastType);
if (mods[i] instanceof ICASTArrayModifier) {
arrayType.setModifiedArrayModifier((ICASTArrayModifier)mods[i++]);
}
for (; i < ((IASTArrayDeclarator)decl).getArrayModifiers().length - 1; i++) {
arrayType = new CArrayType(arrayType);
if (mods[i] instanceof ICASTArrayModifier) {
arrayType.setModifiedArrayModifier((ICASTArrayModifier)mods[i]);
for (IASTArrayModifier mod : mods) {
CArrayType arrayType = new CArrayType(lastType);
if (mod instanceof ICASTArrayModifier) {
arrayType.setModifiedArrayModifier((ICASTArrayModifier)mod);
}
lastType= arrayType;
}
return arrayType;
}
return lastType;