1
/*******************************************************************************
2
* Copyright (c) 2004, 2009 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* John Camelon (IBM) - Initial API and implementation
10
* Markus Schorn (Wind River Systems)
11
*******************************************************************************/
12
package org.eclipse.cdt.internal.core.dom.parser.cpp;
14
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
15
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
16
import org.eclipse.cdt.core.dom.ast.IASTExpression;
17
import org.eclipse.cdt.core.dom.ast.IASTNode;
18
import org.eclipse.cdt.core.dom.ast.IASTStatement;
19
import org.eclipse.cdt.core.dom.ast.IScope;
20
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSwitchStatement;
21
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
22
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
25
* Switch statement in c++.
27
public class CPPASTSwitchStatement extends ASTNode implements
28
ICPPASTSwitchStatement, IASTAmbiguityParent {
31
private IASTExpression controllerExpression;
32
private IASTDeclaration controllerDeclaration;
33
private IASTStatement body;
36
public CPPASTSwitchStatement() {
39
public CPPASTSwitchStatement(IASTDeclaration controller, IASTStatement body) {
40
setControllerDeclaration(controller);
44
public CPPASTSwitchStatement(IASTExpression controller, IASTStatement body) {
45
setControllerExpression(controller);
49
public CPPASTSwitchStatement copy() {
50
CPPASTSwitchStatement copy = new CPPASTSwitchStatement();
51
copy.setControllerDeclaration(controllerDeclaration == null ? null : controllerDeclaration.copy());
52
copy.setControllerExpression(controllerExpression == null ? null : controllerExpression.copy());
53
copy.setBody(body == null ? null : body.copy());
54
copy.setOffsetAndLength(this);
58
public IASTExpression getControllerExpression() {
59
return controllerExpression;
62
public void setControllerExpression(IASTExpression controller) {
64
this.controllerExpression = controller;
65
if (controller != null) {
66
controller.setParent(this);
67
controller.setPropertyInParent(CONTROLLER_EXP);
68
controllerDeclaration= null;
72
public IASTStatement getBody() {
76
public void setBody(IASTStatement body) {
81
body.setPropertyInParent(BODY);
86
public boolean accept( ASTVisitor action ){
87
if( action.shouldVisitStatements ){
88
switch( action.visit( this ) ){
89
case ASTVisitor.PROCESS_ABORT : return false;
90
case ASTVisitor.PROCESS_SKIP : return true;
94
if( controllerExpression != null ) if( !controllerExpression.accept( action ) ) return false;
95
if( controllerDeclaration != null ) if( !controllerDeclaration.accept( action ) ) return false;
96
if( body != null ) if( !body.accept( action ) ) return false;
98
if( action.shouldVisitStatements ){
99
switch( action.leave( this ) ){
100
case ASTVisitor.PROCESS_ABORT : return false;
101
case ASTVisitor.PROCESS_SKIP : return true;
108
public void replace(IASTNode child, IASTNode other) {
110
other.setPropertyInParent(child.getPropertyInParent());
111
other.setParent(child.getParent());
112
body = (IASTStatement) other;
113
} else if (controllerDeclaration == child || controllerExpression == child) {
114
if (other instanceof IASTExpression) {
115
setControllerExpression((IASTExpression) other);
116
} else if (other instanceof IASTDeclaration) {
117
setControllerDeclaration((IASTDeclaration) other);
122
public IASTDeclaration getControllerDeclaration() {
123
return controllerDeclaration;
126
public void setControllerDeclaration(IASTDeclaration d) {
128
controllerDeclaration = d;
131
d.setPropertyInParent(CONTROLLER_DECLARATION);
132
controllerExpression= null;
136
public IScope getScope() {
138
scope = new CPPBlockScope( this );