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
* 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.IASTExpression;
15
import org.eclipse.cdt.core.dom.ast.IASTName;
16
import org.eclipse.cdt.core.dom.ast.IASTNode;
17
import org.eclipse.cdt.core.dom.ast.IBinding;
18
import org.eclipse.cdt.core.dom.ast.IType;
19
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
20
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
21
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
26
public class CPPASTTypenameExpression extends ASTNode implements
27
ICPPASTTypenameExpression, IASTAmbiguityParent {
29
private boolean isTemplate;
30
private IASTName name;
31
private IASTExpression init;
34
public CPPASTTypenameExpression() {
37
public CPPASTTypenameExpression(IASTName name, IASTExpression init) {
38
this(name, init, false);
41
public CPPASTTypenameExpression(IASTName name, IASTExpression init, boolean isTemplate) {
43
setInitialValue(init);
44
this.isTemplate = isTemplate;
47
public CPPASTTypenameExpression copy() {
48
CPPASTTypenameExpression copy = new CPPASTTypenameExpression();
49
copy.setName(name == null ? null : name.copy());
50
copy.setInitialValue(init == null ? null : init.copy());
51
copy.isTemplate = isTemplate;
52
copy.setOffsetAndLength(this);
57
public void setIsTemplate(boolean templateTokenConsumed) {
59
isTemplate = templateTokenConsumed;
62
public boolean isTemplate() {
66
public void setName(IASTName name) {
71
name.setPropertyInParent(TYPENAME);
75
public IASTName getName() {
79
public void setInitialValue(IASTExpression expressionList) {
81
init = expressionList;
82
if (expressionList != null) {
83
expressionList.setParent(this);
84
expressionList.setPropertyInParent(INITIAL_VALUE);
88
public IASTExpression getInitialValue() {
93
public boolean accept( ASTVisitor action ){
94
if( action.shouldVisitExpressions ){
95
switch( action.visit( this ) ){
96
case ASTVisitor.PROCESS_ABORT : return false;
97
case ASTVisitor.PROCESS_SKIP : return true;
102
if( name != null ) if( !name.accept( action ) ) return false;
103
if( init != null ) if( !init.accept( action ) ) return false;
105
if( action.shouldVisitExpressions ){
106
switch( action.leave( this ) ){
107
case ASTVisitor.PROCESS_ABORT : return false;
108
case ASTVisitor.PROCESS_SKIP : return true;
115
public int getRoleForName(IASTName n) {
121
public void replace(IASTNode child, IASTNode other) {
124
other.setPropertyInParent( child.getPropertyInParent() );
125
other.setParent( child.getParent() );
126
init = (IASTExpression) other;
131
public IType getExpressionType() {
132
IBinding binding = getName().resolvePreBinding();
133
if (binding instanceof IType) {
134
return (IType) binding;