Skip to main content
summaryrefslogtreecommitdiffstats
blob: bea59df46022b96e539571367d082d64d874b43f (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
/*******************************************************************************
 * Copyright (c) 2013, 2014 Nathan Ridge.
 * 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:
 *     Nathan Ridge - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;

import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.internal.core.dom.parser.DependentValue;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameterPackType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.cpp.InstantiationContext;
import org.eclipse.core.runtime.CoreException;

/**
 * Evaluation for a pack expansion expression.
 */
public class EvalPackExpansion extends CPPDependentEvaluation {
	private ICPPEvaluation fExpansionPattern;
	private IType fType;

	public EvalPackExpansion(ICPPEvaluation expansionPattern, IASTNode pointOfDefinition) {
		this(expansionPattern, findEnclosingTemplate(pointOfDefinition));
	}

	public EvalPackExpansion(ICPPEvaluation expansionPattern, IBinding templateDefinition) {
		super(templateDefinition);
		fExpansionPattern = expansionPattern;
	}

	public ICPPEvaluation getExpansionPattern() {
		return fExpansionPattern;
	}

	@Override
	public boolean isInitializerList() {
		return fExpansionPattern.isInitializerList();
	}

	@Override
	public boolean isFunctionSet() {
		return fExpansionPattern.isFunctionSet();
	}

	@Override
	public boolean isTypeDependent() {
		return fExpansionPattern.isTypeDependent();
	}

	@Override
	public boolean isValueDependent() {
		return fExpansionPattern.isValueDependent();
	}

	@Override
	public boolean isConstantExpression() {
		return false;
	}

	@Override
	public IType getType() {
		if (fType == null) {
			IType type = fExpansionPattern.getType();
			if (type == null) {
				fType= ProblemType.UNKNOWN_FOR_EXPRESSION;
			} else {
				fType= new CPPParameterPackType(type);
			}
		}
		return fType;
	}

	@Override
	public IValue getValue() {
		return DependentValue.create(fExpansionPattern);
	}

	@Override
	public ValueCategory getValueCategory() {
		return ValueCategory.PRVALUE;
	}

	@Override
	public ICPPEvaluation instantiate(InstantiationContext context, int maxDepth) {
		ICPPEvaluation expansionPattern = fExpansionPattern.instantiate(context, maxDepth);
		if (expansionPattern == fExpansionPattern)
			return this;
		return new EvalPackExpansion(expansionPattern, getTemplateDefinition());
	}

	@Override
	public ICPPEvaluation computeForFunctionCall(ActivationRecord record, ConstexprEvaluationContext context) {
		ICPPEvaluation expansionPattern = fExpansionPattern.computeForFunctionCall(record, context.recordStep());
		if (expansionPattern == fExpansionPattern) {
			return this;
		}

		EvalPackExpansion evalParamPack = new EvalPackExpansion(expansionPattern, getTemplateDefinition());
		return evalParamPack;
	}

	@Override
	public int determinePackSize(ICPPTemplateParameterMap tpMap) {
		return CPPTemplates.PACK_SIZE_NOT_FOUND;
	}

	@Override
	public boolean referencesTemplateParameter() {
		return fExpansionPattern.referencesTemplateParameter();
	}

	@Override
	public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException {
		buffer.putShort(ITypeMarshalBuffer.EVAL_PACK_EXPANSION);
		buffer.marshalEvaluation(fExpansionPattern, includeValue);
		marshalTemplateDefinition(buffer);
	}

	public static ICPPEvaluation unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException {
		ICPPEvaluation expansionPattern = buffer.unmarshalEvaluation();
		IBinding templateDefinition = buffer.unmarshalBinding();
		return new EvalPackExpansion(expansionPattern, templateDefinition);
	}
}

Back to the top