Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 06bbcb610f05cf0d7569a83c3829f5dd42fd0c75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*******************************************************************************
 * Copyright (c) 2005, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Devin Steffler (IBM) - Initial API and implementation
 *    Emanuel Graf IFS - Fix for #198259
 *    Markus Schorn (Wind River Systems)
 *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;

import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;

/**
 * Implementation of conversion function ids
 */
public class CPPASTConversionName extends CPPASTNameBase implements ICPPASTConversionName {
	private IASTTypeId typeId = null;
	private char[] fName;
	
	public CPPASTConversionName() {
	}
	
	public CPPASTConversionName(IASTTypeId typeId) {
		setTypeId(typeId);
	}
	
	@Override
	public CPPASTConversionName copy() {
		return copy(CopyStyle.withoutLocations);
	}
	
	@Override
	public CPPASTConversionName copy(CopyStyle style) {
		CPPASTConversionName copy = new CPPASTConversionName();
		copy.setTypeId(typeId == null ? null : typeId.copy(style));
		copy.setOffsetAndLength(this);
		if (style == CopyStyle.withLocations) {
			copy.setCopyLocation(this);
		}
		return copy;
	}

	@Override
	public IASTTypeId getTypeId() {
		return typeId;
	}

	@Override
	public void setTypeId(IASTTypeId typeId) {
        assertNotFrozen();
		this.typeId=typeId;
		if (typeId != null) {
			typeId.setParent(this);
			typeId.setPropertyInParent(TYPE_ID);
		}
	}
	
	@Override
	public boolean accept(ASTVisitor action) {
		if (action.shouldVisitNames) {
			switch (action.visit(this)) {
			case ASTVisitor.PROCESS_ABORT:
				return false;
			case ASTVisitor.PROCESS_SKIP:
				return true;
			default:
				break;
			}
		}		

		if(typeId != null )if(! typeId.accept( action )) return false;

		if (action.shouldVisitNames) {
			switch (action.leave(this)) {
			case ASTVisitor.PROCESS_ABORT:
				return false;
			case ASTVisitor.PROCESS_SKIP:
				return true;
			default:
				break;
			}
		}
		return true;
	}

	@Override
	protected IBinding createIntermediateBinding() {
		return CPPVisitor.createBinding(this);
	}

	@Override
	public char[] toCharArray() {
		if (fName == null) {
			IType t= null;
			if (typeId != null) {
				t= CPPVisitor.createType(typeId);
			}
			fName= createName(t, typeId);
		}
		return fName;
	}

	public static char[] createName(IType t, IASTNode typeId) {
		StringBuilder buf= new StringBuilder();
		buf.append(Keywords.cOPERATOR);
		buf.append(' ');
		if (t != null) {
			ASTTypeUtil.appendType(t, true, buf);
		} else {
			buf.append(typeId.getRawSignature());
			WHITESPACE_SEQ.matcher(buf).replaceAll(" "); //$NON-NLS-1$
		}
		final int len= buf.length();
		char[] name= new char[len];
		buf.getChars(0, len, name, 0);
		return name;
	}

	@Override
	public char[] getSimpleID() {
		return toCharArray();
	}
	
	@Override
	public char[] getLookupKey() {
		return Keywords.cOPERATOR;
	}
}

Back to the top