mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
Fixes return types of built-in functions, bug 234309.
This commit is contained in:
parent
f87ab3b2cb
commit
508d3c6c86
8 changed files with 41 additions and 49 deletions
|
@ -4755,4 +4755,14 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertSame(t, ct);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.IASTTypeId;
|
||||||
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.IFunctionType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
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.IProblemBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
|
@ -123,15 +125,19 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
||||||
if (!ia.hasUserDeclaredCopyAssignmentOperator()) {
|
if (!ia.hasUserDeclaredCopyAssignmentOperator()) {
|
||||||
//copy assignment operator: A& operator = (const A &)
|
//copy assignment operator: A& operator = (const A &)
|
||||||
IType refType = new CPPReferenceType(clsType);
|
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;
|
implicits[i++] = m;
|
||||||
addBinding(m);
|
addBinding(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ia.hasUserDeclaredDestructor()) {
|
if (!ia.hasUserDeclaredDestructor()) {
|
||||||
//destructor: ~A()
|
//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$
|
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;
|
implicits[i++] = m;
|
||||||
addBinding(m);
|
addBinding(m);
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunc
|
||||||
IFunctionType ft = ((ICPPFunction)getTemplateDefinition()).getType();
|
IFunctionType ft = ((ICPPFunction)getTemplateDefinition()).getType();
|
||||||
IType returnType = ft.getReturnType();
|
IType returnType = ft.getReturnType();
|
||||||
returnType = CPPTemplates.instantiateType( returnType, getArgumentMap(), null);
|
returnType = CPPTemplates.instantiateType( returnType, getArgumentMap(), null);
|
||||||
functionType = CPPVisitor.createImplicitFunctionType( returnType, getParameters() );
|
functionType = CPPVisitor.createImplicitFunctionType( returnType, getParameters(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return functionType;
|
return functionType;
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* 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;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
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.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.ICPPClassScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -29,10 +29,15 @@ public class CPPImplicitConstructor extends CPPImplicitMethod implements ICPPCon
|
||||||
* @param params
|
* @param params
|
||||||
*/
|
*/
|
||||||
public CPPImplicitConstructor( ICPPClassScope scope, char [] name, IParameter[] 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()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor#isExplicit()
|
||||||
*/
|
*/
|
||||||
public boolean isExplicit() {
|
public boolean isExplicit() {
|
||||||
|
|
|
@ -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.IFunctionType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
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.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
|
* 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 IParameter[] parms=null;
|
||||||
private IScope scope=null;
|
private IScope scope=null;
|
||||||
private IType returnType=null;
|
|
||||||
private IFunctionType functionType=null;
|
private IFunctionType functionType=null;
|
||||||
private boolean takesVarArgs=false;
|
private boolean takesVarArgs=false;
|
||||||
private char[] name=null;
|
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 );
|
super( null );
|
||||||
this.name=name;
|
this.name=name;
|
||||||
this.scope=scope;
|
this.scope=scope;
|
||||||
this.returnType=type;
|
this.functionType= type;
|
||||||
this.parms=parms;
|
this.parms=parms;
|
||||||
this.takesVarArgs=takesVarArgs;
|
this.takesVarArgs=takesVarArgs;
|
||||||
}
|
}
|
||||||
|
@ -54,28 +51,9 @@ public class CPPImplicitFunction extends CPPFunction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IFunctionType getType() {
|
public IFunctionType getType() {
|
||||||
if( functionType == null ){
|
return functionType;
|
||||||
ICPPASTFunctionDeclarator primary = getPrimaryDeclaration();
|
|
||||||
|
|
||||||
if( primary != null ){
|
|
||||||
functionType = super.getType();
|
|
||||||
} else {
|
|
||||||
functionType = CPPVisitor.createImplicitFunctionType( returnType, parms );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return functionType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICPPASTFunctionDeclarator getPrimaryDeclaration() {
|
|
||||||
if (definition != null)
|
|
||||||
return definition;
|
|
||||||
else if (declarations != null && declarations.length > 0)
|
|
||||||
return declarations[0];
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return String.valueOf( name );
|
return String.valueOf( name );
|
||||||
|
|
|
@ -9,10 +9,6 @@
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
/*
|
|
||||||
* Created on Jan 19, 2005
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
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 class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod {
|
||||||
|
|
||||||
public CPPImplicitMethod( ICPPClassScope scope, char[] name, IType returnType, IParameter[] params ) {
|
public CPPImplicitMethod( ICPPClassScope scope, char[] name, IFunctionType type, IParameter[] params ) {
|
||||||
super( name, scope, returnType, params, false );
|
super( name, scope, type, params, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getVisibility() throws DOMException {
|
public int getVisibility() throws DOMException {
|
||||||
|
|
|
@ -1629,7 +1629,7 @@ public class CPPTemplates {
|
||||||
@Override
|
@Override
|
||||||
public IFunctionType getType() {
|
public IFunctionType getType() {
|
||||||
if (type == null) {
|
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;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1488,12 +1488,9 @@ public class CPPVisitor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a function type for an implicit function.
|
* Generate a function type for an implicit function.
|
||||||
* NOTE: This does not currectly handle parameters with typedef types.
|
* NOTE: This does not correctly handle parameters with typedef types.
|
||||||
* @param returnType
|
|
||||||
* @param parameters
|
|
||||||
*/
|
*/
|
||||||
|
public static IFunctionType createImplicitFunctionType(IType returnType, IParameter[] parameters, IPointerType thisType) {
|
||||||
public static IFunctionType createImplicitFunctionType(IType returnType, IParameter[] parameters) {
|
|
||||||
IType[] pTypes = new IType[parameters.length];
|
IType[] pTypes = new IType[parameters.length];
|
||||||
IType pt = null;
|
IType pt = null;
|
||||||
|
|
||||||
|
@ -1518,7 +1515,7 @@ public class CPPVisitor {
|
||||||
pTypes[i] = pt;
|
pTypes[i] = pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CPPFunctionType(returnType, pTypes);
|
return new CPPFunctionType(returnType, pTypes, thisType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IType createType(IType returnType, ICPPASTFunctionDeclarator fnDtor) {
|
private static IType createType(IType returnType, ICPPASTFunctionDeclarator fnDtor) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue