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
|
/*******************************************************************************
* Copyright (c) 2008, 2012 Wind River Systems, Inc. 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:
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
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.ICPPParameterPackType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalParameterPack;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId;
import org.eclipse.core.runtime.Assert;
/**
* Implementation of non-type template argument, used by AST and index.
*/
public class CPPTemplateNonTypeArgument implements ICPPTemplateArgument {
private final ICPPEvaluation fEvaluation;
public CPPTemplateNonTypeArgument(ICPPEvaluation evaluation, IASTNode point) {
Assert.isNotNull(evaluation);
if (evaluation instanceof EvalFixed || point == null ||
evaluation.isTypeDependent() || evaluation.isValueDependent()) {
fEvaluation= evaluation;
} else {
IValue value = evaluation.getValue(point);
// Avoid nesting EvalFixed's as nesting causes the signature to be different.
if (value.getEvaluation() instanceof EvalFixed) {
fEvaluation = value.getEvaluation();
} else {
fEvaluation= new EvalFixed(evaluation.getTypeOrFunctionSet(point),
evaluation.getValueCategory(point), value);
}
}
}
public CPPTemplateNonTypeArgument(IValue value, IType type) {
fEvaluation = new EvalFixed(type, PRVALUE, value);
}
@Override
public boolean isTypeValue() {
return false;
}
@Override
public IType getOriginalTypeValue() {
return null;
}
@Override
public boolean isNonTypeValue() {
return true;
}
@Override
public IType getTypeValue() {
return null;
}
@Override
public ICPPEvaluation getNonTypeEvaluation() {
return fEvaluation;
}
@Override
public IValue getNonTypeValue() {
return fEvaluation.getValue(null);
}
@Override
public IType getTypeOfNonTypeValue() {
return fEvaluation.getTypeOrFunctionSet(null);
}
@Override
public boolean isPackExpansion() {
return fEvaluation.getTypeOrFunctionSet(null) instanceof ICPPParameterPackType;
}
@Override
public ICPPTemplateArgument getExpansionPattern() {
IType type = fEvaluation.getTypeOrFunctionSet(null);
if (type instanceof ICPPParameterPackType) {
IType t= ((ICPPParameterPackType) type).getType();
if (t != null) {
ICPPEvaluation evaluation;
if (fEvaluation instanceof EvalParameterPack) {
evaluation = ((EvalParameterPack) fEvaluation).getExpansionPattern();
} else {
evaluation = new EvalTypeId(t, fEvaluation.getTemplateDefinition(), fEvaluation);
}
return new CPPTemplateNonTypeArgument(evaluation, null);
}
}
return null;
}
@Override
public boolean isSameValue(ICPPTemplateArgument arg) {
return getNonTypeValue().equals(arg.getNonTypeValue());
}
@Override
public String toString() {
return getNonTypeValue().toString();
}
}
|