MCPcopy Create free account
hub / github.com/KDE/kdevelop / resolveVariables

Method resolveVariables

plugins/qmakemanager/qmakefilevisitor.cpp:164–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164QStringList QMakeFileVisitor::resolveVariables(const QString& var) const
165{
166 VariableReferenceParser parser;
167 parser.setContent(var);
168 if (!parser.parse()) {
169 qCWarning(KDEV_QMAKE) << "Couldn't parse" << var << "to replace variables in it";
170 return QStringList() << var;
171 }
172 const auto variableReferences = parser.variableReferences();
173 if (variableReferences.isEmpty()) {
174 return QStringList() << var;
175 }
176
177 /// TODO: multiple vars in one place will make the offsets go bonkers
178 QString value = var;
179 for (const auto& variable : variableReferences) {
180 const auto vi = parser.variableInfo(variable);
181 QString varValue;
182
183 switch (vi.type) {
184 case VariableInfo::QMakeVariable:
185 if (int arg = functionArgument(variable)) {
186 if (arg > 0 && arg <= m_arguments.size()) {
187 varValue = m_arguments.at(arg - 1);
188 } else {
189 qCWarning(KDEV_QMAKE) << "undefined macro argument:" << variable;
190 }
191 } else {
192 varValue = resolveVariable(variable, vi.type).join(QLatin1Char(' '));
193 }
194 break;
195 case VariableInfo::ShellVariableResolveQMake:
196 case VariableInfo::ShellVariableResolveMake:
197 /// TODO: make vs qmake time
198 varValue = QProcessEnvironment::systemEnvironment().value(variable);
199 break;
200 case VariableInfo::QtConfigVariable:
201 varValue = resolveVariable(variable, vi.type).join(QLatin1Char(' '));
202 break;
203 case VariableInfo::FunctionCall: {
204 QStringList arguments;
205 arguments.reserve(vi.positions.size());
206 for (const auto& pos : vi.positions) {
207 int start = pos.start + 3 + variable.length();
208 QString args = value.mid(start, pos.end - start);
209 varValue = resolveVariables(args).join(QLatin1Char(' '));
210 arguments << varValue;
211 }
212 varValue = evaluateMacro(variable, arguments).join(QLatin1Char(' '));
213 break;
214 }
215 case VariableInfo::Invalid:
216 qCWarning(KDEV_QMAKE) << "invalid qmake variable:" << variable;
217 continue;
218 }
219
220 for (const auto& pos : vi.positions) {
221 value.replace(pos.start, pos.end - pos.start + 1, varValue);

Callers

nothing calls this directly

Calls 15

QStringListClass · 0.85
functionArgumentFunction · 0.85
variableReferencesMethod · 0.80
variableInfoMethod · 0.80
joinMethod · 0.80
midMethod · 0.80
setContentMethod · 0.45
parseMethod · 0.45
isEmptyMethod · 0.45
sizeMethod · 0.45
atMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected