diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 44590f0e434..141f6111c4f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -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); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java index 9aa3af516dd..6b83625c43e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java @@ -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); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java index 5963060af35..e3c8845e6ed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java @@ -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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitConstructor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitConstructor.java index 05bcb702b66..8b40d21a09d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitConstructor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitConstructor.java @@ -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() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java index d71416ec72f..552e14dd9b4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java @@ -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 ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java index 07678a45aee..5c917103a1d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java @@ -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 { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index fbeaa41d580..1cef8b5488b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index a3d685a6ce9..cff32af0452 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -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) {