本文整理汇总了C++中AST::asSwitchStatement方法的典型用法代码示例。如果您正苦于以下问题:C++ AST::asSwitchStatement方法的具体用法?C++ AST::asSwitchStatement怎么用?C++ AST::asSwitchStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AST
的用法示例。
在下文中一共展示了AST::asSwitchStatement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: noResult
QList<CppQuickFixOperation::Ptr> CompleteSwitchCaseStatement::match(
const QSharedPointer<const CppEditor::Internal::CppQuickFixAssistInterface> &interface)
{
const QList<AST *> &path = interface->path();
if (path.isEmpty())
return noResult(); // nothing to do
// look for switch statement
for (int depth = path.size() - 1; depth >= 0; --depth) {
AST *ast = path.at(depth);
SwitchStatementAST *switchStatement = ast->asSwitchStatement();
if (switchStatement) {
if (!interface->isCursorOn(switchStatement->switch_token) || !switchStatement->statement)
return noResult();
CompoundStatementAST *compoundStatement = switchStatement->statement->asCompoundStatement();
if (!compoundStatement) // we ignore pathologic case "switch (t) case A: ;"
return noResult();
// look if the condition's type is an enum
if (Enum *e = conditionEnum(interface, switchStatement)) {
// check the possible enum values
QStringList values;
Overview prettyPrint;
for (unsigned i = 0; i < e->memberCount(); ++i) {
if (Declaration *decl = e->memberAt(i)->asDeclaration()) {
values << prettyPrint(LookupContext::fullyQualifiedName(decl));
}
}
// Get the used values
Block *block = switchStatement->symbol;
CaseStatementCollector caseValues(interface->semanticInfo().doc, interface->snapshot(),
interface->semanticInfo().doc->scopeAt(block->line(), block->column()));
QStringList usedValues = caseValues(switchStatement);
// save the values that would be added
foreach (const QString &usedValue, usedValues)
values.removeAll(usedValue);
if (values.isEmpty())
return noResult();
else
return singleResult(new Operation(interface, depth, compoundStatement, values));
}
return noResult();
}
}