1
/*******************************************************************************
2
* Copyright (c) 2004, 2011 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
* IBM - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.internal.core.dom.parser.cpp;
13
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
14
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
15
import org.eclipse.cdt.core.dom.ast.IASTNode;
16
import org.eclipse.cdt.core.dom.ast.IASTStatement;
17
import org.eclipse.cdt.core.dom.ast.IScope;
18
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
19
import org.eclipse.cdt.core.parser.util.ArrayUtil;
20
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
21
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
26
public class CPPASTCompoundStatement extends ASTNode implements
27
IASTCompoundStatement, IASTAmbiguityParent {
29
private IASTStatement [] statements = new IASTStatement[2];
30
private ICPPScope scope = null;
33
public CPPASTCompoundStatement copy() {
34
return copy(CopyStyle.withoutLocations);
37
public CPPASTCompoundStatement copy(CopyStyle style) {
38
CPPASTCompoundStatement copy = new CPPASTCompoundStatement();
39
for (IASTStatement statement : getStatements())
40
copy.addStatement(statement == null ? null : statement.copy(style));
41
copy.setOffsetAndLength(this);
42
if (style == CopyStyle.withLocations) {
43
copy.setCopyLocation(this);
48
public IASTStatement[] getStatements() {
49
if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY;
50
return (IASTStatement[]) ArrayUtil.trim( IASTStatement.class, statements );
53
public void addStatement(IASTStatement statement) {
55
statements = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, statements, statement );
56
if (statement != null) {
57
statement.setParent(this);
58
statement.setPropertyInParent(NESTED_STATEMENT);
62
public IScope getScope() {
64
scope = new CPPBlockScope( this );
69
public boolean accept( ASTVisitor action ){
70
if( action.shouldVisitStatements ){
71
switch( action.visit( this ) ){
72
case ASTVisitor.PROCESS_ABORT : return false;
73
case ASTVisitor.PROCESS_SKIP : return true;
77
IASTStatement [] s = getStatements();
78
for ( int i = 0; i < s.length; i++ ) {
79
if( !s[i].accept( action ) ) return false;
81
if( action.shouldVisitStatements ){
82
switch( action.leave( this ) ){
83
case ASTVisitor.PROCESS_ABORT : return false;
84
case ASTVisitor.PROCESS_SKIP : return true;
91
public void replace(IASTNode child, IASTNode other) {
92
if( statements == null ) return;
93
for( int i = 0; i < statements.length; ++i )
95
if( statements[i] == child )
97
other.setParent( statements[i].getParent() );
98
other.setPropertyInParent( statements[i].getPropertyInParent() );
99
statements[i] = (IASTStatement) other;