mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
Bug 84144 - [Parser2] GCC: labels as values
Add support for GNU goto label references. "http://gcc.gnu.org/onlinedocs/gcc-3.3.2/gcc/Labels-as-Values.html#Labels%20as%20Values GCC extensions to C allow taking the address of labels. These addresses can be used in a goto statement where any expression of type void * is allowed: foo: void* labelPtr = &&foo; goto *labelPtr;", comment from Andrew Niefer Add new classes and necessary changes in existing classes to support the above. Updated to not change API. Signed-off-by: Anders Dahlberg <anders.xb.dahlberg@ericsson.com> Change-Id: Ibb69ce7748f201c15bdf2da05348c157cdd5aaae Reviewed-on: https://git.eclipse.org/r/29574 Tested-by: Hudson CI Reviewed-by: Thomas Corbat <tcorbat@hsr.ch> Tested-by: Thomas Corbat <tcorbat@hsr.ch>
This commit is contained in:
parent
17d10e5823
commit
bf0ac98464
7 changed files with 84 additions and 65 deletions
|
@ -106,29 +106,30 @@ public interface IASTUnaryExpression extends IASTExpression {
|
|||
@Deprecated
|
||||
public static final int op_typeof = 14;
|
||||
|
||||
/**
|
||||
* For GCC parsers, only. {@code op_labelReference} is used for &&label type
|
||||
* expressions.
|
||||
*/
|
||||
public static final int op_labelReference = 15;
|
||||
|
||||
/**
|
||||
* For GCC parsers, only. {@code op_alignOf} is used for __alignOf( unaryExpression ) type
|
||||
* expressions.
|
||||
*/
|
||||
public static final int op_alignOf = 16;
|
||||
public static final int op_alignOf = 15;
|
||||
|
||||
/**
|
||||
* For C++, only: 'sizeof... ( parameterPack )'
|
||||
* @since 5.2
|
||||
*/
|
||||
public static final int op_sizeofParameterPack = 17;
|
||||
public static final int op_sizeofParameterPack = 16;
|
||||
|
||||
/**
|
||||
* For C++, only: noexcept ( expression )
|
||||
* @since 5.5
|
||||
*/
|
||||
public static final int op_noexcept = 18;
|
||||
public static final int op_noexcept = 17;
|
||||
|
||||
/**
|
||||
* For GCC parsers, only. {@code op_labelReference} is used for &&label type
|
||||
* expressions.
|
||||
* @since 5.8
|
||||
*/
|
||||
public static final int op_labelReference = 18;
|
||||
|
||||
/**
|
||||
* {@code op_last} is made available for subclasses.
|
||||
|
|
|
@ -121,8 +121,12 @@ public interface INodeFactory {
|
|||
|
||||
public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement);
|
||||
|
||||
public IASTStatement newGotoStatement(IASTName name);
|
||||
public IASTGotoStatement newGotoStatement(IASTName name);
|
||||
|
||||
/**
|
||||
* Note: Adding as separate function to avoid changing API.
|
||||
* @since 5.8
|
||||
*/
|
||||
public IASTStatement newGotoStatement(IASTExpression expression);
|
||||
|
||||
public IASTIdExpression newIdExpression(IASTName name);
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|||
* goto *labelPtr;
|
||||
* </code>
|
||||
*
|
||||
* @since 8.4
|
||||
* @since 5.8
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
|
@ -298,7 +299,7 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IASTStatement newGotoStatement(IASTName name) {
|
||||
public IASTGotoStatement newGotoStatement(IASTName name) {
|
||||
return new CASTGotoStatement(name);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,10 +24,10 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
|
|||
* void *labelPtr = &&foo;
|
||||
* goto *labelPtr; // this is the statement
|
||||
* </code>
|
||||
* @since 8.4
|
||||
*
|
||||
* @since 5.8
|
||||
*/
|
||||
public class GNUCASTGotoStatement extends ASTAttributeOwner
|
||||
implements IGNUASTGotoStatement {
|
||||
public class GNUCASTGotoStatement extends ASTAttributeOwner implements IGNUASTGotoStatement {
|
||||
private IASTExpression fExpression;
|
||||
|
||||
public GNUCASTGotoStatement() {
|
||||
|
@ -53,9 +53,12 @@ public class GNUCASTGotoStatement extends ASTAttributeOwner
|
|||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitExpressions) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
case ASTVisitor.PROCESS_ABORT:
|
||||
return false;
|
||||
case ASTVisitor.PROCESS_SKIP:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
|
||||
|
@ -430,7 +431,7 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IASTStatement newGotoStatement(IASTName name) {
|
||||
public IASTGotoStatement newGotoStatement(IASTName name) {
|
||||
return new CPPASTGotoStatement(name);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
|
|||
* goto *labelPtr; // this is the statement
|
||||
* </code>
|
||||
*
|
||||
* @since 8.4
|
||||
* @since 5.8
|
||||
*/
|
||||
public class GNUCPPASTGotoStatement extends ASTAttributeOwner implements IGNUASTGotoStatement {
|
||||
private IASTExpression expression;
|
||||
|
@ -44,7 +44,8 @@ public class GNUCPPASTGotoStatement extends ASTAttributeOwner implements IGNUAST
|
|||
|
||||
@Override
|
||||
public GNUCPPASTGotoStatement copy(CopyStyle style) {
|
||||
GNUCPPASTGotoStatement copy = new GNUCPPASTGotoStatement(expression == null ? null : expression.copy(style));
|
||||
GNUCPPASTGotoStatement copy = new GNUCPPASTGotoStatement(expression == null ? null
|
||||
: expression.copy(style));
|
||||
return copy(copy, style);
|
||||
}
|
||||
|
||||
|
@ -52,20 +53,28 @@ public class GNUCPPASTGotoStatement extends ASTAttributeOwner implements IGNUAST
|
|||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitStatements) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
default : break;
|
||||
case ASTVisitor.PROCESS_ABORT:
|
||||
return false;
|
||||
case ASTVisitor.PROCESS_SKIP:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!acceptByAttributeSpecifiers(action)) return false;
|
||||
if (expression != null && !expression.accept(action)) return false;
|
||||
if (!acceptByAttributeSpecifiers(action))
|
||||
return false;
|
||||
if (expression != null && !expression.accept(action))
|
||||
return false;
|
||||
|
||||
if (action.shouldVisitStatements) {
|
||||
switch (action.leave(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
default : break;
|
||||
case ASTVisitor.PROCESS_ABORT:
|
||||
return false;
|
||||
case ASTVisitor.PROCESS_SKIP:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Add table
Reference in a new issue