1
/*******************************************************************************
2
* Copyright (c) 2005, 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 Rational Software) - Initial API and implementation
10
* Markus Schorn (Wind River Systems)
11
* Yuan Zhang / Beth Tibbitts (IBM Research)
12
*******************************************************************************/
13
package org.eclipse.cdt.internal.core.dom.parser.c;
15
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
16
import org.eclipse.cdt.core.dom.ast.IASTExpression;
17
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
18
import org.eclipse.cdt.core.dom.ast.IASTNode;
19
import org.eclipse.cdt.core.dom.ast.IType;
20
import org.eclipse.cdt.core.parser.util.ArrayUtil;
21
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
22
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
25
* Expression list in C
27
public class CASTExpressionList extends ASTNode implements IASTExpressionList,
30
public CASTExpressionList copy() {
31
CASTExpressionList copy = new CASTExpressionList();
32
for(IASTExpression expr : getExpressions())
33
copy.addExpression(expr == null ? null : expr.copy());
34
copy.setOffsetAndLength(this);
38
public IASTExpression[] getExpressions() {
39
if (expressions == null)
40
return IASTExpression.EMPTY_EXPRESSION_ARRAY;
41
return (IASTExpression[]) ArrayUtil.trim( IASTExpression.class, expressions );
44
public void addExpression(IASTExpression expression) {
46
expressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, expressions, expression );
47
if(expression != null) {
48
expression.setParent(this);
49
expression.setPropertyInParent(NESTED_EXPRESSION);
53
private IASTExpression [] expressions = new IASTExpression[2];
56
public boolean accept(ASTVisitor action) {
57
if (action.shouldVisitExpressions) {
58
switch (action.visit(this)) {
59
case ASTVisitor.PROCESS_ABORT:
61
case ASTVisitor.PROCESS_SKIP:
68
IASTExpression[] exps = getExpressions();
69
for (int i = 0; i < exps.length; i++)
70
if (!exps[i].accept(action))
73
if (action.shouldVisitExpressions) {
74
switch (action.leave(this)) {
75
case ASTVisitor.PROCESS_ABORT:
77
case ASTVisitor.PROCESS_SKIP:
86
public void replace(IASTNode child, IASTNode other) {
87
if( expressions == null ) return;
88
for (int i = 0; i < expressions.length; ++i) {
89
if (child == expressions[i]) {
90
other.setPropertyInParent(child.getPropertyInParent());
91
other.setParent(child.getParent());
92
expressions[i] = (IASTExpression) other;
97
public IType getExpressionType() {
98
for (int i = expressions.length-1; i >= 0; i--) {
99
IASTExpression expr= expressions[i];
101
return expr.getExpressionType();