From e55325538485fe691418c4b50c7a4d947239d95c Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 16 May 2012 13:27:59 -0700 Subject: [PATCH] Bug 332829. Parsing support for constexpr keyword. Also added few new C++11 keywords. --- .../parser/tests/ast2/AST2CPPSpecTest.java | 18 +++++++++ .../cdt/core/dom/ast/ASTSignatureUtil.java | 15 ++++++-- .../dom/ast/cpp/ICPPASTDeclSpecifier.java | 16 ++++++++ .../org/eclipse/cdt/core/parser/IToken.java | 7 +++- .../org/eclipse/cdt/core/parser/Keywords.java | 33 +++++++++++++---- .../parser/cpp/CPPASTBaseDeclSpecifier.java | 37 +++++++++++++------ .../cpp/CPPASTCompositeTypeSpecifier.java | 7 +--- .../cpp/CPPASTElaboratedTypeSpecifier.java | 10 ++--- .../cpp/CPPASTEnumerationSpecifier.java | 7 +--- .../parser/cpp/CPPASTNamedTypeSpecifier.java | 6 +-- .../parser/cpp/CPPASTSimpleDeclSpecifier.java | 29 ++++++--------- .../dom/parser/cpp/GNUCPPSourceParser.java | 21 +++++++---- .../parser/cpp/GPPASTSimpleDeclSpecifier.java | 15 +++----- .../dom/rewrite/astwriter/DeclSpecWriter.java | 10 +++-- .../core/parser/token/KeywordSets.java | 6 +++ .../TrailNodeEqualityChecker.java | 27 +++++++------- .../xlc/ast/XlcCPPASTVectorTypeSpecifier.java | 6 +-- 17 files changed, 166 insertions(+), 104 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 156d1e97c51..c9e3cbc9c99 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 @@ -1184,6 +1184,24 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { assertInstance(d, IASTProblemDeclaration.class); } + // constexpr int square(int x); + // constexpr int bufsz = 1024; + // struct pixel { + // int x; + // int y; + // constexpr pixel(int); + // }; + // constexpr pixel::pixel(int a) + // : x(square(a)), y(square(a)) + // { } + // constexpr int square(int x) { + // return x * x; + // } + // constexpr pixel large(4); + public void test7_1_5s1() throws Exception { + parse(getAboveComment(), ParserLanguage.CPP, true, 0); + } + // int foo() { // const int ci = 3; // cvqualified (initialized as required) // ci = 4; // illformed: attempt to modify const diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java index 8456fe8b57b..33edb3e4f21 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java @@ -510,7 +510,16 @@ public class ASTSignatureUtil { } if (declSpec instanceof ICPPASTDeclSpecifier) { - if (((ICPPASTDeclSpecifier) declSpec).isExplicit()) { + ICPPASTDeclSpecifier cppDeclSpec = (ICPPASTDeclSpecifier) declSpec; + if (cppDeclSpec.isConstexpr()) { + if (needSpace) { + result.append(SPACE); + needSpace = false; + } + result.append(Keywords.CONSTEXPR); + needSpace = true; + } + if (cppDeclSpec.isExplicit()) { if (needSpace) { result.append(SPACE); needSpace = false; @@ -518,7 +527,7 @@ public class ASTSignatureUtil { result.append(Keywords.EXPLICIT); needSpace = true; } - if (((ICPPASTDeclSpecifier) declSpec).isFriend()) { + if (cppDeclSpec.isFriend()) { if (needSpace) { result.append(SPACE); needSpace = false; @@ -526,7 +535,7 @@ public class ASTSignatureUtil { result.append(Keywords.FRIEND); needSpace = true; } - if (((ICPPASTDeclSpecifier) declSpec).isVirtual()) { + if (cppDeclSpec.isVirtual()) { if (needSpace) { result.append(SPACE); needSpace = false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTDeclSpecifier.java index 0374605f39b..761bf1c7fe0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTDeclSpecifier.java @@ -63,6 +63,22 @@ public interface ICPPASTDeclSpecifier extends IASTDeclSpecifier { */ public void setExplicit(boolean value); + /** + * Is this a constexpr + * + * @return boolean + * @since 5.4 + */ + public boolean isConstexpr(); + + /** + * Sets this to be constexpr. + * + * @param value the new value + * @since 5.4 + */ + public void setConstexpr(boolean value); + /** * @since 5.1 */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java index e11ac4ca605..887aba558e7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java @@ -114,7 +114,8 @@ public interface IToken { /** @deprecated use {@link #tBITCOMPLEMENT} */ @Deprecated int tCOMPL= tBITCOMPLEMENT; /** @deprecated use {@link #tBITCOMPLEMENT} */ @Deprecated int t_compl = 66; int t_const = 67; - + + /** @since 5.4 */ int t_constexpr = 5400; int t_const_cast = 69; int t_continue = 70; /** @since 5.2 */ @@ -141,7 +142,8 @@ public interface IToken { int t_mutable = 90; int t_namespace = 91; int t_new = 92; - /** @since 5.4 */ int t_nullptr = 5400; + /** @since 5.4 */ int t_noexcept = 5401; + /** @since 5.4 */ int t_nullptr = 5402; /** @deprecated use {@link #tNOT} */ @Deprecated int t_not = 93; /** @deprecated use {@link #tNOTEQUAL} */ @Deprecated int t_not_eq = 94; int t_operator = 95; @@ -164,6 +166,7 @@ public interface IToken { int t_switch = 110; int t_template = 111; int t_this = 112; + /** @since 5.4 */ int t_thread_local = 5403; int t_throw = 113; int t_true = 114; int t_try = 115; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/Keywords.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/Keywords.java index 2a3c2f16ee1..511699575d9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/Keywords.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/Keywords.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM Rational Software) - Initial API and implementation - * Anton Leherbauer (Wind River Systems) - * Markus Schorn (Wind River Systems) + * John Camelon (IBM Rational Software) - Initial API and implementation + * Anton Leherbauer (Wind River Systems) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser; @@ -20,9 +20,10 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap; */ @SuppressWarnings("nls") public class Keywords { - - public static final String CAST = "cast"; - public static final String ALIGNOF = "alignof"; + public static final String CAST = "cast"; + /** @since 5.4 */ + public static final String ALIGNAS = "alignas"; + public static final String ALIGNOF = "alignof"; public static final String TYPEOF = "typeof"; public static final String _BOOL = "_Bool"; @@ -46,6 +47,8 @@ public class Keywords { public static final String CLASS = "class"; public static final String COMPL = "compl"; public static final String CONST = "const"; + /** @since 5.4 */ + public static final String CONSTEXPR = "constexpr"; public static final String CONST_CAST = "const_cast"; public static final String CONTINUE = "continue"; /** @since 5.2 */ @@ -75,7 +78,9 @@ public class Keywords { /** @since 5.4 */ public static final String NULLPTR = "nullptr"; public static final String NEW = "new"; - public static final String NOT = "not"; + /** @since 5.4 */ + public static final String NOEXCEPT = "noexcept"; + public static final String NOT = "not"; public static final String NOT_EQ = "not_eq"; public static final String OPERATOR = "operator"; public static final String OR = "or"; @@ -98,6 +103,8 @@ public class Keywords { public static final String SWITCH = "switch"; public static final String TEMPLATE = "template"; public static final String THIS = "this"; + /** @since 5.4 */ + public static final String THREAD_LOCAL = "thread_local"; public static final String THROW = "throw"; public static final String TRUE = "true"; public static final String TRY = "try"; @@ -119,6 +126,8 @@ public class Keywords { public static final char[] c_BOOL = "_Bool".toCharArray(); public static final char[] c_COMPLEX = "_Complex".toCharArray(); public static final char[] c_IMAGINARY = "_Imaginary".toCharArray(); + /** @since 5.4 */ + public static final char[] cALIGNAS = "alignas".toCharArray(); /** @since 5.3 */ public static final char[] cALIGNOF = "alignof".toCharArray(); public static final char[] cAND = "and".toCharArray(); @@ -139,6 +148,8 @@ public class Keywords { public static final char[] cCLASS = "class".toCharArray(); public static final char[] cCOMPL = "compl".toCharArray(); public static final char[] cCONST = "const".toCharArray(); + /** @since 5.4 */ + public static final char[] cCONSTEXPR = "constexpr".toCharArray(); public static final char[] cCONST_CAST = "const_cast".toCharArray(); public static final char[] cCONTINUE = "continue".toCharArray(); public static final char[] cDEFAULT = "default".toCharArray(); @@ -167,6 +178,8 @@ public class Keywords { public static final char[] cNEW = "new".toCharArray(); /** @since 5.4 */ public static final char[] cNULLPTR = NULLPTR.toCharArray(); + /** @since 5.4 */ + public static final char[] cNOEXCEPT = "noexcept".toCharArray(); public static final char[] cNOT = "not".toCharArray(); public static final char[] cNOT_EQ = "not_eq".toCharArray(); public static final char[] cOPERATOR = "operator".toCharArray(); @@ -192,6 +205,8 @@ public class Keywords { public static final char[] cSWITCH = "switch".toCharArray(); public static final char[] cTEMPLATE = "template".toCharArray(); public static final char[] cTHIS = "this".toCharArray(); + /** @since 5.4 */ + public static final char[] cTHREAD_LOCAL = "thread_local".toCharArray(); public static final char[] cTHROW = "throw".toCharArray(); public static final char[] cTRUE = "true".toCharArray(); public static final char[] cTRY = "try".toCharArray(); @@ -301,7 +316,6 @@ public class Keywords { addCpp(kw); } - private static void addCommon(CharArrayIntMap words) { words.put(Keywords._Pragma, IToken.t_PRAGMA); words.put(Keywords.cAUTO, IToken.t_auto); @@ -354,6 +368,7 @@ public class Keywords { cppkeywords.put(Keywords.cCHAR16_T, IToken.t_char16_t); cppkeywords.put(Keywords.cCHAR32_T, IToken.t_char32_t); cppkeywords.put(Keywords.cCLASS, IToken.t_class); + cppkeywords.put(Keywords.cCONSTEXPR, IToken.t_constexpr); cppkeywords.put(Keywords.cCONST_CAST, IToken.t_const_cast); cppkeywords.put(Keywords.cDECLTYPE, IToken.t_decltype); cppkeywords.put(Keywords.cDELETE, IToken.t_delete); @@ -365,6 +380,7 @@ public class Keywords { cppkeywords.put(Keywords.cMUTABLE, IToken.t_mutable); cppkeywords.put(Keywords.cNAMESPACE, IToken.t_namespace); cppkeywords.put(Keywords.cNEW, IToken.t_new); + cppkeywords.put(Keywords.cNOEXCEPT, IToken.t_noexcept); cppkeywords.put(Keywords.cNULLPTR, IToken.t_nullptr); cppkeywords.put(Keywords.cOPERATOR, IToken.t_operator); cppkeywords.put(Keywords.cPRIVATE, IToken.t_private); @@ -375,6 +391,7 @@ public class Keywords { cppkeywords.put(Keywords.cSTATIC_CAST, IToken.t_static_cast); cppkeywords.put(Keywords.cTEMPLATE, IToken.t_template); cppkeywords.put(Keywords.cTHIS, IToken.t_this); + cppkeywords.put(Keywords.cTHREAD_LOCAL, IToken.t_thread_local); cppkeywords.put(Keywords.cTHROW, IToken.t_throw); cppkeywords.put(Keywords.cTRUE, IToken.t_true); cppkeywords.put(Keywords.cTRY, IToken.t_try); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java index a987b133687..aad5598a91d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java @@ -22,6 +22,7 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST private boolean friend; private boolean inline; private boolean isConst; + private boolean isConstexpr; private boolean isVolatile; private boolean isRestrict; private int sc; @@ -55,6 +56,17 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST isConst = value; } + @Override + public boolean isConstexpr() { + return isConstexpr; + } + + @Override + public void setConstexpr(boolean value) { + assertNotFrozen(); + isConstexpr = value; + } + @Override public boolean isVolatile() { return isVolatile; @@ -116,18 +128,19 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST this.explicit = value; } - protected void copyBaseDeclSpec(CPPASTBaseDeclSpecifier other) { - other.friend = friend; - other.inline = inline; - other.isConst = isConst; - other.isVolatile = isVolatile; - other.isRestrict= isRestrict; - other.virtual = virtual; - other.explicit = explicit; - other.sc = sc; - other.setOffsetAndLength(this); - } - + protected T copy(T copy, CopyStyle style) { + copy.friend = friend; + copy.inline = inline; + copy.isConst = isConst; + copy.isConstexpr = isConstexpr; + copy.isVolatile = isVolatile; + copy.isRestrict= isRestrict; + copy.virtual = virtual; + copy.explicit = explicit; + copy.sc = sc; + return super.copy(copy, style); + } + /** * Provided for debugging purposes, only. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java index 20ef93b2382..964f20290da 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java @@ -61,16 +61,11 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier public CPPASTCompositeTypeSpecifier copy(CopyStyle style) { CPPASTCompositeTypeSpecifier copy = new CPPASTCompositeTypeSpecifier(fKey, fName == null ? null : fName.copy(style)); - copyBaseDeclSpec(copy); for (IASTDeclaration member : getMembers()) copy.addMemberDeclaration(member == null ? null : member.copy(style)); for (ICPPASTBaseSpecifier baseSpecifier : getBaseSpecifiers()) copy.addBaseSpecifier(baseSpecifier == null ? null : baseSpecifier.copy(style)); - - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return super.copy(copy, style); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java index a730058492d..acd89eed3e6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java @@ -45,13 +45,9 @@ public class CPPASTElaboratedTypeSpecifier extends CPPASTBaseDeclSpecifier @Override public CPPASTElaboratedTypeSpecifier copy(CopyStyle style) { - CPPASTElaboratedTypeSpecifier copy = new CPPASTElaboratedTypeSpecifier(kind, name == null - ? null : name.copy(style)); - copyBaseDeclSpec(copy); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + CPPASTElaboratedTypeSpecifier copy = + new CPPASTElaboratedTypeSpecifier(kind, name == null ? null : name.copy(style)); + return super.copy(copy, style); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java index f91b784b2f8..b5d58ffd789 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java @@ -55,13 +55,10 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier new CPPASTEnumerationSpecifier(fIsScoped, fName == null ? null : fName.copy(style), fBaseType == null ? null : fBaseType.copy(style)); copy.fIsOpaque = fIsOpaque; - for (IASTEnumerator enumerator : getEnumerators()) + for (IASTEnumerator enumerator : getEnumerators()) { copy.addEnumerator(enumerator == null ? null : enumerator.copy(style)); - copyBaseDeclSpec(copy); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); } - return copy; + return super.copy(copy, style); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java index 4f9fe0081af..bbfc9cd0b12 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java @@ -47,12 +47,8 @@ public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier public CPPASTNamedTypeSpecifier copy(CopyStyle style) { CPPASTNamedTypeSpecifier copy = new CPPASTNamedTypeSpecifier(name == null ? null : name.copy(style)); - copyBaseDeclSpec(copy); copy.typename = typename; - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return super.copy(copy, style); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java index bf020df8804..45804b803d4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java @@ -37,27 +37,22 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier @Override public CPPASTSimpleDeclSpecifier copy(CopyStyle style) { - CPPASTSimpleDeclSpecifier copy = new CPPASTSimpleDeclSpecifier(); - copySimpleDeclSpec(copy, style); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(new CPPASTSimpleDeclSpecifier(), style); } - protected void copySimpleDeclSpec(CPPASTSimpleDeclSpecifier other, CopyStyle style) { - copyBaseDeclSpec(other); - other.type = type; - other.isSigned = isSigned; - other.isUnsigned = isUnsigned; - other.isShort = isShort; - other.isLong = isLong; - other.isLonglong= isLonglong; - other.isComplex= isComplex; - other.isImaginary= isImaginary; + protected T copy(T copy, CopyStyle style) { + copy.type = type; + copy.isSigned = isSigned; + copy.isUnsigned = isUnsigned; + copy.isShort = isShort; + copy.isLong = isLong; + copy.isLonglong= isLonglong; + copy.isComplex= isComplex; + copy.isImaginary= isImaginary; if (fDeclTypeExpression != null) { - other.setDeclTypeExpression(fDeclTypeExpression.copy(style)); + copy.setDeclTypeExpression(fDeclTypeExpression.copy(style)); } + return super.copy(copy, style); } /** 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 7ee540631fb..ff1e01f9025 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 @@ -2593,9 +2593,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } - private final static int INLINE=0x1, CONST=0x2, RESTRICT=0x4, VOLATILE=0x8, - SHORT=0x10, UNSIGNED= 0x20, SIGNED=0x40, COMPLEX=0x80, IMAGINARY=0x100, - VIRTUAL=0x200, EXPLICIT=0x400, FRIEND=0x800; + private final static int INLINE= 0x1, CONST= 0x2, CONSTEXPR= 0x4, RESTRICT= 0x8, VOLATILE= 0x10, + SHORT= 0x20, UNSIGNED= 0x40, SIGNED= 0x80, COMPLEX= 0x100, IMAGINARY= 0x200, + VIRTUAL= 0x400, EXPLICIT= 0x800, FRIEND= 0x1000; private static final int FORBID_IN_EMPTY_DECLSPEC = CONST | RESTRICT | VOLATILE | SHORT | UNSIGNED | SIGNED | COMPLEX | IMAGINARY | FRIEND; @@ -2605,14 +2605,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * the ANSI C++ specification. * declSpecifier : * "register" | "static" | "extern" | "mutable" | - * "inline" | "virtual" | "explicit" | - * "typedef" | "friend" | - * "const" | "volatile" | + * "inline" | "virtual" | "explicit" | + * "typedef" | "friend" | "constexpr" | + * "const" | "volatile" | * "short" | "long" | "signed" | "unsigned" | "int" | * "char" | "wchar_t" | "bool" | "float" | "double" | "void" | * "auto" | - * ("typename")? name | - * { "class" | "struct" | "union" } classSpecifier | + * ("typename")? name | + * { "class" | "struct" | "union" } classSpecifier | * {"enum"} enumSpecifier */ @Override @@ -2707,6 +2707,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { options |= FRIEND; endOffset= consume().getEndOffset(); break; + case IToken.t_constexpr: + options |= CONSTEXPR; + endOffset= consume().getEndOffset(); + break; // type specifier case IToken.t_const: options |= CONST; @@ -3007,6 +3011,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private void configureDeclSpec(ICPPASTDeclSpecifier declSpec, int storageClass, int options) { declSpec.setStorageClass(storageClass); declSpec.setConst((options & CONST) != 0); + declSpec.setConstexpr((options & CONSTEXPR) != 0); declSpec.setVolatile((options & VOLATILE) != 0); declSpec.setInline((options & INLINE) != 0); declSpec.setFriend((options & FRIEND) != 0); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java index 4d3b7d3344e..5a113ed7b4f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPASTSimpleDeclSpecifier.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * John Camelon (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -18,8 +18,8 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier; * @deprecated Replaced by {@link CPPASTSimpleDeclSpecifier} */ @Deprecated -public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier implements - IGPPASTSimpleDeclSpecifier { +public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier + implements IGPPASTSimpleDeclSpecifier { public GPPASTSimpleDeclSpecifier() { } @@ -36,12 +36,7 @@ public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier impleme @Override public GPPASTSimpleDeclSpecifier copy(CopyStyle style) { - GPPASTSimpleDeclSpecifier copy = new GPPASTSimpleDeclSpecifier(); - copySimpleDeclSpec(copy, style); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(new GPPASTSimpleDeclSpecifier(), style); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java index 66d25dd9378..ac0d579a0d0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java @@ -54,11 +54,12 @@ public class DeclSpecWriter extends NodeWriter { private static final String STRUCT = "struct"; //$NON-NLS-1$ private static final String CLASS = "class"; //$NON-NLS-1$ private static final String FRIEND = "friend "; //$NON-NLS-1$ + private static final String CONSTEXPR = "constexpr "; //$NON-NLS-1$ private static final String EXPLICIT = "explicit "; //$NON-NLS-1$ private static final String VIRTUAL = "virtual "; //$NON-NLS-1$ private static final String UNION_SPACE = "union "; //$NON-NLS-1$ private static final String STRUCT_SPACE = "struct "; //$NON-NLS-1$ - private static final String ENUM = "enum "; //$NON-NLS-1$ + private static final String ENUM_SPACE = "enum "; //$NON-NLS-1$ private static final String _BOOL = "_Bool"; //$NON-NLS-1$ public DeclSpecWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) { @@ -168,7 +169,7 @@ public class DeclSpecWriter extends NodeWriter { private String getElabTypeString(int kind) { switch (kind) { case IASTElaboratedTypeSpecifier.k_enum: - return ENUM; + return ENUM_SPACE; case IASTElaboratedTypeSpecifier.k_struct: return STRUCT_SPACE; case IASTElaboratedTypeSpecifier.k_union: @@ -185,6 +186,9 @@ public class DeclSpecWriter extends NodeWriter { if (cppDelcSpec.isVirtual()) { scribe.print(VIRTUAL); } + if (cppDelcSpec.isConstexpr()) { + scribe.print(CONSTEXPR); + } if (cppDelcSpec.isExplicit()) { scribe.print(EXPLICIT); } @@ -209,7 +213,7 @@ public class DeclSpecWriter extends NodeWriter { } private void writeEnumSpec(IASTEnumerationSpecifier enumSpec) { - scribe.print(ENUM); + scribe.print(ENUM_SPACE); enumSpec.getName().accept(visitor); scribe.print('{'); scribe.printSpace(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/KeywordSets.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/KeywordSets.java index 20553a044b5..2328b67a60d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/KeywordSets.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/KeywordSets.java @@ -393,6 +393,7 @@ public class KeywordSets { ALL_CPP.add(Keywords.CLASS); ALL_CPP.add(Keywords.COMPL); ALL_CPP.add(Keywords.CONST); + ALL_CPP.add(Keywords.CONSTEXPR); ALL_CPP.add(Keywords.CONST_CAST); ALL_CPP.add(Keywords.CONTINUE); ALL_CPP.add(Keywords.DECLTYPE); @@ -418,6 +419,7 @@ public class KeywordSets { ALL_CPP.add(Keywords.MUTABLE); ALL_CPP.add(Keywords.NAMESPACE); ALL_CPP.add(Keywords.NEW); + ALL_CPP.add(Keywords.NOEXCEPT); ALL_CPP.add(Keywords.NOT); ALL_CPP.add(Keywords.NOT_EQ); ALL_CPP.add(Keywords.NULLPTR); @@ -440,6 +442,7 @@ public class KeywordSets { ALL_CPP.add(Keywords.SWITCH); ALL_CPP.add(Keywords.TEMPLATE); ALL_CPP.add(Keywords.THIS); + ALL_CPP.add(Keywords.THREAD_LOCAL); ALL_CPP.add(Keywords.THROW); ALL_CPP.add(Keywords.TRUE); ALL_CPP.add(Keywords.TRY); @@ -480,6 +483,7 @@ public class KeywordSets { KEYWORDS_CPP.add(Keywords.CLASS); KEYWORDS_CPP.add(Keywords.COMPL); KEYWORDS_CPP.add(Keywords.CONST); + KEYWORDS_CPP.add(Keywords.CONSTEXPR); KEYWORDS_CPP.add(Keywords.CONST_CAST); KEYWORDS_CPP.add(Keywords.CONTINUE); KEYWORDS_CPP.add(Keywords.DECLTYPE); @@ -501,6 +505,7 @@ public class KeywordSets { KEYWORDS_CPP.add(Keywords.MUTABLE); KEYWORDS_CPP.add(Keywords.NAMESPACE); KEYWORDS_CPP.add(Keywords.NEW); + KEYWORDS_CPP.add(Keywords.NOEXCEPT); KEYWORDS_CPP.add(Keywords.NOT); KEYWORDS_CPP.add(Keywords.NOT_EQ); KEYWORDS_CPP.add(Keywords.NULLPTR); @@ -522,6 +527,7 @@ public class KeywordSets { KEYWORDS_CPP.add(Keywords.SWITCH); KEYWORDS_CPP.add(Keywords.TEMPLATE); KEYWORDS_CPP.add(Keywords.THIS); + KEYWORDS_CPP.add(Keywords.THREAD_LOCAL); KEYWORDS_CPP.add(Keywords.THROW); KEYWORDS_CPP.add(Keywords.TRUE); KEYWORDS_CPP.add(Keywords.TRY); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/TrailNodeEqualityChecker.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/TrailNodeEqualityChecker.java index d2e70c22c7c..4e5e29f942f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/TrailNodeEqualityChecker.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/TrailNodeEqualityChecker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -16,7 +16,6 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; @@ -106,8 +105,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker { } else if (node instanceof IASTName) { return isNameEqual(trailNode, node); } else { - Assert.isLegal(false, "Unexpected node type " + node.getClass().getSimpleName() + //$NON-NLS-1$ - ", this code shoud not be reached"); //$NON-NLS-1$ + CUIPlugin.logError("Unexpected node type " + node.getClass().getSimpleName()); //$NON-NLS-1$ return true; } } @@ -140,10 +138,11 @@ public class TrailNodeEqualityChecker implements EqualityChecker { ICPPASTNamedTypeSpecifier decl = (ICPPASTNamedTypeSpecifier) node; return isDeclSpecifierEqual(trailDecl, decl) && isSameNamedTypeSpecifierName(trailDecl, decl) - && trailDecl.isTypename() == decl.isTypename() - && trailDecl.isExplicit() == decl.isExplicit() - && trailDecl.isFriend() == decl.isFriend() - && trailDecl.isVirtual() == decl.isVirtual(); + && trailDecl.isTypename() == decl.isTypename() + && trailDecl.isConstexpr() == decl.isConstexpr() + && trailDecl.isExplicit() == decl.isExplicit() + && trailDecl.isFriend() == decl.isFriend() + && trailDecl.isVirtual() == decl.isVirtual(); } else if (trailNode instanceof IASTNamedTypeSpecifier) { IASTNamedTypeSpecifier trailDecl = (IASTNamedTypeSpecifier) trailNode; IASTNamedTypeSpecifier decl = (IASTNamedTypeSpecifier) node; @@ -163,9 +162,10 @@ public class TrailNodeEqualityChecker implements EqualityChecker { ICPPASTDeclSpecifier trailDecl = (ICPPASTDeclSpecifier) trailNode; ICPPASTDeclSpecifier decl = (ICPPASTDeclSpecifier) node; return isDeclSpecifierEqual(trailDecl, decl) - && trailDecl.isExplicit() == decl.isExplicit() - && trailDecl.isFriend() == decl.isFriend() - && trailDecl.isVirtual() == decl.isVirtual(); + && trailDecl.isConstexpr() == decl.isConstexpr() + && trailDecl.isExplicit() == decl.isExplicit() + && trailDecl.isFriend() == decl.isFriend() + && trailDecl.isVirtual() == decl.isVirtual(); } else if (trailNode instanceof ICASTDeclSpecifier) { ICASTDeclSpecifier trailDecl = (ICASTDeclSpecifier) trailNode; ICASTDeclSpecifier decl = (ICASTDeclSpecifier) node; @@ -176,7 +176,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker { IASTDeclSpecifier decl = (IASTDeclSpecifier) node; return isDeclSpecifierEqual(trailDecl, decl); } else { - //is same + // The same. return true; } } @@ -315,7 +315,8 @@ public class TrailNodeEqualityChecker implements EqualityChecker { if (trailDeclSpeci instanceof ICPPASTDeclSpecifier) { ICPPASTDeclSpecifier trailCppDecl= (ICPPASTDeclSpecifier) trailDeclSpeci; ICPPASTDeclSpecifier cppDecl= (ICPPASTDeclSpecifier) declSpeci; - if (trailCppDecl.isExplicit() != cppDecl.isExplicit() + if (trailCppDecl.isConstexpr() != cppDecl.isConstexpr() + || trailCppDecl.isExplicit() != cppDecl.isExplicit() || trailCppDecl.isFriend() != cppDecl.isFriend() || trailCppDecl.isVirtual() != cppDecl.isVirtual()) { return false; diff --git a/xlc/org.eclipse.cdt.core.lrparser.xlc/parser/org/eclipse/cdt/internal/core/lrparser/xlc/ast/XlcCPPASTVectorTypeSpecifier.java b/xlc/org.eclipse.cdt.core.lrparser.xlc/parser/org/eclipse/cdt/internal/core/lrparser/xlc/ast/XlcCPPASTVectorTypeSpecifier.java index f3036b962af..1b865bbda59 100644 --- a/xlc/org.eclipse.cdt.core.lrparser.xlc/parser/org/eclipse/cdt/internal/core/lrparser/xlc/ast/XlcCPPASTVectorTypeSpecifier.java +++ b/xlc/org.eclipse.cdt.core.lrparser.xlc/parser/org/eclipse/cdt/internal/core/lrparser/xlc/ast/XlcCPPASTVectorTypeSpecifier.java @@ -30,12 +30,8 @@ public class XlcCPPASTVectorTypeSpecifier extends CPPASTSimpleDeclSpecifier impl @Override public XlcCPPASTVectorTypeSpecifier copy(CopyStyle style) { XlcCPPASTVectorTypeSpecifier copy = new XlcCPPASTVectorTypeSpecifier(); - copySimpleDeclSpec(copy, style); copy.isPixel = isPixel; - if(style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(copy, style); } public boolean isPixel() {