1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 327300. Parsing support for noexcept operators and noexcept

specifications in function declarators. Adjustments for CDT 8.1.x.
This commit is contained in:
Sergey Prigogin 2012-08-17 14:01:33 -07:00
parent d89b672a97
commit ae8af8e02f
7 changed files with 31 additions and 21 deletions

View file

@ -30,6 +30,13 @@
</message_arguments> </message_arguments>
</filter> </filter>
</resource> </resource>
<resource path="parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java" type="org.eclipse.cdt.core.dom.ast.IASTUnaryExpression">
<filter id="1211105284">
<message_arguments>
<message_argument value="op_noexcept"/>
</message_arguments>
</filter>
</resource>
<resource path="parser/org/eclipse/cdt/core/dom/ast/IScope.java" type="org.eclipse.cdt.core.dom.ast.IScope$ScopeLookupData"> <resource path="parser/org/eclipse/cdt/core/dom/ast/IScope.java" type="org.eclipse.cdt.core.dom.ast.IScope$ScopeLookupData">
<filter id="1211105284"> <filter id="1211105284">
<message_arguments> <message_arguments>

View file

@ -119,7 +119,6 @@ public interface IASTUnaryExpression extends IASTExpression {
/** /**
* For c++, only: noexcept ( expression ) * For c++, only: noexcept ( expression )
* @since 5.5
*/ */
public static final int op_noexcept = 17; public static final int op_noexcept = 17;

View file

@ -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.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; 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. * C++ adds a few things to function declarators.
@ -31,18 +29,8 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato
*/ */
public static final IASTTypeId[] NO_EXCEPTION_SPECIFICATION = {}; 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( public static final ASTNodeProperty EXCEPTION_TYPEID = new ASTNodeProperty(
"ICPPASTFunctionDeclarator.EXCEPTION_TYPEID [IASTTypeId]"); //$NON-NLS-1$ "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 */ /** @since 5.2 */
public static final ASTNodeProperty TRAILING_RETURN_TYPE = new ASTNodeProperty( public static final ASTNodeProperty TRAILING_RETURN_TYPE = new ASTNodeProperty(
"ICPPASTFunctionDeclarator.TRAILING_RETURN_TYPE [IASTTypeId]"); //$NON-NLS-1$ "ICPPASTFunctionDeclarator.TRAILING_RETURN_TYPE [IASTTypeId]"); //$NON-NLS-1$
@ -115,16 +103,18 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato
public void setEmptyExceptionSpecification(); public void setEmptyExceptionSpecification();
/** /**
* Returns the noexcept expression, {@link #NOEXCEPT_DEFAULT} if the noexcept specification * Returns the noexcept expression, {@link
* does not contain an expression, or {@code null} the noexcept specification is not present. * 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. * See C++11 5.4.1.
* @since 5.5 * @noreference This method is not intended to be referenced by clients.
*/ */
public ICPPASTExpression getNoexceptExpression(); public ICPPASTExpression getNoexceptExpression();
/** /**
* Sets the noexcept expression. * Sets the noexcept expression.
* @since 5.5 * @noreference This method is not intended to be referenced by clients.
*/ */
public void setNoexceptExpression(ICPPASTExpression expression); public void setNoexceptExpression(ICPPASTExpression expression);

View file

@ -12,6 +12,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; 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.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTName; 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.ICPPASTExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; 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.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.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope; 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.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; 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, public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPASTFunctionDeclarator,
IASTAmbiguityParent { 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 IASTTypeId[] typeIds = NO_EXCEPTION_SPECIFICATION;
private ICPPASTExpression noexceptExpression; private ICPPASTExpression noexceptExpression;
private IASTTypeId trailingReturnType; private IASTTypeId trailingReturnType;

View file

@ -3964,7 +3964,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
expression = expression(); expression = expression();
endOffset = consume(IToken.tRPAREN).getEndOffset(); // ) endOffset = consume(IToken.tRPAREN).getEndOffset(); // )
} else { } else {
expression = ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT; expression = CPPASTFunctionDeclarator.NOEXCEPT_DEFAULT;
} }
fc.setNoexceptExpression((ICPPASTExpression) expression); fc.setNoexceptExpression((ICPPASTExpression) expression);
} }

View file

@ -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.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFieldReference; 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.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.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
@ -1002,7 +1003,7 @@ public class CPPVisitor extends ASTQueries {
} }
} else if (node instanceof IASTParameterDeclaration || } else if (node instanceof IASTParameterDeclaration ||
node.getPropertyInParent() == ICPPASTFunctionDeclarator.NOEXCEPT_EXPRESSION) { node.getPropertyInParent() == CPPASTFunctionDeclarator.NOEXCEPT_EXPRESSION) {
IASTNode parent = node.getParent(); IASTNode parent = node.getParent();
if (parent instanceof ICPPASTFunctionDeclarator) { if (parent instanceof ICPPASTFunctionDeclarator) {
IScope result = scopeViaFunctionDtor((ICPPASTFunctionDeclarator) parent); IScope result = scopeViaFunctionDtor((ICPPASTFunctionDeclarator) parent);

View file

@ -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.cpp.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.parser.Keywords; 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; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
/** /**
@ -164,7 +165,7 @@ public class DeclaratorWriter extends NodeWriter {
if (noexceptExpression != null) { if (noexceptExpression != null) {
scribe.printSpace(); scribe.printSpace();
scribe.print(Keywords.NOEXCEPT); scribe.print(Keywords.NOEXCEPT);
if (noexceptExpression != ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT) { if (noexceptExpression != CPPASTFunctionDeclarator.NOEXCEPT_DEFAULT) {
scribe.printSpace(); scribe.printSpace();
scribe.print('('); scribe.print('(');
noexceptExpression.accept(visitor); noexceptExpression.accept(visitor);