From 1eabfa5241d2f7f320a8f4bf32b6e0c7b10f3f14 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 26 Aug 2014 17:50:09 -0700 Subject: [PATCH] Bug 438384 - "syntax error" for class method ref qualifiers --- .../parser/tests/ast2/AST2CPPSpecTest.java | 35 +++++++++---- .../org.eclipse.cdt.core/META-INF/MANIFEST.MF | 2 +- .../internal/core/model/ASTStringUtil.java | 12 +++++ .../eclipse/cdt/core/dom/ast/ASTTypeUtil.java | 11 ++++ .../ast/cpp/ICPPASTFunctionDeclarator.java | 19 ++++++- .../core/dom/ast/cpp/ICPPFunctionType.java | 20 ++++++-- .../parser/cpp/CPPASTFunctionDeclarator.java | 15 +++++- .../core/dom/parser/cpp/CPPClosureType.java | 6 +-- .../core/dom/parser/cpp/CPPFunctionType.java | 39 +++++++++++---- .../dom/parser/cpp/GNUCPPSourceParser.java | 19 ++++++- .../parser/cpp/semantics/CPPTemplates.java | 9 ++-- .../dom/parser/cpp/semantics/CPPVisitor.java | 7 ++- .../parser/cpp/semantics/SemanticUtil.java | 6 ++- .../rewrite/astwriter/DeclaratorWriter.java | 12 +++++ .../composite/cpp/CPPCompositesFactory.java | 5 +- .../formatter/CodeFormatterVisitor.java | 50 +++---------------- .../ImplementMethodRefactoring.java | 3 +- 17 files changed, 187 insertions(+), 83 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index 0e34a15f5b4..5b29df60322 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -2242,6 +2242,31 @@ public class AST2CPPSpecTest extends AST2SpecTestBase { parse(getAboveComment(), ParserLanguage.CPP, true, 0); } + //class A { + // void a() & {} + // void b() && {} + // + // void c() const& {} + // void d() const&& {} + // + // void e() volatile & {} + // void f() volatile && {} + // + // void g() volatile const& {} + // void h() volatile const&& {} + //}; + public void test8s4() throws Exception { + parse(getAboveComment(), ParserLanguage.CPP, true, 0); + } + + // void print(int a, int) + // { + // //printf("a = %d",a); + // } + public void test8_4s5() throws Exception { + parse(getAboveComment(), ParserLanguage.CPP, true, 0); + } + // int a; // struct X { // static int a; @@ -5717,7 +5742,7 @@ public class AST2CPPSpecTest extends AST2SpecTestBase { // template int f(T[5]); // int I = f(0); - // int j = f(0); // invalid array // also no error with gcc + // int j = f(0); // invalid array public void _test14_8_2s8b() throws Exception { final String content= getAboveComment(); BindingAssertionHelper bh= new BindingAssertionHelper(content, true); @@ -6593,14 +6618,6 @@ public class AST2CPPSpecTest extends AST2SpecTestBase { parse(getAboveComment(), ParserLanguage.CPP, false, 0); } - // void print(int a, int) - // { - // //printf("a = %d",a); - // } - public void test8_4s5() throws Exception { - parse(getAboveComment(), ParserLanguage.CPP, true, 0); - } - // int a; // const int b = a; // int c = b; diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index db827143d38..4aaa50b55a8 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true -Bundle-Version: 5.8.0.qualifier +Bundle-Version: 5.9.0.qualifier Bundle-Activator: org.eclipse.cdt.core.CCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java index c9fbbf496d9..e6e5da5d3f2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java @@ -59,6 +59,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDecltypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator.RefQualifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNameSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression; @@ -314,6 +315,17 @@ public class ASTStringUtil { if (cppFunctionDecl.isVolatile()) { buffer.append(Keywords.VOLATILE).append(' '); } + RefQualifier refQualifier = cppFunctionDecl.getRefQualifier(); + if (refQualifier != null) { + switch (refQualifier) { + case LVALUE: + buffer.append(Keywords.cpAMPER).append(' '); + break; + case RVALUE: + buffer.append(Keywords.cpAND).append(' '); + break; + } + } if (cppFunctionDecl.isPureVirtual()) { buffer.append("=0 "); //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java index 252f7e22cdf..9d4cd0c4a2b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java @@ -398,6 +398,9 @@ public class ASTTypeUtil { if (type instanceof ICPPFunctionType) { ICPPFunctionType ft= (ICPPFunctionType) type; needSpace= appendCVQ(result, needSpace, ft.isConst(), ft.isVolatile(), false); + if (ft.hasRefQualifier()) { + appendRefQualifier(result, needSpace, ft.isRValueReference()); needSpace = true; + } } } else if (type instanceof IPointerType) { if (type instanceof ICPPPointerToMemberType) { @@ -466,6 +469,14 @@ public class ASTTypeUtil { return needSpace; } + private static void appendRefQualifier(StringBuilder target, boolean needSpace, + boolean isRValueReference) { + if (needSpace) { + target.append(SPACE); + } + target.append(isRValueReference ? Keywords.cpAND : Keywords.cpAMPER); + } + /** * Returns the normalized string representation of the type. * @see #getType(IType, boolean) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java index 2d69c437aca..e551a15ece8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 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 @@ -26,6 +26,11 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; * @noextend This interface is not intended to be extended by clients. */ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarator, ICPPASTDeclarator { + /** + * @since 5.9 + */ + public enum RefQualifier { LVALUE, RVALUE } + /** * Used as return value for {@link #getExceptionSpecification()}. * @since 5.1 @@ -99,6 +104,18 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato */ public void setPureVirtual(boolean isPureVirtual); + /** + * Returns the ref-qualifier. + * @since 5.9 + */ + public RefQualifier getRefQualifier(); + + /** + * Sets the ref-qualifier. + * @since 5.9 + */ + public void setRefQualifier(RefQualifier value); + /** * @since 5.2 */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionType.java index 6305c925e67..fbf9f9515ae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005-2009 IBM Corporation and others. + * Copyright (c) 2005, 2014 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 @@ -24,18 +24,30 @@ public interface ICPPFunctionType extends IFunctionType { * Returns {@code true} for a constant method. */ public boolean isConst(); - + /** * Returns {@code true} for a volatile method. */ public boolean isVolatile(); - + + /** + * Returns {@code true} for a method declared with a ref-qualifier. + * @since 5.9 + */ + public boolean hasRefQualifier(); + + /** + * Returns {@code true} if the type of the implicit object parameter is an rvalue reference. + * @since 5.9 + */ + public boolean isRValueReference(); + /** * Whether the function type takes variable number of arguments. * @since 5.2 */ public boolean takesVarArgs(); - + /** * @deprecated function types don't relate to this pointers at all. * @noreference This method is not intended to be referenced by clients and should be removed. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java index 16cdb6d8873..9282028e468 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 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 @@ -44,6 +44,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS private boolean isVolatile; private boolean isConst; private boolean isMutable; + private RefQualifier refQualifier; private ICPPFunctionScope scope; @@ -67,6 +68,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS copy.isVolatile = isVolatile; copy.isConst = isConst; copy.isMutable = isMutable; + copy.refQualifier = refQualifier; for (IASTParameterDeclaration param : getParameters()) { copy.addParameterDeclaration(param == null ? null : param.copy(style)); @@ -213,6 +215,17 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS } @Override + public RefQualifier getRefQualifier() { + return refQualifier; + } + + @Override + public void setRefQualifier(RefQualifier value) { + assertNotFrozen(); + refQualifier = value; + } + + @Override @Deprecated public org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer[] getConstructorChain() { if (ASTQueries.findTypeRelevantDeclarator(this) == this) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java index 01f86a3ef0a..74d4e110476 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2013 Wind River Systems, Inc. and others. + * Copyright (c) 2010, 2014 Wind River Systems, Inc. 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 @@ -102,7 +102,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP // Function call operator final IType returnType= getReturnType(); final IType[] parameterTypes= getParameterTypes(); - ft= new CPPFunctionType(returnType, parameterTypes, !isMutable(), false, false); + ft= new CPPFunctionType(returnType, parameterTypes, !isMutable(), false, false, false, false); ICPPParameter[] params = new ICPPParameter[parameterTypes.length]; for (int i = 0; i < params.length; i++) { @@ -117,7 +117,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP // Conversion operator if (needConversionOperator) { final CPPFunctionType conversionTarget = new CPPFunctionType(returnType, parameterTypes); - ft= new CPPFunctionType(conversionTarget, IType.EMPTY_TYPE_ARRAY, true, false, false); + ft= new CPPFunctionType(conversionTarget, IType.EMPTY_TYPE_ARRAY, true, false, false, false, false); m= new CPPImplicitMethod(scope, CPPASTConversionName.createName(conversionTarget, null), ft, params); result[5]= m; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java index af5e800a349..3fc876aa289 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 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 @@ -31,18 +31,22 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { private final IType returnType; private final boolean isConst; private final boolean isVolatile; + private final boolean hasRefQualifier; + private final boolean isRValueReference; private final boolean takesVarargs; public CPPFunctionType(IType returnType, IType[] types) { - this(returnType, types, false, false, false); + this(returnType, types, false, false, false, false, false); } public CPPFunctionType(IType returnType, IType[] types, boolean isConst, boolean isVolatile, - boolean takesVarargs) { + boolean hasRefQualifier, boolean isRValueReference, boolean takesVarargs) { this.returnType = returnType; this.parameters = types; this.isConst = isConst; this.isVolatile= isVolatile; + this.hasRefQualifier = hasRefQualifier; + this.isRValueReference = isRValueReference; this.takesVarargs= takesVarargs; } @@ -52,7 +56,10 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { return o.isSameType(this); if (o instanceof ICPPFunctionType) { ICPPFunctionType ft = (ICPPFunctionType) o; - if (isConst() != ft.isConst() || isVolatile() != ft.isVolatile() || takesVarArgs() != ft.takesVarArgs()) { + if (isConst() != ft.isConst() || isVolatile() != ft.isVolatile() + || hasRefQualifier() != ft.hasRefQualifier() + || isRValueReference() != ft.isRValueReference() + || takesVarArgs() != ft.takesVarArgs()) { return false; } @@ -62,7 +69,7 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { if ((returnType == null) ^ (ft.getReturnType() == null)) return false; - if (returnType != null && ! returnType.isSameType(ft.getReturnType())) + if (returnType != null && !returnType.isSameType(ft.getReturnType())) return false; if (parameters.length == fps.length) { @@ -72,7 +79,7 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { } } else { if (!SemanticUtil.isEmptyParameterList(parameters) - || !SemanticUtil.isEmptyParameterList(fps)) { + || !SemanticUtil.isEmptyParameterList(fps)) { return false; } } @@ -118,6 +125,16 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { return isVolatile; } + @Override + public boolean hasRefQualifier() { + return hasRefQualifier; + } + + @Override + public boolean isRValueReference() { + return isRValueReference; + } + @Override public boolean takesVarArgs() { return takesVarargs; @@ -131,9 +148,11 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { short firstBytes= ITypeMarshalBuffer.FUNCTION_TYPE; - if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1; - if (takesVarArgs()) firstBytes |= ITypeMarshalBuffer.FLAG2; - if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG3; + if (isConst) firstBytes |= ITypeMarshalBuffer.FLAG1; + if (takesVarargs) firstBytes |= ITypeMarshalBuffer.FLAG2; + if (isVolatile) firstBytes |= ITypeMarshalBuffer.FLAG3; + if (hasRefQualifier) firstBytes |= ITypeMarshalBuffer.FLAG4; + if (isRValueReference) firstBytes |= ITypeMarshalBuffer.FLAG5; buffer.putShort(firstBytes); buffer.putInt(parameters.length); @@ -154,6 +173,8 @@ public class CPPFunctionType implements ICPPFunctionType, ISerializableType { return new CPPFunctionType(rt, pars, (firstBytes & ITypeMarshalBuffer.FLAG1) != 0, // const (firstBytes & ITypeMarshalBuffer.FLAG3) != 0, // volatile + (firstBytes & ITypeMarshalBuffer.FLAG5) != 0, // has ref-qualifier + (firstBytes & ITypeMarshalBuffer.FLAG4) != 0, // rvalue reference (firstBytes & ITypeMarshalBuffer.FLAG2) != 0); // takes varargs } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 334750bd871..6377117b0e7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -74,6 +74,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAttribute; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTClassVirtSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; @@ -91,13 +92,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator.RefQualifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression.CaptureDefault; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTClassVirtSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTName; @@ -4224,7 +4225,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { endOffset= consume().getEndOffset(); } } else { - cvloop: while(true) { + cvloop: while (true) { switch (LT(1)) { case IToken.t_const: fc.setConst(true); @@ -4240,6 +4241,20 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } + // ref-qualifiers + switch (LT(1)) { + case IToken.tAMPER: + fc.setRefQualifier(RefQualifier.LVALUE); + endOffset= consume().getEndOffset(); + break; + case IToken.tAND: + fc.setRefQualifier(RefQualifier.RVALUE); + endOffset= consume().getEndOffset(); + break; + default: + break; + } + // throws clause if (LT(1) == IToken.t_throw) { fc.setEmptyExceptionSpecification(); 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 0552f12b918..cd4e128bcd4 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 @@ -864,6 +864,7 @@ public class CPPTemplates { if (i < parameters.length) { par = parameters[i]; } // else reuse last parameter (which should be a pack) + @SuppressWarnings("null") IValue defaultValue = par.getDefaultValue(); IValue specializedValue = CPPTemplates.instantiateValue(defaultValue, tpMap, packOffset, within, maxdepth, point); @@ -1325,7 +1326,8 @@ public class CPPTemplates { params[i]= CPPVisitor.adjustParameterType(p, true); } } - return new CPPFunctionType(ret, params, ft.isConst(), ft.isVolatile(), ft.takesVarArgs()); + return new CPPFunctionType(ret, params, ft.isConst(), ft.isVolatile(), + ft.hasRefQualifier(), ft.isRValueReference(), ft.takesVarArgs()); } if (type instanceof ICPPTemplateParameter) { @@ -2227,10 +2229,11 @@ public class CPPTemplates { } } ICPPFunctionType originalType = function.getType(); - if (i == parameters.length) // no parameters with default arguments + if (i == parameters.length) // No parameters with default arguments. return originalType; return new CPPFunctionType(originalType.getReturnType(), ArrayUtil.trim(parameterTypes), - originalType.isConst(), originalType.isVolatile(), originalType.takesVarArgs()); + originalType.isConst(), originalType.isVolatile(), originalType.hasRefQualifier(), + originalType.isRValueReference(), originalType.takesVarArgs()); } private static int compareSpecialization(ICPPFunctionTemplate f1, ICPPFunctionTemplate f2, TypeSelection mode, IASTNode point) throws DOMException { 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 d538c4eb500..db7878dfa59 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 @@ -112,6 +112,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator.RefQualifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause; @@ -1830,7 +1831,7 @@ public class CPPVisitor extends ASTQueries { pTypes[i] = pt; } - return new CPPFunctionType(returnType, pTypes, isConst, isVolatile, false); + return new CPPFunctionType(returnType, pTypes, isConst, isVolatile, false, false, false); } /** @@ -1869,7 +1870,9 @@ public class CPPVisitor extends ASTQueries { returnType = getPointerTypes(returnType, fnDtor); } - CPPFunctionType type = new CPPFunctionType(returnType, pTypes, fnDtor.isConst(), fnDtor.isVolatile(), + RefQualifier refQualifier = fnDtor.getRefQualifier(); + CPPFunctionType type = new CPPFunctionType(returnType, pTypes, fnDtor.isConst(), + fnDtor.isVolatile(), refQualifier != null, refQualifier == RefQualifier.RVALUE, fnDtor.takesVarArgs()); final IASTDeclarator nested = fnDtor.getNestedDeclarator(); if (nested != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index 2d9887cd974..1676df560ee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -355,7 +355,8 @@ public class SemanticUtil { if (ret == r && params == ps) { return type; } - return new CPPFunctionType(ret, params, ft.isConst(), ft.isVolatile(), ft.takesVarArgs()); + return new CPPFunctionType(ret, params, ft.isConst(), ft.isVolatile(), + ft.hasRefQualifier(), ft.isRValueReference(), ft.takesVarArgs()); } if (type instanceof ITypedef) { @@ -499,7 +500,8 @@ public class SemanticUtil { if (ret == r) { return type; } - return new CPPFunctionType(ret, ft.getParameterTypes(), ft.isConst(), ft.isVolatile(), ft.takesVarArgs()); + return new CPPFunctionType(ret, ft.getParameterTypes(), ft.isConst(), ft.isVolatile(), + ft.hasRefQualifier(), ft.isRValueReference(), ft.takesVarArgs()); } if (type instanceof ITypeContainer) { final ITypeContainer tc = (ITypeContainer) type; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java index 585c332517f..f5ee1c59b70 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java @@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator.RefQualifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; @@ -142,6 +143,17 @@ public class DeclaratorWriter extends NodeWriter { scribe.printSpace(); scribe.print(Keywords.VOLATILE); } + RefQualifier refQualifier = funcDec.getRefQualifier(); + if (refQualifier != null) { + switch (refQualifier) { + case LVALUE: + scribe.print(Keywords.cpAMPER); + break; + case RVALUE: + scribe.print(Keywords.cpAND); + break; + } + } if (funcDec.isMutable()) { scribe.printSpace(); scribe.print(Keywords.MUTABLE); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java index f9c4632182d..ac013cae8ca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Symbian Software Systems and others. + * Copyright (c) 2007, 2014 Symbian Software Systems 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 @@ -157,7 +157,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory { IType[] p= ft.getParameterTypes(); IType[] p2= getCompositeTypes(p); if (r != r2 || p != p2) { - return new CPPFunctionType(r2, p2, ft.isConst(), ft.isVolatile(), ft.takesVarArgs()); + return new CPPFunctionType(r2, p2, ft.isConst(), ft.isVolatile(), + ft.hasRefQualifier(), ft.isRValueReference(), ft.takesVarArgs()); } return ft; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index ba913a88f75..1a8767025b7 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2013 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2014 Wind River Systems, Inc. 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 @@ -289,6 +289,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, public void run() { boolean needSpace = skipConstVolatileRestrict(); int token = peekNextToken(); + // Ref-qualifier. + if (token == Token.tAMPER || token == Token.tAND) { + scribe.printNextToken(token, true); + token = peekNextToken(); + needSpace = true; + } if (token == Token.t_throw || token == Token.tIDENTIFIER) { if (node instanceof ICPPASTFunctionDeclarator) { final IASTTypeId[] exceptionSpecification= @@ -1417,48 +1423,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, formatList(parameters, options, true, node.takesVarArgs(), new FunctionDeclaratorTailFormatter(node, tailFormatter)); -// IASTFileLocation fileLocation= node.getFileLocation(); -// if (fileLocation != null && -// scribe.scanner.getCurrentPosition() < fileLocation.getNodeOffset() + fileLocation.getNodeLength()) { -// skipConstVolatileRestrict(); -// -// int token = peekNextToken(); -// if (token == Token.t_throw || token == Token.tIDENTIFIER) { -// final IASTTypeId[] exceptionSpecification= node.getExceptionSpecification(); -// if (exceptionSpecification != null && token == Token.t_throw) -// formatExceptionSpecification(exceptionSpecification); -// if (peekNextToken() == Token.tIDENTIFIER) { -// Alignment alignment = scribe.createAlignment( -// Alignment.TRAILING_TEXT, -// Alignment.M_COMPACT_SPLIT, -// 1, -// scribe.scanner.getCurrentPosition()); -// -// scribe.enterAlignment(alignment); -// boolean ok = false; -// do { -// try { -// scribe.alignFragment(alignment, 0); -// // Skip the rest of the declarator. -// scribe.printTrailingComment(); -// scribe.space(); -// if (tailFormatter != null) -// tailFormatter.run(); -// skipNode(node); -// ok = true; -// } catch (AlignmentException e) { -// scribe.redoAlignment(e); -// } -// } while (!ok); -// scribe.exitAlignment(alignment, true); -// } -// } else { -// // Skip the rest (=0) -// scribe.printTrailingComment(); -// scribe.space(); -// skipNode(node); -// } -// } return PROCESS_SKIP; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java index 5385fd8fabc..72a79121f12 100755 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/ImplementMethodRefactoring.java @@ -38,11 +38,11 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTNode.CopyStyle; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; @@ -264,6 +264,7 @@ public class ImplementMethodRefactoring extends CRefactoring { createdMethodDeclarator = nodeFactory.newFunctionDeclarator(qName); createdMethodDeclarator.setConst(functionDeclarator.isConst()); + createdMethodDeclarator.setRefQualifier(functionDeclarator.getRefQualifier()); for (IASTPointerOperator pop : functionDeclarator.getPointerOperators()) { createdMethodDeclarator.addPointerOperator(pop.copy(CopyStyle.withLocations)); }