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:
parent
130514d961
commit
dfb6a300d1
2 changed files with 23 additions and 19 deletions
|
@ -1660,22 +1660,22 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
// int a[restrict];
|
// int a[restrict];
|
||||||
// char * b[][];
|
// char * b[][];
|
||||||
// const char * const c[][][];
|
// const char * const c[][][];
|
||||||
|
// char* d[const][];
|
||||||
public void testArrayTypes() throws Exception {
|
public void testArrayTypes() throws Exception {
|
||||||
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C);
|
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C);
|
||||||
|
|
||||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
|
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||||
.getDeclarations()[0];
|
|
||||||
IASTName name_a = decl.getDeclarators()[0].getName();
|
IASTName name_a = decl.getDeclarators()[0].getName();
|
||||||
IVariable a = (IVariable) decl.getDeclarators()[0].getName()
|
IVariable a = (IVariable) decl.getDeclarators()[0].getName().resolveBinding();
|
||||||
.resolveBinding();
|
|
||||||
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
||||||
IASTName name_b = decl.getDeclarators()[0].getName();
|
IASTName name_b = decl.getDeclarators()[0].getName();
|
||||||
IVariable b = (IVariable) decl.getDeclarators()[0].getName()
|
IVariable b = (IVariable) decl.getDeclarators()[0].getName().resolveBinding();
|
||||||
.resolveBinding();
|
|
||||||
decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
|
decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
|
||||||
IASTName name_c = decl.getDeclarators()[0].getName();
|
IASTName name_c = decl.getDeclarators()[0].getName();
|
||||||
IVariable c = (IVariable) decl.getDeclarators()[0].getName()
|
IVariable c = (IVariable) decl.getDeclarators()[0].getName().resolveBinding();
|
||||||
.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();
|
IType t_a_1 = a.getType();
|
||||||
assertTrue(t_a_1 instanceof ICArrayType);
|
assertTrue(t_a_1 instanceof ICArrayType);
|
||||||
|
@ -1694,6 +1694,16 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertTrue(t_b_4 instanceof IBasicType);
|
assertTrue(t_b_4 instanceof IBasicType);
|
||||||
assertEquals(((IBasicType) t_b_4).getType(), IBasicType.t_char);
|
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();
|
IType t_c_1 = c.getType();
|
||||||
assertTrue(t_c_1 instanceof IArrayType);
|
assertTrue(t_c_1 instanceof IArrayType);
|
||||||
IType t_c_2 = ((IArrayType) t_c_1).getType();
|
IType t_c_2 = ((IArrayType) t_c_1).getType();
|
||||||
|
|
|
@ -1918,20 +1918,14 @@ public class CVisitor {
|
||||||
*/
|
*/
|
||||||
private static IType setupArrayChain(IASTDeclarator decl, IType lastType) {
|
private static IType setupArrayChain(IASTDeclarator decl, IType lastType) {
|
||||||
if (decl instanceof IASTArrayDeclarator) {
|
if (decl instanceof IASTArrayDeclarator) {
|
||||||
int i=0;
|
|
||||||
IASTArrayModifier[] mods = ((IASTArrayDeclarator)decl).getArrayModifiers();
|
IASTArrayModifier[] mods = ((IASTArrayDeclarator)decl).getArrayModifiers();
|
||||||
|
for (IASTArrayModifier mod : mods) {
|
||||||
CArrayType arrayType = new CArrayType(lastType);
|
CArrayType arrayType = new CArrayType(lastType);
|
||||||
if (mods[i] instanceof ICASTArrayModifier) {
|
if (mod instanceof ICASTArrayModifier) {
|
||||||
arrayType.setModifiedArrayModifier((ICASTArrayModifier)mods[i++]);
|
arrayType.setModifiedArrayModifier((ICASTArrayModifier)mod);
|
||||||
}
|
|
||||||
for (; i < ((IASTArrayDeclarator)decl).getArrayModifiers().length - 1; i++) {
|
|
||||||
arrayType = new CArrayType(arrayType);
|
|
||||||
if (mods[i] instanceof ICASTArrayModifier) {
|
|
||||||
arrayType.setModifiedArrayModifier((ICASTArrayModifier)mods[i]);
|
|
||||||
}
|
}
|
||||||
|
lastType= arrayType;
|
||||||
}
|
}
|
||||||
return arrayType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastType;
|
return lastType;
|
||||||
|
|
Loading…
Add table
Reference in a new issue