1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 14:15:23 +02:00

Fixes return types of built-in functions, bug 234309.

This commit is contained in:
Markus Schorn 2008-05-28 07:45:14 +00:00
parent f87ab3b2cb
commit 508d3c6c86
8 changed files with 41 additions and 49 deletions

View file

@ -4755,4 +4755,14 @@ public class AST2Tests extends AST2BaseTest {
assertSame(t, ct);
}
}
// void checkLong(long);
// void test() {
// checkLong(__builtin_expect(1, 1));
// }
public void testReturnTypeOfBuiltin_Bug234309() throws Exception {
String code= getAboveComment();
parseAndCheckBindings(code, ParserLanguage.C, true);
parseAndCheckBindings(code, ParserLanguage.CPP, true);
}
}

View file

@ -31,7 +31,9 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
@ -123,15 +125,19 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
if (!ia.hasUserDeclaredCopyAssignmentOperator()) {
//copy assignment operator: A& operator = (const A &)
IType refType = new CPPReferenceType(clsType);
ICPPMethod m = new CPPImplicitMethod(this, OverloadableOperator.ASSIGN.toCharArray(), refType, ps);
IPointerType thisType= new CPPPointerType(clsType);
IFunctionType ft= CPPVisitor.createImplicitFunctionType(refType, ps, thisType);
ICPPMethod m = new CPPImplicitMethod(this, OverloadableOperator.ASSIGN.toCharArray(), ft, ps);
implicits[i++] = m;
addBinding(m);
}
if (!ia.hasUserDeclaredDestructor()) {
//destructor: ~A()
IPointerType thisType= new CPPPointerType(clsType);
IFunctionType ft= CPPVisitor.createImplicitFunctionType(new CPPBasicType(IBasicType.t_unspecified, 0), voidPs, thisType);
char[] dtorName = CharArrayUtils.concat("~".toCharArray(), className); //$NON-NLS-1$
ICPPMethod m = new CPPImplicitMethod(this, dtorName, new CPPBasicType(IBasicType.t_unspecified, 0), voidPs);
ICPPMethod m = new CPPImplicitMethod(this, dtorName, ft, voidPs);
implicits[i++] = m;
addBinding(m);
}

View file

@ -94,7 +94,7 @@ public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunc
IFunctionType ft = ((ICPPFunction)getTemplateDefinition()).getType();
IType returnType = ft.getReturnType();
returnType = CPPTemplates.instantiateType( returnType, getArgumentMap(), null);
functionType = CPPVisitor.createImplicitFunctionType( returnType, getParameters() );
functionType = CPPVisitor.createImplicitFunctionType( returnType, getParameters(), null);
}
return functionType;

View file

@ -1,23 +1,23 @@
/*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
/*
* Created on Jan 19, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* @author aniefer
@ -29,10 +29,15 @@ public class CPPImplicitConstructor extends CPPImplicitMethod implements ICPPCon
* @param params
*/
public CPPImplicitConstructor( ICPPClassScope scope, char [] name, IParameter[] params ) {
super( scope, name, new CPPBasicType( IBasicType.t_unspecified, 0 ), params );
super( scope, name, createFunctionType(scope, params), params );
}
/* (non-Javadoc)
private static IFunctionType createFunctionType(ICPPClassScope scope, IParameter[] params) {
IType returnType= new CPPBasicType(IBasicType.t_unspecified, 0);
return CPPVisitor.createImplicitFunctionType(returnType, params, null);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor#isExplicit()
*/
public boolean isExplicit() {

View file

@ -17,9 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* The CPPImplicitFunction is used to represent implicit functions that exist on the translation
@ -33,16 +31,15 @@ public class CPPImplicitFunction extends CPPFunction {
private IParameter[] parms=null;
private IScope scope=null;
private IType returnType=null;
private IFunctionType functionType=null;
private boolean takesVarArgs=false;
private char[] name=null;
public CPPImplicitFunction(char[] name, IScope scope, IType type, IParameter[] parms, boolean takesVarArgs) {
public CPPImplicitFunction(char[] name, IScope scope, IFunctionType type, IParameter[] parms, boolean takesVarArgs) {
super( null );
this.name=name;
this.scope=scope;
this.returnType=type;
this.functionType= type;
this.parms=parms;
this.takesVarArgs=takesVarArgs;
}
@ -54,28 +51,9 @@ public class CPPImplicitFunction extends CPPFunction {
@Override
public IFunctionType getType() {
if( functionType == null ){
ICPPASTFunctionDeclarator primary = getPrimaryDeclaration();
if( primary != null ){
functionType = super.getType();
} else {
functionType = CPPVisitor.createImplicitFunctionType( returnType, parms );
}
}
return functionType;
return functionType;
}
private ICPPASTFunctionDeclarator getPrimaryDeclaration() {
if (definition != null)
return definition;
else if (declarations != null && declarations.length > 0)
return declarations[0];
return null;
}
@Override
public String getName() {
return String.valueOf( name );

View file

@ -9,10 +9,6 @@
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
/*
* Created on Jan 19, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
@ -42,8 +38,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
*/
public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod {
public CPPImplicitMethod( ICPPClassScope scope, char[] name, IType returnType, IParameter[] params ) {
super( name, scope, returnType, params, false );
public CPPImplicitMethod( ICPPClassScope scope, char[] name, IFunctionType type, IParameter[] params ) {
super( name, scope, type, params, false );
}
public int getVisibility() throws DOMException {

View file

@ -1629,7 +1629,7 @@ public class CPPTemplates {
@Override
public IFunctionType getType() {
if (type == null) {
type = CPPVisitor.createImplicitFunctionType(new CPPBasicType(IBasicType.t_void, 0), functionParameters);
type = CPPVisitor.createImplicitFunctionType(new CPPBasicType(IBasicType.t_void, 0), functionParameters, null);
}
return type;
}

View file

@ -1488,12 +1488,9 @@ public class CPPVisitor {
/**
* Generate a function type for an implicit function.
* NOTE: This does not currectly handle parameters with typedef types.
* @param returnType
* @param parameters
* NOTE: This does not correctly handle parameters with typedef types.
*/
public static IFunctionType createImplicitFunctionType(IType returnType, IParameter[] parameters) {
public static IFunctionType createImplicitFunctionType(IType returnType, IParameter[] parameters, IPointerType thisType) {
IType[] pTypes = new IType[parameters.length];
IType pt = null;
@ -1518,7 +1515,7 @@ public class CPPVisitor {
pTypes[i] = pt;
}
return new CPPFunctionType(returnType, pTypes);
return new CPPFunctionType(returnType, pTypes, thisType);
}
private static IType createType(IType returnType, ICPPASTFunctionDeclarator fnDtor) {