Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f2a8209a161fd24975f9816a36dbfdde86a6821a (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
/*******************************************************************************
 * Copyright (c) 2007, 2009 QNX Software Systems 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:
 *    Bryan Wilkinson (QNX) - Initial API and implementation
 *    Markus Schorn (Wind River Systems)
 *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;

import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;

/**
 * Binding for a specialization of a parameter in the index.
 */
class PDOMCPPParameterSpecialization extends PDOMCPPSpecialization implements ICPPParameter {
	private static final int NEXT_PARAM = PDOMCPPSpecialization.RECORD_SIZE;
	@SuppressWarnings("hiding")
	private static final int RECORD_SIZE = NEXT_PARAM + Database.PTR_SIZE;

	private final IType fType;
	
	public PDOMCPPParameterSpecialization(PDOMLinkage linkage, long record, IType t) {
		super(linkage, record);
		fType= t;
	}
		
	public PDOMCPPParameterSpecialization(PDOMLinkage linkage, PDOMCPPFunctionSpecialization parent, ICPPParameter astParam,
			PDOMCPPParameter original, PDOMCPPParameterSpecialization next) throws CoreException {
		super(linkage, parent, (ICPPSpecialization) astParam, original);
		fType= null;  // this constructor is used for adding parameters to the database, only.
		
		Database db = getDB();
		db.putRecPtr(record + NEXT_PARAM, next == null ? 0 : next.getRecord());
	}

	@Override
	protected int getRecordSize() {
		return RECORD_SIZE;
	}

	@Override
	public int getNodeType() {
		return IIndexCPPBindingConstants.CPP_PARAMETER_SPECIALIZATION;
	}

	long getNextPtr() throws CoreException {
		long rec = getDB().getRecPtr(record + NEXT_PARAM);
		return rec;
	}
	
	public IType getType() {
		return fType;
	}
	
	@Override
	protected IPDOMBinding loadSpecializedBinding(long record) throws CoreException {
		if (record == 0)
			return null;
		IType type= null;
		IBinding parent = getParentBinding();
		if (parent instanceof ICPPSpecialization && parent instanceof ICPPFunction) {
			try {
				IParameter[] pars= ((ICPPFunction) parent).getParameters();
				int parPos= -1;
				for (parPos= 0; parPos<pars.length; parPos++) {
					IParameter par= pars[parPos];
					if (equals(par)) {
						break;
					}
				}
				if (parPos < pars.length) {
					parent= ((ICPPSpecialization) parent).getSpecializedBinding();
					if (parent instanceof ICPPFunction) {
						ICPPFunctionType ftype = ((ICPPFunction) parent).getType();
						if (ftype != null) {
							IType[] ptypes= ftype.getParameterTypes();
							if (parPos < ptypes.length) {
								type= ptypes[parPos];
							}
						}
					}
				}
			} catch (DOMException e) {
			}
		} 
		return new PDOMCPPParameter(getLinkage(), record, type);
	}

	private ICPPParameter getParameter(){
		return (ICPPParameter) getSpecializedBinding();
	}
	
	public boolean hasDefaultValue() {
		return getParameter().hasDefaultValue();
	}

	public boolean isParameterPack() {
		return getType() instanceof ICPPParameterPackType;
	}

	public boolean isAuto() throws DOMException {
		return getParameter().isAuto();
	}

	public boolean isRegister() throws DOMException {
		return getParameter().isRegister();
	}

	public boolean isExtern() throws DOMException {
		return false;
	}

	public boolean isExternC() {
		return false;
	}

	public boolean isStatic() throws DOMException {
		return false;
	}

	public boolean isMutable() throws DOMException {
		return false;
	}

	public IValue getInitialValue() {
		return null;
	}
}

Back to the top