blob: 29f4703398bad7f9ec1bf763a62f991094d784c8 (
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
|
/*******************************************************************************
* Copyright (c) 2005, 2010 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:
* Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* Binding for a non-type template parameter.
*/
public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements
ICPPTemplateNonTypeParameter {
private IType type = null;
public CPPTemplateNonTypeParameter(IASTName name) {
super(name);
}
@Override
public IASTExpression getDefault() {
IASTInitializerClause def= getDefaultClause();
if (def instanceof IASTExpression) {
return (IASTExpression) def;
}
return null;
}
public IASTInitializerClause getDefaultClause() {
IASTName[] nds = getDeclarations();
if (nds == null || nds.length == 0)
return null;
for (IASTName name : nds) {
if (name != null) {
IASTNode parent = name.getParent();
assert parent instanceof IASTDeclarator;
if (parent instanceof IASTDeclarator) {
IASTDeclarator dtor = ASTQueries.findOutermostDeclarator((IASTDeclarator) parent);
IASTInitializer initializer = dtor.getInitializer();
if (initializer instanceof IASTEqualsInitializer) {
return ((IASTEqualsInitializer) initializer).getInitializerClause();
}
}
}
}
return null;
}
@Override
public ICPPTemplateArgument getDefaultValue() {
IASTInitializerClause dc= getDefault();
IASTExpression d= null;
if (dc instanceof IASTExpression) {
d= (IASTExpression) dc;
} else if (dc instanceof ICPPASTInitializerList) {
ICPPASTInitializerList list= (ICPPASTInitializerList) dc;
switch(list.getSize()) {
case 0:
return new CPPTemplateArgument(Value.create(0), getType());
case 1:
dc= list.getClauses()[0];
if (dc instanceof IASTExpression) {
d= (IASTExpression) dc;
}
}
}
if (d == null)
return null;
IValue val= Value.create(d, Value.MAX_RECURSION_DEPTH);
IType t= getType();
return new CPPTemplateArgument(val, t);
}
@Override
public IType getType() {
if (type == null) {
IASTNode parent= getPrimaryDeclaration().getParent();
while (parent != null) {
if (parent instanceof ICPPASTParameterDeclaration) {
type= CPPVisitor.createType((ICPPASTParameterDeclaration) parent, true);
break;
}
parent= parent.getParent();
}
}
return type;
}
@Override
public boolean isParameterPack() {
return getType() instanceof ICPPParameterPackType;
}
@Override
public boolean isStatic() {
return false;
}
@Override
public boolean isExtern() {
return false;
}
@Override
public boolean isAuto() {
return false;
}
@Override
public boolean isRegister() {
return false;
}
@Override
public IValue getInitialValue() {
return null;
}
@Override
public boolean isExternC() {
return false;
}
@Override
public boolean isMutable() {
return false;
}
}
|