From ae8af8e02fcdf3bc41cf90483954d95183c8e415 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 17 Aug 2012 14:01:33 -0700 Subject: [PATCH] Bug 327300. Parsing support for noexcept operators and noexcept specifications in function declarators. Adjustments for CDT 8.1.x. --- .../.settings/.api_filters | 7 ++++++ .../cdt/core/dom/ast/IASTUnaryExpression.java | 1 - .../ast/cpp/ICPPASTFunctionDeclarator.java | 22 +++++-------------- .../parser/cpp/CPPASTFunctionDeclarator.java | 14 +++++++++++- .../dom/parser/cpp/GNUCPPSourceParser.java | 2 +- .../dom/parser/cpp/semantics/CPPVisitor.java | 3 ++- .../rewrite/astwriter/DeclaratorWriter.java | 3 ++- 7 files changed, 31 insertions(+), 21 deletions(-) diff --git a/core/org.eclipse.cdt.core/.settings/.api_filters b/core/org.eclipse.cdt.core/.settings/.api_filters index 00ccfe79000..667f53987ac 100644 --- a/core/org.eclipse.cdt.core/.settings/.api_filters +++ b/core/org.eclipse.cdt.core/.settings/.api_filters @@ -30,6 +30,13 @@ + + + + + + + diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java index 919ac7a9814..17088594624 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java @@ -119,7 +119,6 @@ public interface IASTUnaryExpression extends IASTExpression { /** * For c++, only: noexcept ( expression ) - * @since 5.5 */ public static final int op_noexcept = 17; 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 d9f1542c734..4a6c53e839f 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 @@ -15,8 +15,6 @@ package org.eclipse.cdt.core.dom.ast.cpp; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.Keywords; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; /** * C++ adds a few things to function declarators. @@ -31,18 +29,8 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato */ public static final IASTTypeId[] NO_EXCEPTION_SPECIFICATION = {}; - /** - * Represents a 'noexcept' specification without an expression. - * @since 5.5 - */ - public static final ICPPASTLiteralExpression NOEXCEPT_DEFAULT = - new CPPASTLiteralExpression(ICPPASTLiteralExpression.lk_true, Keywords.cTRUE); - public static final ASTNodeProperty EXCEPTION_TYPEID = new ASTNodeProperty( "ICPPASTFunctionDeclarator.EXCEPTION_TYPEID [IASTTypeId]"); //$NON-NLS-1$ - /** @since 5.5 */ - public static final ASTNodeProperty NOEXCEPT_EXPRESSION = new ASTNodeProperty( - "ICPPASTFunctionDeclarator.NOEXCEPT_EXPRESSION [ICPPASTExpression]"); //$NON-NLS-1$ /** @since 5.2 */ public static final ASTNodeProperty TRAILING_RETURN_TYPE = new ASTNodeProperty( "ICPPASTFunctionDeclarator.TRAILING_RETURN_TYPE [IASTTypeId]"); //$NON-NLS-1$ @@ -115,16 +103,18 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato public void setEmptyExceptionSpecification(); /** - * Returns the noexcept expression, {@link #NOEXCEPT_DEFAULT} if the noexcept specification - * does not contain an expression, or {@code null} the noexcept specification is not present. + * Returns the noexcept expression, {@link + * org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator#NOEXCEPT_DEFAULT} + * if the noexcept specification does not contain an expression, or {@code null} the noexcept + * specification is not present. * See C++11 5.4.1. - * @since 5.5 + * @noreference This method is not intended to be referenced by clients. */ public ICPPASTExpression getNoexceptExpression(); /** * Sets the noexcept expression. - * @since 5.5 + * @noreference This method is not intended to be referenced by clients. */ public void setNoexceptExpression(ICPPASTExpression expression); 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 649fdc88797..acdd8d9fede 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 @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -21,8 +22,10 @@ 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.ICPPASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope; +import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; @@ -32,7 +35,16 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; */ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPASTFunctionDeclarator, IASTAmbiguityParent { - private ICPPASTParameterDeclaration[] parameters; + /** + * Represents a 'noexcept' specification without an expression. + */ + public static final ICPPASTLiteralExpression NOEXCEPT_DEFAULT = + new CPPASTLiteralExpression(ICPPASTLiteralExpression.lk_true, Keywords.cTRUE); + + public static final ASTNodeProperty NOEXCEPT_EXPRESSION = new ASTNodeProperty( + "ICPPASTFunctionDeclarator.NOEXCEPT_EXPRESSION [ICPPASTExpression]"); //$NON-NLS-1$ + + private ICPPASTParameterDeclaration[] parameters; private IASTTypeId[] typeIds = NO_EXCEPTION_SPECIFICATION; private ICPPASTExpression noexceptExpression; private IASTTypeId trailingReturnType; 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 2c960038b66..93f1881c111 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 @@ -3964,7 +3964,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { expression = expression(); endOffset = consume(IToken.tRPAREN).getEndOffset(); // ) } else { - expression = ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT; + expression = CPPASTFunctionDeclarator.NOEXCEPT_DEFAULT; } fc.setNoexceptExpression((ICPPASTExpression) expression); } 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 330b4c9d173..a1e5188afc1 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 @@ -168,6 +168,7 @@ import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFieldReference; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionCallExpression; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit; @@ -1002,7 +1003,7 @@ public class CPPVisitor extends ASTQueries { } } else if (node instanceof IASTParameterDeclaration || - node.getPropertyInParent() == ICPPASTFunctionDeclarator.NOEXCEPT_EXPRESSION) { + node.getPropertyInParent() == CPPASTFunctionDeclarator.NOEXCEPT_EXPRESSION) { IASTNode parent = node.getParent(); if (parent instanceof ICPPASTFunctionDeclarator) { IScope result = scopeViaFunctionDtor((ICPPASTFunctionDeclarator) parent); 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 37ed8922ed2..c5e1c1c7640 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 @@ -32,6 +32,7 @@ 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.parser.cpp.CPPASTFunctionDeclarator; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; /** @@ -164,7 +165,7 @@ public class DeclaratorWriter extends NodeWriter { if (noexceptExpression != null) { scribe.printSpace(); scribe.print(Keywords.NOEXCEPT); - if (noexceptExpression != ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT) { + if (noexceptExpression != CPPASTFunctionDeclarator.NOEXCEPT_DEFAULT) { scribe.printSpace(); scribe.print('('); noexceptExpression.accept(visitor);