Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 17a396faf7d388932c4ee86140dfa29eee74000c (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*******************************************************************************
 * Copyright (c) 2003, 2004 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:
 * IBM Rational Software - Initial API and implementation
 *******************************************************************************/
/*
 * Created on Nov 4, 2003
 */
package org.eclipse.cdt.internal.core.parser.pst;

import java.util.List;

import org.eclipse.cdt.core.parser.util.ObjectMap;

public class BasicSymbol extends ExtensibleSymbol implements ISymbol
{
	
	public BasicSymbol( ParserSymbolTable table, char[] name ){
		super( table );
		_name = name;
	}	
	
	public BasicSymbol( ParserSymbolTable table, char[] name, ITypeInfo.eType typeInfo )
	{
		super( table );
		_name = name;
		_typeInfo = TypeInfoProvider.newTypeInfo( typeInfo );
	}
		
	public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{
		if( !isTemplateMember() &&  !getContainingSymbol().isTemplateMember() ){
			return null;
		}
		ISymbol newSymbol = (ISymbol) clone();
		newSymbol.setTypeInfo( TemplateEngine.instantiateTypeInfo( newSymbol.getTypeInfo(), template, argMap ) );
		newSymbol.setInstantiatedSymbol( this );
		
		return newSymbol;	
	}
	
	public char[] getName() { return _name; }
	public void setName(char[] name) { _name = name; }


	public void setContainingSymbol( IContainerSymbol scope ){ 
		super.setContainingSymbol( scope );
		_depth = scope.getDepth() + 1; 
	}

	public void setType(ITypeInfo.eType t){
		getTypeInfo().setType( t );	 
	}

	public ITypeInfo.eType getType(){ 
		return getTypeInfo().getType(); 
	}

	public boolean isType( ITypeInfo.eType type ){
		return getTypeInfo().isType( type, ITypeInfo.t_undef ); 
	}

	public boolean isType( ITypeInfo.eType type, ITypeInfo.eType upperType ){
		return getTypeInfo().isType( type, upperType );
	}
	
	public ISymbol getTypeSymbol(){
		ISymbol symbol = getTypeInfo().getTypeSymbol();
		
		if( symbol != null && symbol.isForwardDeclaration() && symbol.getForwardSymbol() != null ){
			return symbol.getForwardSymbol();
		}
		
		return symbol;
	}

	public void setTypeSymbol( ISymbol type ){
		getTypeInfo().setTypeSymbol( type ); 
	}

	public ITypeInfo getTypeInfo(){
		return ( _typeInfo != null ) ? _typeInfo : (_typeInfo = new TypeInfo()); 
	}
	
	public void setTypeInfo( ITypeInfo info ) {
		_typeInfo = info;
	}
	
	public boolean isForwardDeclaration(){
		return _isForwardDeclaration;
	}
	
	public void setIsForwardDeclaration( boolean forward ){
		_isForwardDeclaration = forward;
	}
	public void setForwardSymbol( ISymbol forward ){
		_symbolDef = forward;  
	}
	public ISymbol getForwardSymbol(){
		return (_isForwardDeclaration || isType( ITypeInfo.t_namespace) ) ? _symbolDef : null;
	}
	/**
	 * returns 0 if same, non zero otherwise
	 */
	public int compareCVQualifiersTo( ISymbol symbol ){
		int size = symbol.getTypeInfo().hasPtrOperators() ? symbol.getTypeInfo().getPtrOperators().size() : 0;
		int size2 = getTypeInfo().hasPtrOperators() ? getTypeInfo().getPtrOperators().size() : 0;
			
		if( size != size2 ){
			return size2 - size;
		} else if( size == 0 ) 
			return 0; 
		else {
			ITypeInfo.PtrOp op1 = null, op2 = null;
			for( int i = 0; i > size; i++ ){
				op1 = (ITypeInfo.PtrOp)symbol.getTypeInfo().getPtrOperators().get(i);
				op2 = (ITypeInfo.PtrOp)getTypeInfo().getPtrOperators().get(i);
	
				if( op1.compareCVTo( op2 ) != 0 ){
					return -1;
				}
			}
		}
		
		return 0;
	}
	
	public List getPtrOperators(){
		return getTypeInfo().getPtrOperators();
	}
	public void addPtrOperator( ITypeInfo.PtrOp ptrOp ){
		getTypeInfo().addPtrOperator( ptrOp );
	}	
	public void preparePtrOperatros(int numPtrOps) {
		getTypeInfo().preparePtrOperators( numPtrOps );
	}		

	
	public int getDepth(){
		return _depth;
	}
	
	public boolean isTemplateMember(){
		return _isTemplateMember;
	}
	public void setIsTemplateMember( boolean isMember ){
		_isTemplateMember = isMember;
	}
	public boolean isTemplateInstance(){
		return ( _isTemplateInstance && _symbolDef != null );
	}
	public ISymbol getInstantiatedSymbol(){
		return _symbolDef;
	}
	public void setInstantiatedSymbol( ISymbol symbol ){
	    _isTemplateInstance = true;
		_symbolDef = symbol;
	}
	
	public boolean getIsInvisible(){
		return _isInvisible;
	}
	public void setIsInvisible( boolean invisible ){
		_isInvisible = invisible ;
	}
	
	private 	char[] 				_name;					//our name
	private		ITypeInfo			_typeInfo;				//our type info
	private		int 				_depth;					//how far down the scope stack we are
	
	private 	boolean				_isInvisible = false;	//used by friend declarations (11.4-9)
	private		boolean				_isTemplateMember = false;
	private		boolean				_isForwardDeclaration = false;
	private     boolean 			_isTemplateInstance = false;
	private		ISymbol				_symbolDef = null;		//used for forward declarations and template instantiations
	
	
	/* (non-Javadoc)
	 * @see java.lang.Object#clone()
	 */
	public Object clone() {
		
		BasicSymbol s = (BasicSymbol) super.clone();
		s._typeInfo = TypeInfoProvider.newTypeInfo( s._typeInfo );
		return s;
	}
}

Back to the top