mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 02:05:39 +02:00
Correct type-strings for function and array types, bug 277320.
This commit is contained in:
parent
6bc28a4959
commit
fc4e49794c
4 changed files with 82 additions and 45 deletions
|
@ -797,7 +797,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
assertNull(newExpr.getNewPlacement());
|
assertNull(newExpr.getNewPlacement());
|
||||||
assertNull(newExpr.getNewInitializer());
|
assertNull(newExpr.getNewInitializer());
|
||||||
IASTTypeId typeid= newExpr.getTypeId();
|
IASTTypeId typeid= newExpr.getTypeId();
|
||||||
isTypeEqual(CPPVisitor.createType(typeid), "int () * []");
|
isTypeEqual(CPPVisitor.createType(typeid), "int (* [])()");
|
||||||
}
|
}
|
||||||
|
|
||||||
// typedef int T;
|
// typedef int T;
|
||||||
|
@ -1858,7 +1858,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
|
|
||||||
BindingAssertionHelper ba= new BindingAssertionHelper(code, true);
|
BindingAssertionHelper ba= new BindingAssertionHelper(code, true);
|
||||||
IFunction f= ba.assertNonProblem("f", 1, IFunction.class);
|
IFunction f= ba.assertNonProblem("f", 1, IFunction.class);
|
||||||
isTypeEqual(f.getType(), "void (int (C) *)");
|
isTypeEqual(f.getType(), "void (int (*)(C))");
|
||||||
}
|
}
|
||||||
|
|
||||||
// class C { };
|
// class C { };
|
||||||
|
@ -1869,7 +1869,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||||
parse(code, ParserLanguage.CPP, true, 0);
|
parse(code, ParserLanguage.CPP, true, 0);
|
||||||
BindingAssertionHelper ba= new BindingAssertionHelper(code, true);
|
BindingAssertionHelper ba= new BindingAssertionHelper(code, true);
|
||||||
IFunction f= ba.assertNonProblem("h", 1, IFunction.class);
|
IFunction f= ba.assertNonProblem("h", 1, IFunction.class);
|
||||||
isTypeEqual(f.getType(), "void (int * (C *) *)");
|
isTypeEqual(f.getType(), "void (int * (*)(C *))");
|
||||||
}
|
}
|
||||||
|
|
||||||
// namespace A {
|
// namespace A {
|
||||||
|
|
|
@ -1089,7 +1089,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
IFunction g = (IFunction) collector.getName(8).resolveBinding();
|
IFunction g = (IFunction) collector.getName(8).resolveBinding();
|
||||||
isTypeEqual(g.getType(), "void (char *)");
|
isTypeEqual(g.getType(), "void (char *)");
|
||||||
IFunction h = (IFunction) collector.getName(12).resolveBinding();
|
IFunction h = (IFunction) collector.getName(12).resolveBinding();
|
||||||
isTypeEqual(h.getType(), "void (int () *)");
|
isTypeEqual(h.getType(), "void (int (*)())");
|
||||||
|
|
||||||
assertInstances(collector, f, 3);
|
assertInstances(collector, f, 3);
|
||||||
assertInstances(collector, g, 2);
|
assertInstances(collector, g, 2);
|
||||||
|
@ -5746,10 +5746,10 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
checkNewExpression(fdef, 10, IASTIdExpression.class, "int", IASTExpressionList.class);
|
checkNewExpression(fdef, 10, IASTIdExpression.class, "int", IASTExpressionList.class);
|
||||||
checkNewExpression(fdef, 11, IASTIdExpression.class, "int", IASTIdExpression.class);
|
checkNewExpression(fdef, 11, IASTIdExpression.class, "int", IASTIdExpression.class);
|
||||||
|
|
||||||
checkNewExpression(fdef, 12, null, "int [] []", null);
|
checkNewExpression(fdef, 12, null, "int [][]", null);
|
||||||
checkNewExpression(fdef, 13, IASTIdExpression.class, "int [] []", null);
|
checkNewExpression(fdef, 13, IASTIdExpression.class, "int [][]", null);
|
||||||
checkNewExpression(fdef, 14, null, "int [] []", null);
|
checkNewExpression(fdef, 14, null, "int [][]", null);
|
||||||
checkNewExpression(fdef, 15, IASTIdExpression.class, "int [] []", null);
|
checkNewExpression(fdef, 15, IASTIdExpression.class, "int [][]", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkNewExpression(IASTFunctionDefinition fdef, int i_expr, Class<?> placement, String type, Class<?> init) {
|
private void checkNewExpression(IASTFunctionDefinition fdef, int i_expr, Class<?> placement, String type, Class<?> init) {
|
||||||
|
|
|
@ -4008,7 +4008,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
// for plain C this is actually not a problem, the second J has to be interpreted as a (useless)
|
// for plain C this is actually not a problem, the second J has to be interpreted as a (useless)
|
||||||
// parameter name.
|
// parameter name.
|
||||||
assertInstance(typedef, ITypedef.class);
|
assertInstance(typedef, ITypedef.class);
|
||||||
isTypeEqual(((ITypedef) typedef).getType(), "int (int) *");
|
isTypeEqual(((ITypedef) typedef).getType(), "int (*)(int)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5123,19 +5123,19 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
BindingAssertionHelper ba= new BindingAssertionHelper(comment, isCpp);
|
BindingAssertionHelper ba= new BindingAssertionHelper(comment, isCpp);
|
||||||
|
|
||||||
IFunction f= ba.assertNonProblem("f1", 2, IFunction.class);
|
IFunction f= ba.assertNonProblem("f1", 2, IFunction.class);
|
||||||
isTypeEqual(f.getType(), "int (int (int) *)");
|
isTypeEqual(f.getType(), "int (int (*)(int))");
|
||||||
|
|
||||||
f= ba.assertNonProblem("f2", 2, IFunction.class);
|
f= ba.assertNonProblem("f2", 2, IFunction.class);
|
||||||
isTypeEqual(f.getType(), "int (int (int) *)");
|
isTypeEqual(f.getType(), "int (int (*)(int))");
|
||||||
|
|
||||||
f= ba.assertNonProblem("f3", 2, IFunction.class);
|
f= ba.assertNonProblem("f3", 2, IFunction.class);
|
||||||
isTypeEqual(f.getType(), "int (int (int) *)");
|
isTypeEqual(f.getType(), "int (int (*)(int))");
|
||||||
|
|
||||||
f= ba.assertNonProblem("f4", 2, IFunction.class);
|
f= ba.assertNonProblem("f4", 2, IFunction.class);
|
||||||
isTypeEqual(f.getType(), "int (int)");
|
isTypeEqual(f.getType(), "int (int)");
|
||||||
|
|
||||||
f= ba.assertNonProblem("f5", 2, IFunction.class);
|
f= ba.assertNonProblem("f5", 2, IFunction.class);
|
||||||
isTypeEqual(f.getType(), "int (int * (int *) *)");
|
isTypeEqual(f.getType(), "int (int * (*)(int *))");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5145,7 +5145,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
||||||
|
|
||||||
IFunction f= ba.assertNonProblem("f1", 2, IFunction.class);
|
IFunction f= ba.assertNonProblem("f1", 2, IFunction.class);
|
||||||
isTypeEqual(f.getType(), "void (int (C) *)");
|
isTypeEqual(f.getType(), "void (int (*)(C))");
|
||||||
}
|
}
|
||||||
|
|
||||||
// int (*f1(int par))[5] {};
|
// int (*f1(int par))[5] {};
|
||||||
|
@ -5157,10 +5157,10 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), isCpp);
|
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), isCpp);
|
||||||
|
|
||||||
IFunction f= ba.assertNonProblem("f1", 2, IFunction.class);
|
IFunction f= ba.assertNonProblem("f1", 2, IFunction.class);
|
||||||
isTypeEqual(f.getType(), "int [] * (int)");
|
isTypeEqual(f.getType(), "int (* (int))[]");
|
||||||
|
|
||||||
f= ba.assertNonProblem("f1 ", 2, IFunction.class);
|
f= ba.assertNonProblem("f1 ", 2, IFunction.class);
|
||||||
isTypeEqual(f.getType(), "int [] * (int)");
|
isTypeEqual(f.getType(), "int (* (int))[]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,10 @@ package org.eclipse.cdt.core.dom.ast;
|
||||||
|
|
||||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF;
|
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.BitSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
|
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
|
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
|
||||||
|
@ -379,23 +382,13 @@ public class ASTTypeUtil {
|
||||||
result.append(SPACE);
|
result.append(SPACE);
|
||||||
result.append(getNameForAnonymous((IEnumeration) type));
|
result.append(getNameForAnonymous((IEnumeration) type));
|
||||||
} else if (type instanceof IFunctionType) {
|
} else if (type instanceof IFunctionType) {
|
||||||
try {
|
String temp = getParameterTypeString((IFunctionType) type);
|
||||||
String temp = getType(((IFunctionType) type).getReturnType(), normalize);
|
if (temp != null && !temp.equals(EMPTY_STRING)) {
|
||||||
if (temp != null && !temp.equals(EMPTY_STRING)) {
|
result.append(temp); needSpace = false;
|
||||||
result.append(temp); needSpace = true;
|
}
|
||||||
}
|
if (type instanceof ICPPFunctionType) {
|
||||||
if (needSpace) {
|
ICPPFunctionType ft= (ICPPFunctionType) type;
|
||||||
result.append(SPACE); needSpace = false;
|
needSpace= appendCVQ(result, needSpace, ft.isConst(), ft.isVolatile());
|
||||||
}
|
|
||||||
temp = getParameterTypeString((IFunctionType) type);
|
|
||||||
if (temp != null && !temp.equals(EMPTY_STRING)) {
|
|
||||||
result.append(temp); needSpace = false;
|
|
||||||
}
|
|
||||||
if (type instanceof ICPPFunctionType) {
|
|
||||||
ICPPFunctionType ft= (ICPPFunctionType) type;
|
|
||||||
needSpace= appendCVQ(result, needSpace, ft.isConst(), ft.isVolatile());
|
|
||||||
}
|
|
||||||
} catch (DOMException e) {
|
|
||||||
}
|
}
|
||||||
} else if (type instanceof IPointerType) {
|
} else if (type instanceof IPointerType) {
|
||||||
if (type instanceof ICPPPointerToMemberType) {
|
if (type instanceof ICPPPointerToMemberType) {
|
||||||
|
@ -515,26 +508,70 @@ public class ASTTypeUtil {
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
type= null;
|
type= null;
|
||||||
}
|
}
|
||||||
|
} else if (type instanceof IFunctionType) {
|
||||||
|
try {
|
||||||
|
type= ((IFunctionType) type).getReturnType();
|
||||||
|
} catch (DOMException e) {
|
||||||
|
type= null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
type= null;
|
type= null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pop all of the types off of the stack, and build the string representation while doing so
|
// pop all of the types off of the stack, and build the string representation while doing so
|
||||||
|
List<IType> postfix= null;
|
||||||
|
BitSet parenthesis= null;
|
||||||
|
boolean needParenthesis= false;
|
||||||
for (int j = types.length - 1; j >= 0; j--) {
|
for (int j = types.length - 1; j >= 0; j--) {
|
||||||
if (types[j] != null && result.length() > 0)
|
IType tj = types[j];
|
||||||
result.append(SPACE); // only add a space if this is not the first type being added
|
if (tj != null) {
|
||||||
|
if (j > 0 && types[j - 1] instanceof IQualifierType) {
|
||||||
|
if (result.length() > 0)
|
||||||
|
result.append(SPACE); // only add a space if this is not the first type being added
|
||||||
|
result.append(getTypeString(types[j - 1], normalize));
|
||||||
|
result.append(SPACE);
|
||||||
|
result.append(getTypeString(tj, normalize));
|
||||||
|
--j;
|
||||||
|
} else {
|
||||||
|
// handle post-fix
|
||||||
|
if (tj instanceof IFunctionType || tj instanceof IArrayType) {
|
||||||
|
if (j == 0) {
|
||||||
|
if (result.length() > 0)
|
||||||
|
result.append(SPACE); // only add a space if this is not the first type being added
|
||||||
|
result.append(getTypeString(tj, normalize));
|
||||||
|
} else {
|
||||||
|
if (postfix == null) {
|
||||||
|
postfix= new ArrayList<IType>();
|
||||||
|
}
|
||||||
|
postfix.add(tj);
|
||||||
|
needParenthesis= true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (result.length() > 0)
|
||||||
|
result.append(SPACE); // only add a space if this is not the first type being added
|
||||||
|
if (needParenthesis && postfix != null) {
|
||||||
|
result.append('(');
|
||||||
|
if (parenthesis == null) {
|
||||||
|
parenthesis= new BitSet();
|
||||||
|
}
|
||||||
|
parenthesis.set(postfix.size()-1);
|
||||||
|
}
|
||||||
|
result.append(getTypeString(tj, normalize));
|
||||||
|
needParenthesis= false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (types[j] != null) {
|
if (postfix != null) {
|
||||||
if (j > 0 && types[j - 1] instanceof IQualifierType) {
|
for (int j = postfix.size() - 1; j >= 0; j--) {
|
||||||
result.append(getTypeString(types[j - 1], normalize));
|
if (parenthesis != null && parenthesis.get(j)) {
|
||||||
result.append(SPACE);
|
result.append(')');
|
||||||
result.append(getTypeString(types[j], normalize));
|
}
|
||||||
--j;
|
IType tj = postfix.get(j);
|
||||||
} else {
|
result.append(getTypeString(tj, normalize));
|
||||||
result.append(getTypeString(types[j], normalize));
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
|
|
Loading…
Add table
Reference in a new issue