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 f85e9075dfb..c64e96b3069 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 @@ -1077,6 +1077,13 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { parse(getAboveComment(), ParserLanguage.CPP, true, 0); } + // thread_local int e; + // static thread_local int f; + // extern thread_local int g; + public void test7_1_1s1() throws Exception { + parse(getAboveComment(), ParserLanguage.CPP, true, 0); + } + // static char* f(); // f() has internal linkage // char* f() // f() still has internal linkage // { // 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 33edb3e4f21..7be75b33a5f 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 @@ -511,6 +511,14 @@ public class ASTSignatureUtil { if (declSpec instanceof ICPPASTDeclSpecifier) { ICPPASTDeclSpecifier cppDeclSpec = (ICPPASTDeclSpecifier) declSpec; + if (cppDeclSpec.isThreadLocal()) { + if (needSpace) { + result.append(SPACE); + needSpace = false; + } + result.append(Keywords.THREAD_LOCAL); + needSpace = true; + } if (cppDeclSpec.isConstexpr()) { if (needSpace) { result.append(SPACE); 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 864847fb465..2814b6afa56 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2012 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 @@ -8,6 +8,7 @@ * Contributors: * Doug Schaefer (IBM) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; @@ -79,6 +80,22 @@ public interface ICPPASTDeclSpecifier extends IASTDeclSpecifier { */ public void setConstexpr(boolean value); + /** + * Is this thread_local + * + * @return boolean + * @since 5.4 + */ + public boolean isThreadLocal(); + + /** + * Sets this to be thread_local. + * + * @param value the new value + * @since 5.4 + */ + public void setThreadLocal(boolean value); + /** * @since 5.1 */ 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 aad5598a91d..37d095d279b 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 @@ -26,6 +26,7 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST private boolean isVolatile; private boolean isRestrict; private int sc; + private boolean isThreadLocal; private boolean virtual; private boolean explicit; @@ -45,6 +46,17 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST sc = storageClass; } + @Override + public boolean isThreadLocal() { + return isThreadLocal; + } + + @Override + public void setThreadLocal(boolean value) { + assertNotFrozen(); + isThreadLocal = value; + } + @Override public boolean isConst() { return isConst; 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 ff1e01f9025..e4634d81fb0 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 @@ -2595,9 +2595,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { 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; + VIRTUAL= 0x400, EXPLICIT= 0x800, FRIEND= 0x1000, THREAD_LOCAL= 0x2000; private static final int FORBID_IN_EMPTY_DECLSPEC = - CONST | RESTRICT | VOLATILE | SHORT | UNSIGNED | SIGNED | COMPLEX | IMAGINARY | FRIEND; + CONST | RESTRICT | VOLATILE | SHORT | UNSIGNED | SIGNED | COMPLEX | IMAGINARY | FRIEND | THREAD_LOCAL; /** @@ -2682,6 +2682,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { storageClass = IASTDeclSpecifier.sc_extern; endOffset= consume().getEndOffset(); break; + case IToken.t_thread_local: + options |= THREAD_LOCAL; // thread_local may appear with static or extern + endOffset= consume().getEndOffset(); + break; case IToken.t_mutable: storageClass = IASTDeclSpecifier.sc_mutable; endOffset= consume().getEndOffset(); @@ -3018,6 +3022,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { declSpec.setVirtual((options & VIRTUAL) != 0); declSpec.setExplicit((options & EXPLICIT) != 0); declSpec.setRestrict((options & RESTRICT) != 0); + declSpec.setThreadLocal((options & THREAD_LOCAL) != 0); } private ICPPASTDeclSpecifier enumDeclaration(boolean allowOpaque) throws BacktrackException, EndOfFileException { 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 ac0d579a0d0..dd5de13f038 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 @@ -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 @@ -8,6 +8,7 @@ * * Contributors: * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; @@ -44,23 +45,6 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; * @author Emanuel Graf IFS */ public class DeclSpecWriter extends NodeWriter { - private static final String MUTABLE = "mutable "; //$NON-NLS-1$ - private static final String _COMPLEX = "_Complex "; //$NON-NLS-1$ - private static final String LONG_LONG = "long long "; //$NON-NLS-1$ - private static final String REGISTER = "register "; //$NON-NLS-1$ - private static final String AUTO = "auto "; //$NON-NLS-1$ - private static final String TYPEDEF = "typedef "; //$NON-NLS-1$ - private static final String UNION = "union"; //$NON-NLS-1$ - 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_SPACE = "enum "; //$NON-NLS-1$ - private static final String _BOOL = "_Bool"; //$NON-NLS-1$ public DeclSpecWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) { super(scribe, visitor, commentMap); @@ -89,23 +73,23 @@ public class DeclSpecWriter extends NodeWriter { case IASTSimpleDeclSpecifier.t_unspecified: return ""; //$NON-NLS-1$ case IASTSimpleDeclSpecifier.t_void: - return VOID; + return Keywords.VOID; case IASTSimpleDeclSpecifier.t_char: - return CHAR; + return Keywords.CHAR; case IASTSimpleDeclSpecifier.t_int: - return INT; + return Keywords.INT; case IASTSimpleDeclSpecifier.t_float: - return FLOAT; + return Keywords.FLOAT; case IASTSimpleDeclSpecifier.t_double: - return DOUBLE; + return Keywords.DOUBLE; case IASTSimpleDeclSpecifier.t_bool: - return isCpp ? CPP_BOOL : _BOOL; + return isCpp ? Keywords.BOOL : Keywords._BOOL; case IASTSimpleDeclSpecifier.t_wchar_t: if (isCpp) - return WCHAR_T; + return Keywords.WCHAR_T; break; case IASTSimpleDeclSpecifier.t_char16_t: if (isCpp) @@ -134,7 +118,7 @@ public class DeclSpecWriter extends NodeWriter { private void writeCDeclSpec(ICASTDeclSpecifier cDeclSpec) { if (cDeclSpec.isRestrict()) { - scribe.print(RESTRICT); + scribe.printStringSpace(Keywords.RESTRICT); } if (cDeclSpec instanceof ICASTCompositeTypeSpecifier) { @@ -152,7 +136,7 @@ public class DeclSpecWriter extends NodeWriter { private void writeNamedTypeSpecifier(ICPPASTNamedTypeSpecifier namedSpc) { if (namedSpc.isTypename()) { - scribe.print(TYPENAME); + scribe.printStringSpace(Keywords.TYPENAME); } namedSpc.getName().accept(visitor); } @@ -162,20 +146,20 @@ public class DeclSpecWriter extends NodeWriter { } private void writeElaboratedTypeSec(IASTElaboratedTypeSpecifier elabType) { - scribe.print(getElabTypeString(elabType.getKind())); + scribe.printStringSpace(getElabTypeString(elabType.getKind())); elabType.getName().accept(visitor); } private String getElabTypeString(int kind) { switch (kind) { case IASTElaboratedTypeSpecifier.k_enum: - return ENUM_SPACE; + return Keywords.ENUM; case IASTElaboratedTypeSpecifier.k_struct: - return STRUCT_SPACE; + return Keywords.STRUCT; case IASTElaboratedTypeSpecifier.k_union: - return UNION_SPACE; + return Keywords.UNION; case ICPPASTElaboratedTypeSpecifier.k_class: - return CLASS_SPACE; + return Keywords.CLASS; default: throw new IllegalArgumentException("Unknown elaborated type: " + kind); //$NON-NLS-1$ @@ -184,19 +168,22 @@ public class DeclSpecWriter extends NodeWriter { private void writeCPPDeclSpec(ICPPASTDeclSpecifier cppDelcSpec) { if (cppDelcSpec.isVirtual()) { - scribe.print(VIRTUAL); + scribe.printStringSpace(Keywords.VIRTUAL); } if (cppDelcSpec.isConstexpr()) { - scribe.print(CONSTEXPR); + scribe.printStringSpace(Keywords.CONSTEXPR); } if (cppDelcSpec.isExplicit()) { - scribe.print(EXPLICIT); + scribe.printStringSpace(Keywords.EXPLICIT); } if (cppDelcSpec.isFriend()) { - scribe.print(FRIEND); + scribe.printStringSpace(Keywords.FRIEND); + } + if (cppDelcSpec.isThreadLocal()) { + scribe.printStringSpace(Keywords.THREAD_LOCAL); } if (cppDelcSpec.getStorageClass() == IASTDeclSpecifier.sc_mutable) { - scribe.print(MUTABLE); + scribe.printStringSpace(Keywords.MUTABLE); } if (cppDelcSpec instanceof ICPPASTCompositeTypeSpecifier) { @@ -213,7 +200,7 @@ public class DeclSpecWriter extends NodeWriter { } private void writeEnumSpec(IASTEnumerationSpecifier enumSpec) { - scribe.print(ENUM_SPACE); + scribe.printStringSpace(Keywords.ENUM); enumSpec.getName().accept(visitor); scribe.print('{'); scribe.printSpace(); @@ -288,13 +275,13 @@ public class DeclSpecWriter extends NodeWriter { private void writeBaseSpecifiers(ICPPASTBaseSpecifier specifier) { switch (specifier.getVisibility()) { case ICPPASTBaseSpecifier.v_public: - scribe.printStringSpace(PUBLIC); + scribe.printStringSpace(Keywords.PUBLIC); break; case ICPPASTBaseSpecifier.v_protected: - scribe.printStringSpace(PROTECTED); + scribe.printStringSpace(Keywords.PROTECTED); break; case ICPPASTBaseSpecifier.v_private: - scribe.printStringSpace(PRIVATE); + scribe.printStringSpace(Keywords.PRIVATE); break; } specifier.getName().accept(visitor); @@ -306,7 +293,7 @@ public class DeclSpecWriter extends NodeWriter { } switch (key) { case ICPPASTCompositeTypeSpecifier.k_class: - return CLASS; + return Keywords.CLASS; default: throw new IllegalArgumentException("Unknown type specifier: " + key); //$NON-NLS-1$ } @@ -315,9 +302,9 @@ public class DeclSpecWriter extends NodeWriter { private String getCompositeTypeString(int key) { switch (key) { case IASTCompositeTypeSpecifier.k_struct: - return STRUCT; + return Keywords.STRUCT; case IASTCompositeTypeSpecifier.k_union: - return UNION; + return Keywords.UNION; default: throw new IllegalArgumentException("Unknown type specifier: " + key); //$NON-NLS-1$ } @@ -325,30 +312,30 @@ public class DeclSpecWriter extends NodeWriter { private void writeDeclSpec(IASTDeclSpecifier declSpec) { if (declSpec.isInline()) { - scribe.print(INLINE); + scribe.printStringSpace(Keywords.INLINE); } switch (declSpec.getStorageClass()) { case IASTDeclSpecifier.sc_typedef: - scribe.print(TYPEDEF); + scribe.printStringSpace(Keywords.TYPEDEF); break; case IASTDeclSpecifier.sc_extern: - scribe.print(EXTERN); + scribe.printStringSpace(Keywords.EXTERN); break; case IASTDeclSpecifier.sc_static: - scribe.print(STATIC); + scribe.printStringSpace(Keywords.STATIC); break; case IASTDeclSpecifier.sc_auto: - scribe.print(AUTO); + scribe.printStringSpace(Keywords.AUTO); break; case IASTDeclSpecifier.sc_register: - scribe.print(REGISTER); + scribe.printStringSpace(Keywords.REGISTER); break; } if (declSpec.isConst()) { - scribe.printStringSpace(CONST); + scribe.printStringSpace(Keywords.CONST); } if (declSpec.isVolatile()) { - scribe.printStringSpace(VOLATILE); + scribe.printStringSpace(Keywords.VOLATILE); } } @@ -367,22 +354,23 @@ public class DeclSpecWriter extends NodeWriter { private void printQualifiers(IASTSimpleDeclSpecifier simpDeclSpec) { if (simpDeclSpec.isSigned()) { - scribe.printStringSpace(SIGNED); + scribe.printStringSpace(Keywords.SIGNED); } else if (simpDeclSpec.isUnsigned()) { - scribe.printStringSpace(UNSIGNED); + scribe.printStringSpace(Keywords.UNSIGNED); } if (simpDeclSpec.isShort()) { - scribe.printStringSpace(SHORT); + scribe.printStringSpace(Keywords.SHORT); } else if (simpDeclSpec.isLong()) { - scribe.printStringSpace(LONG); + scribe.printStringSpace(Keywords.LONG); } else if (simpDeclSpec.isLongLong()) { - scribe.print(LONG_LONG); + scribe.printStringSpace(Keywords.LONG); + scribe.printStringSpace(Keywords.LONG); } if (simpDeclSpec instanceof ICASTSimpleDeclSpecifier) { ICASTSimpleDeclSpecifier cSimpDeclSpec = (ICASTSimpleDeclSpecifier) simpDeclSpec; if (cSimpDeclSpec.isComplex()) { - scribe.print(_COMPLEX); + scribe.printStringSpace(Keywords._COMPLEX); } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java index 2e4f6fcc360..dc15a60bdc3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java @@ -51,10 +51,7 @@ public class DeclarationWriter extends NodeWriter { private static final String ASM_END = ")"; //$NON-NLS-1$ private static final String ASM_START = "asm("; //$NON-NLS-1$ private static final String TEMPLATE_DECLARATION = "template<"; //$NON-NLS-1$ - private static final String EXPORT = "export "; //$NON-NLS-1$ private static final String TEMPLATE_SPECIALIZATION = "template <> "; //$NON-NLS-1$ - private static final String NAMESPACE = "namespace "; //$NON-NLS-1$ - private static final String USING = "using "; //$NON-NLS-1$ private boolean printSemicolon; public DeclarationWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) { @@ -111,15 +108,15 @@ public class DeclarationWriter extends NodeWriter { scribe.decrementIndentationLevel(); switch (visiblityLabel.getVisibility()) { case ICPPASTVisibilityLabel.v_private: - scribe.print(PRIVATE); + scribe.print(Keywords.PRIVATE); scribe.print(':'); break; case ICPPASTVisibilityLabel.v_protected: - scribe.print(PROTECTED); + scribe.print(Keywords.PROTECTED); scribe.print(':'); break; case ICPPASTVisibilityLabel.v_public: - scribe.print(PUBLIC); + scribe.print(Keywords.PUBLIC); scribe.print(':'); break; default: @@ -129,15 +126,16 @@ public class DeclarationWriter extends NodeWriter { } private void writeUsingDirective(ICPPASTUsingDirective usingDirective) { - scribe.print(USING + NAMESPACE); + scribe.printStringSpace(Keywords.USING); + scribe.printStringSpace(Keywords.NAMESPACE); usingDirective.getQualifiedName().accept(visitor); scribe.printSemicolon(); } private void writeUsingDeclaration(ICPPASTUsingDeclaration usingDeclaration) { - scribe.print(USING); + scribe.printStringSpace(Keywords.USING); if (usingDeclaration.isTypename()) { - scribe.print(TYPENAME); + scribe.printStringSpace(Keywords.TYPENAME); } usingDeclaration.getName().accept(visitor); scribe.printSemicolon(); @@ -150,7 +148,7 @@ public class DeclarationWriter extends NodeWriter { protected void writeTemplateDeclaration(ICPPASTTemplateDeclaration templateDeclaration) { if (templateDeclaration.isExported()) { - scribe.print(EXPORT); + scribe.printStringSpace(Keywords.EXPORT); } scribe.print(TEMPLATE_DECLARATION); ICPPASTTemplateParameter[] paraDecls = templateDeclaration.getTemplateParameters(); @@ -172,7 +170,7 @@ public class DeclarationWriter extends NodeWriter { } private void writeNamespaceDefinition(ICPPASTNamespaceDefinition namespaceDefinition) { - scribe.print(NAMESPACE); + scribe.printStringSpace(Keywords.NAMESPACE); namespaceDefinition.getName().accept(visitor); if (!hasTrailingComments(namespaceDefinition.getName())) { scribe.newLine(); @@ -200,7 +198,7 @@ public class DeclarationWriter extends NodeWriter { } private void writeNamespaceAlias(ICPPASTNamespaceAlias namespaceAliasDefinition) { - scribe.print(NAMESPACE); + scribe.printStringSpace(Keywords.NAMESPACE); namespaceAliasDefinition.getAlias().accept(visitor); scribe.print(EQUALS); namespaceAliasDefinition.getMappingName().accept(visitor); @@ -208,9 +206,8 @@ public class DeclarationWriter extends NodeWriter { } private void writeLinkageSpecification(ICPPASTLinkageSpecification linkageSpecification) { - scribe.print(EXTERN); - scribe.print(linkageSpecification.getLiteral()); - scribe.printSpaces(1); + scribe.printStringSpace(Keywords.EXTERN); + scribe.printStringSpace(linkageSpecification.getLiteral()); IASTDeclaration[] declarations = linkageSpecification.getDeclarations(); if (declarations.length > 1) { @@ -230,17 +227,17 @@ public class DeclarationWriter extends NodeWriter { private void writeExplicitTemplateInstantiation(ICPPASTExplicitTemplateInstantiation explicitTemplateInstantiation) { switch(explicitTemplateInstantiation.getModifier()) { case ICPPASTExplicitTemplateInstantiation.EXTERN: - scribe.print(EXTERN); + scribe.printStringSpace(Keywords.EXTERN); break; case ICPPASTExplicitTemplateInstantiation.INLINE: - scribe.print(INLINE); + scribe.printStringSpace(Keywords.INLINE); break; case ICPPASTExplicitTemplateInstantiation.STATIC: - scribe.print(STATIC); + scribe.printStringSpace(Keywords.STATIC); break; } - scribe.print(TEMPLATE); + scribe.printStringSpace(Keywords.TEMPLATE); explicitTemplateInstantiation.getDeclaration().accept(visitor); } 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 7d3fdf05c10..bf7a28e139c 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 @@ -9,6 +9,7 @@ * Contributors: * Institute for Software - initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; @@ -29,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; 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; +import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; /** @@ -41,7 +43,6 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; public class DeclaratorWriter extends NodeWriter { private static final String AMPERSAND_AMPERSAND = "&&"; //$NON-NLS-1$ private static final String PURE_VIRTUAL = " = 0"; //$NON-NLS-1$ - private static final String MUTABLE = "mutable"; //$NON-NLS-1$ private static final String ARROW_OPERATOR = "->"; //$NON-NLS-1$ public DeclaratorWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) { @@ -128,15 +129,15 @@ public class DeclaratorWriter extends NodeWriter { private void writeCppFunctionDeclarator(ICPPASTFunctionDeclarator funcDec) { if (funcDec.isConst()) { scribe.printSpace(); - scribe.print(CONST); + scribe.print(Keywords.CONST); } if (funcDec.isVolatile()) { scribe.printSpace(); - scribe.print(VOLATILE); + scribe.print(Keywords.VOLATILE); } if (funcDec.isMutable()) { scribe.printSpace(); - scribe.print(MUTABLE); + scribe.print(Keywords.MUTABLE); } if (funcDec.isPureVirtual()) { scribe.print(PURE_VIRTUAL); @@ -153,7 +154,7 @@ public class DeclaratorWriter extends NodeWriter { protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec, IASTTypeId[] exceptions) { if (exceptions != ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION) { scribe.printSpace(); - scribe.print(THROW); + scribe.printStringSpace(Keywords.THROW); scribe.print('('); writeNodeList(exceptions); scribe.print(')'); @@ -182,13 +183,13 @@ public class DeclaratorWriter extends NodeWriter { } if (operator.isConst()) { - scribe.printStringSpace(CONST); + scribe.printStringSpace(Keywords.CONST); } if (operator.isVolatile()) { - scribe.printStringSpace(VOLATILE); + scribe.printStringSpace(Keywords.VOLATILE); } if (operator.isRestrict()) { - scribe.print(RESTRICT); + scribe.printStringSpace(Keywords.RESTRICT); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java index 150f6c74545..774aa8791e9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java @@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTBinaryExpression; +import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; /** @@ -112,6 +113,7 @@ public class ExpressionWriter extends NodeWriter{ private static final String OPENING_SQUARE_BRACKET = "["; //$NON-NLS-1$ private static final String CLOSING_SQUARE_BRACKET = "]"; //$NON-NLS-1$ private static final String THIS = "this"; //$NON-NLS-1$ + private static final String THROW = "throw "; //$NON-NLS-1$ private final MacroExpansionHandler macroHandler; public ExpressionWriter(Scribe scribe, ASTWriterVisitor visitor, MacroExpansionHandler macroHandler, NodeCommentMap commentMap) { @@ -423,7 +425,7 @@ public class ExpressionWriter extends NodeWriter{ if (fieldRef instanceof ICPPASTFieldReference) { ICPPASTFieldReference cppFieldRef = (ICPPASTFieldReference) fieldRef; if (cppFieldRef.isTemplate()) { - scribe.print(TEMPLATE); + scribe.printStringSpace(Keywords.TEMPLATE); } } fieldRef.getFieldName().accept(visitor); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NameWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NameWriter.java index 941931511cd..610f86a6f3b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NameWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NameWriter.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; +import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeParameter; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; @@ -58,7 +59,7 @@ public class NameWriter extends NodeWriter { private void writeTempalteId(ICPPASTTemplateId tempId) { if (needsTemplateQualifier(tempId)) { - scribe.print(TEMPLATE); + scribe.printStringSpace(Keywords.TEMPLATE); } scribe.print(tempId.getTemplateName().toString()); scribe.print('<'); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java index 1a5e4b1e44f..6e654b9b711 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java @@ -30,31 +30,7 @@ public class NodeWriter { protected NodeCommentMap commentMap; protected static final String COMMA_SPACE = ", "; //$NON-NLS-1$ protected static final String EQUALS = " = "; //$NON-NLS-1$ - protected static final String RESTRICT = "restrict "; //$NON-NLS-1$ - protected static final String TYPENAME = "typename "; //$NON-NLS-1$ - protected static final String PUBLIC = "public"; //$NON-NLS-1$ - protected static final String PRIVATE = "private"; //$NON-NLS-1$ - protected static final String PROTECTED = "protected"; //$NON-NLS-1$ - protected static final String CONST = "const"; //$NON-NLS-1$ - protected static final String VOLATILE = "volatile"; //$NON-NLS-1$ - protected static final String INLINE = "inline "; //$NON-NLS-1$ - protected static final String EXTERN = "extern "; //$NON-NLS-1$ - protected static final String STATIC = "static "; //$NON-NLS-1$ - protected static final String THROW = "throw "; //$NON-NLS-1$ protected static final String SPACE_COLON_SPACE = " : "; //$NON-NLS-1$ - protected static final String TEMPLATE = "template "; //$NON-NLS-1$ - protected static final String DOUBLE = "double"; //$NON-NLS-1$ - protected static final String FLOAT = "float"; //$NON-NLS-1$ - protected static final String INT = "int"; //$NON-NLS-1$ - protected static final String CHAR = "char"; //$NON-NLS-1$ - protected static final String VOID = "void"; //$NON-NLS-1$ - protected static final String WCHAR_T = "wchar_t"; //$NON-NLS-1$ - protected static final String CPP_BOOL = "bool"; //$NON-NLS-1$ - protected static final String LONG = "long"; //$NON-NLS-1$ - protected static final String SHORT = "short"; //$NON-NLS-1$ - protected static final String UNSIGNED = "unsigned"; //$NON-NLS-1$ - protected static final String SIGNED = "signed"; //$NON-NLS-1$ - protected static final String CLASS_SPACE = "class "; //$NON-NLS-1$ protected static final String VAR_ARGS = "..."; //$NON-NLS-1$ protected static final String COLON_COLON = "::"; //$NON-NLS-1$ protected static final String COLON_SPACE = ": "; //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/TemplateParameterWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/TemplateParameterWriter.java index 64d11679574..d4e09f4d925 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/TemplateParameterWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/TemplateParameterWriter.java @@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; +import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; /** @@ -69,10 +70,10 @@ public class TemplateParameterWriter extends NodeWriter { private void writeSimpleTypeTemplateParameter(ICPPASTSimpleTypeTemplateParameter simple) { switch (simple.getParameterType()) { case ICPPASTSimpleTypeTemplateParameter.st_class: - scribe.print(CLASS_SPACE); + scribe.printStringSpace(Keywords.CLASS); break; case ICPPASTSimpleTypeTemplateParameter.st_typename: - scribe.print(TYPENAME); + scribe.printStringSpace(Keywords.TYPENAME); break; } 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 4e5e29f942f..0cc74e006b0 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 @@ -138,10 +138,11 @@ public class TrailNodeEqualityChecker implements EqualityChecker { ICPPASTNamedTypeSpecifier decl = (ICPPASTNamedTypeSpecifier) node; return isDeclSpecifierEqual(trailDecl, decl) && isSameNamedTypeSpecifierName(trailDecl, decl) - && trailDecl.isTypename() == decl.isTypename() && trailDecl.isConstexpr() == decl.isConstexpr() && trailDecl.isExplicit() == decl.isExplicit() && trailDecl.isFriend() == decl.isFriend() + && trailDecl.isThreadLocal() == decl.isThreadLocal() + && trailDecl.isTypename() == decl.isTypename() && trailDecl.isVirtual() == decl.isVirtual(); } else if (trailNode instanceof IASTNamedTypeSpecifier) { IASTNamedTypeSpecifier trailDecl = (IASTNamedTypeSpecifier) trailNode; @@ -157,7 +158,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker { IASTCompositeTypeSpecifier trailDecl = (IASTCompositeTypeSpecifier) trailNode; IASTCompositeTypeSpecifier decl = (IASTCompositeTypeSpecifier) node; return isDeclSpecifierEqual(trailDecl, decl) - && trailDecl.getKey() == decl.getKey(); + && trailDecl.getKey() == decl.getKey(); } else if (trailNode instanceof ICPPASTDeclSpecifier) { ICPPASTDeclSpecifier trailDecl = (ICPPASTDeclSpecifier) trailNode; ICPPASTDeclSpecifier decl = (ICPPASTDeclSpecifier) node; @@ -165,12 +166,13 @@ public class TrailNodeEqualityChecker implements EqualityChecker { && trailDecl.isConstexpr() == decl.isConstexpr() && trailDecl.isExplicit() == decl.isExplicit() && trailDecl.isFriend() == decl.isFriend() + && trailDecl.isThreadLocal() == decl.isThreadLocal() && trailDecl.isVirtual() == decl.isVirtual(); } else if (trailNode instanceof ICASTDeclSpecifier) { ICASTDeclSpecifier trailDecl = (ICASTDeclSpecifier) trailNode; ICASTDeclSpecifier decl = (ICASTDeclSpecifier) node; return isDeclSpecifierEqual(trailDecl, decl) - && trailDecl.isRestrict() == decl.isRestrict(); + && trailDecl.isRestrict() == decl.isRestrict(); } else if (trailNode instanceof IASTDeclSpecifier) { IASTDeclSpecifier trailDecl = (IASTDeclSpecifier) trailNode; IASTDeclSpecifier decl = (IASTDeclSpecifier) node; @@ -318,6 +320,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker { if (trailCppDecl.isConstexpr() != cppDecl.isConstexpr() || trailCppDecl.isExplicit() != cppDecl.isExplicit() || trailCppDecl.isFriend() != cppDecl.isFriend() + || trailCppDecl.isThreadLocal() != cppDecl.isThreadLocal() || trailCppDecl.isVirtual() != cppDecl.isVirtual()) { return false; }