1
/*******************************************************************************
2
* Copyright (c) 2005, 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
* John Camelon (IBM Rational Software) - Initial API and implementation
10
* Markus Schorn (Wind River Systems)
11
*******************************************************************************/
12
package org.eclipse.cdt.internal.core.dom.parser.c;
14
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
15
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
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.IASTTypeId;
19
import org.eclipse.cdt.core.dom.ast.IType;
20
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
21
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
24
* Cast expressions for c
26
public class CASTCastExpression extends ASTNode implements IASTCastExpression, IASTAmbiguityParent {
28
private IASTExpression operand;
29
private IASTTypeId typeId;
32
public CASTCastExpression() {
33
this.operator = op_cast;
36
public CASTCastExpression(IASTTypeId typeId, IASTExpression operand) {
42
public CASTCastExpression copy() {
43
return copy(CopyStyle.withoutLocations);
46
public CASTCastExpression copy(CopyStyle style) {
47
CASTCastExpression copy = new CASTCastExpression();
48
copy.setTypeId(typeId == null ? null : typeId.copy(style));
49
IASTExpression operand = getOperand();
50
copy.setOperand(operand == null ? null : operand.copy(style));
51
copy.setOffsetAndLength(this);
52
if (style == CopyStyle.withLocations) {
53
copy.setCopyLocation(this);
58
public int getOperator() {
62
public void setOperator(int value) {
64
this.operator = value;
67
public IASTExpression getOperand() {
71
public void setOperand(IASTExpression expression) {
74
if (expression != null) {
75
expression.setParent(this);
76
expression.setPropertyInParent(OPERAND);
80
public void setTypeId(IASTTypeId typeId) {
84
typeId.setParent(this);
85
typeId.setPropertyInParent(TYPE_ID);
89
public IASTTypeId getTypeId() {
94
public boolean accept( ASTVisitor action ){
95
if( action.shouldVisitExpressions ){
96
switch( action.visit( this ) ){
97
case ASTVisitor.PROCESS_ABORT : return false;
98
case ASTVisitor.PROCESS_SKIP : return true;
103
if( typeId != null ) if( !typeId.accept( action ) ) return false;
104
IASTExpression operand = getOperand();
105
if( operand != null ) if( !operand.accept( action ) ) return false;
107
if( action.shouldVisitExpressions ){
108
switch( action.leave( this ) ){
109
case ASTVisitor.PROCESS_ABORT : return false;
110
case ASTVisitor.PROCESS_SKIP : return true;
119
public void replace(IASTNode child, IASTNode other) {
120
if (child == operand) {
121
other.setPropertyInParent(child.getPropertyInParent());
122
other.setParent(child.getParent());
123
operand = (IASTExpression) other;
127
public IType getExpressionType() {
128
IASTTypeId id= getTypeId();
129
return CVisitor.createType(id.getAbstractDeclarator());
132
public boolean isLValue() {
136
public final ValueCategory getValueCategory() {
137
return ValueCategory.PRVALUE;