~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 * IBM - Initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.internal.core.dom.parser.cpp;
 
12
 
 
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;
 
22
 
 
23
/**
 
24
 * @author jcamelon
 
25
 */
 
26
public class CPPASTCompoundStatement extends ASTNode implements
 
27
        IASTCompoundStatement, IASTAmbiguityParent {
 
28
 
 
29
    private IASTStatement [] statements = new IASTStatement[2];
 
30
    private ICPPScope scope = null;
 
31
 
 
32
    
 
33
    public CPPASTCompoundStatement copy() {
 
34
                return copy(CopyStyle.withoutLocations);
 
35
        }
 
36
 
 
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);
 
44
                }
 
45
                return copy;
 
46
        }
 
47
 
 
48
    public IASTStatement[] getStatements() {
 
49
        if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY;
 
50
        return (IASTStatement[]) ArrayUtil.trim( IASTStatement.class, statements );
 
51
    }
 
52
 
 
53
    public void addStatement(IASTStatement statement) {
 
54
        assertNotFrozen();
 
55
        statements = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, statements, statement );
 
56
        if (statement != null) {
 
57
                        statement.setParent(this);
 
58
                        statement.setPropertyInParent(NESTED_STATEMENT);
 
59
                }
 
60
    }
 
61
 
 
62
    public IScope getScope() {
 
63
        if( scope == null )
 
64
                scope = new CPPBlockScope( this );
 
65
        return scope;
 
66
    }
 
67
 
 
68
    @Override
 
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;
 
74
                    default : break;
 
75
                }
 
76
                }
 
77
        IASTStatement [] s = getStatements();
 
78
        for ( int i = 0; i < s.length; i++ ) {
 
79
            if( !s[i].accept( action ) ) return false;
 
80
        }
 
81
        if( action.shouldVisitStatements ){
 
82
                switch( action.leave( this ) ){
 
83
                        case ASTVisitor.PROCESS_ABORT : return false;
 
84
                        case ASTVisitor.PROCESS_SKIP  : return true;
 
85
                        default : break;
 
86
                }
 
87
        }
 
88
        return true;
 
89
    }
 
90
    
 
91
    public void replace(IASTNode child, IASTNode other) {
 
92
        if( statements == null ) return;
 
93
        for( int i = 0; i < statements.length; ++i )
 
94
        {
 
95
            if( statements[i] == child )
 
96
            {
 
97
                other.setParent( statements[i].getParent() );
 
98
                other.setPropertyInParent( statements[i].getPropertyInParent() );
 
99
                statements[i] = (IASTStatement) other;
 
100
            }
 
101
        }
 
102
    }
 
103
}