mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 23:35:48 +02:00
Adjusting c-parameter type for typedefs, bug 284248.
This commit is contained in:
parent
760abf7ac7
commit
448fec099f
2 changed files with 37 additions and 12 deletions
|
@ -6392,4 +6392,19 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// /* Check that a parameter declared as a typedef'd array
|
||||||
|
// * is treated as a pointer
|
||||||
|
// */
|
||||||
|
//typedef int my_buf[16];
|
||||||
|
//void goo(my_buf in);
|
||||||
|
//
|
||||||
|
public void testBug284248() throws Exception {
|
||||||
|
for(ParserLanguage lang : ParserLanguage.values()) {
|
||||||
|
IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), lang);
|
||||||
|
assertTrue(tu.isFrozen());
|
||||||
|
IASTName n = ((IASTSimpleDeclaration)tu.getDeclarations()[1]).getDeclarators()[0].getName();
|
||||||
|
assertTrue(((IFunction)n.resolveBinding()).getType().getParameterTypes()[0] instanceof IPointerType);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
|
@ -1273,22 +1274,31 @@ public class CVisitor extends ASTQueries {
|
||||||
|
|
||||||
|
|
||||||
if (isParameter) {
|
if (isParameter) {
|
||||||
|
IType paramType = type;
|
||||||
|
// Remove typedefs ready for subsequent processing.
|
||||||
|
while (paramType instanceof ITypedef) {
|
||||||
|
paramType = ((ITypedef)paramType).getType();
|
||||||
|
}
|
||||||
|
|
||||||
//C99: 6.7.5.3-7 a declaration of a parameter as "array of type" shall be adjusted to "qualified pointer to type", where the
|
//C99: 6.7.5.3-7 a declaration of a parameter as "array of type" shall be adjusted to "qualified pointer to type", where the
|
||||||
//type qualifiers (if any) are those specified within the[and] of the array type derivation
|
//type qualifiers (if any) are those specified within the[and] of the array type derivation
|
||||||
if (type instanceof ICArrayType) {
|
if (paramType instanceof IArrayType) { // the index does not yet return ICArrayTypes
|
||||||
ICArrayType at = (ICArrayType) type;
|
IArrayType at = (IArrayType) paramType;
|
||||||
try {
|
int q= 0;
|
||||||
int q= 0;
|
if (at instanceof ICArrayType) {
|
||||||
if (at.isConst()) q |= CPointerType.IS_CONST;
|
ICArrayType cat= (ICArrayType) at;
|
||||||
if (at.isVolatile()) q |= CPointerType.IS_VOLATILE;
|
try {
|
||||||
if (at.isRestrict()) q |= CPointerType.IS_RESTRICT;
|
if (cat.isConst()) q |= CPointerType.IS_CONST;
|
||||||
type = new CPointerType(at.getType(), q);
|
if (cat.isVolatile()) q |= CPointerType.IS_VOLATILE;
|
||||||
} catch (DOMException e) {
|
if (cat.isRestrict()) q |= CPointerType.IS_RESTRICT;
|
||||||
// stick to the array
|
} catch (DOMException e) {
|
||||||
|
// ignore the qualifiers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (type instanceof IFunctionType) {
|
type = new CPointerType(at.getType(), q);
|
||||||
|
} else if (paramType instanceof IFunctionType) {
|
||||||
//-8 A declaration of a parameter as "function returning type" shall be adjusted to "pointer to function returning type"
|
//-8 A declaration of a parameter as "function returning type" shall be adjusted to "pointer to function returning type"
|
||||||
type = new CPointerType(type, 0);
|
type = new CPointerType(paramType, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue