当前位置: 首页>>代码示例>>C++>>正文


C++ AST::asStringLiteral方法代码示例

本文整理汇总了C++中AST::asStringLiteral方法的典型用法代码示例。如果您正苦于以下问题:C++ AST::asStringLiteral方法的具体用法?C++ AST::asStringLiteral怎么用?C++ AST::asStringLiteral使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AST的用法示例。


在下文中一共展示了AST::asStringLiteral方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fineTuneASTNodePositions

void CppSelectionChanger::fineTuneASTNodePositions(ASTNodePositions &positions) const
{
    AST *ast = positions.ast;

    if (ast->asCompoundStatement()) {
        // Allow first selecting the contents of the scope, without selecting the braces, and
        // afterwards select the contents together with  braces.
        if (currentASTStep() == 1) {
            if (debug)
                qDebug() << "Selecting inner contents of compound statement.";

            unsigned firstInnerTokenIndex = positions.firstTokenIndex + 1;
            unsigned lastInnerTokenIndex = positions.lastTokenIndex - 2;
            Token firstInnerToken = m_unit->tokenAt(firstInnerTokenIndex);
            Token lastInnerToken = m_unit->tokenAt(lastInnerTokenIndex);
            if (debug) {
                qDebug() << "LastInnerToken:" << lastInnerToken.spell();
                qDebug() << "FirstInnerToken:" << firstInnerToken.spell();
            }

            // Check if compound statement is empty, then select just the blank space inside it.
            int newPosStart, newPosEnd;
            if (positions.secondToLastTokenIndex - positions.firstTokenIndex <= 1) {
                // TODO: If the empty space has a new tab character, or spaces, and the document is
                // not saved, the last semantic info is not updated, and the selection is not
                // properly computed. Figure out how to work around this.
                newPosStart = getTokenEndCursorPosition(positions.firstTokenIndex, m_workingCursor);
                newPosEnd = getTokenStartCursorPosition(positions.secondToLastTokenIndex,
                                                        m_workingCursor);
                if (debug)
                    qDebug() << "Selecting inner contents of compound statement which is empty.";
            } else {
                // Select the inner contents of the scope, without the braces.
                newPosStart = getTokenStartCursorPosition(firstInnerTokenIndex, m_workingCursor);
                newPosEnd = getTokenEndCursorPosition(lastInnerTokenIndex, m_workingCursor);
            }

            if (debug) {
                qDebug() << "New" << newPosStart << newPosEnd
                         << "Old" << m_workingCursor.anchor() << m_workingCursor.position();
            }

            positions.astPosStart = newPosStart;
            positions.astPosEnd = newPosEnd;
        }
        // Next time, we select the braces as well. Reverse for shrinking.
        // The positions already have the correct selection, so no need to set them.
    } else if (CallAST *callAST = ast->asCall()) {
        unsigned firstParenTokenIndex = callAST->lparen_token;
        unsigned lastParenTokenIndex = callAST->rparen_token;
        Token firstParenToken = m_unit->tokenAt(firstParenTokenIndex);
        Token lastParenToken = m_unit->tokenAt(lastParenTokenIndex);
        if (debug) {
            qDebug() << "firstParenToken:" << firstParenToken.spell();
            qDebug() << "lastParenToken:" << lastParenToken.spell();
        }

        // Select the parenthesis of the call, and everything between.
        int newPosStart = getTokenStartCursorPosition(firstParenTokenIndex, m_workingCursor);
        int newPosEnd = getTokenEndCursorPosition(lastParenTokenIndex, m_workingCursor);

        bool isInFunctionName =
                m_initialChangeSelectionCursor.position() <= newPosStart;

        // If cursor is inside the function name, select the name implicitly (because it's a
        // different AST node), and then the whole call expression (so just one step).
        // If cursor is inside parentheses, on first step select everything inside them,
        // on second step select the everything inside parentheses including them,
        // on third step select the whole call expression.
        if (currentASTStep() == 1 && !isInFunctionName) {
            if (debug)
                qDebug() << "Selecting everything inside parentheses.";
            positions.astPosStart = newPosStart + 1;
            positions.astPosEnd = newPosEnd - 1;
        }
        if (currentASTStep() == 2 && !isInFunctionName) {
            if (debug)
                qDebug() << "Selecting everything inside and including "
                            "the parentheses of the function call.";
            positions.astPosStart = newPosStart;
            positions.astPosEnd = newPosEnd;
        }
    } else if (StringLiteralAST *stringLiteralAST = ast->asStringLiteral()) {
        // Select literal without quotes on first step, and the whole literal on next step.
        if (currentASTStep() == 1) {
            Token firstToken = m_unit->tokenAt(stringLiteralAST->firstToken());
            bool isRawLiteral = firstToken.f.kind >= T_FIRST_RAW_STRING_LITERAL
                                && firstToken.f.kind <= T_RAW_UTF32_STRING_LITERAL;
            if (debug && isRawLiteral)
                qDebug() << "Is raw literal.";

            // Start from positions that include quotes.
            int newPosEnd = positions.astPosEnd;

            // Decrement last position to skip last quote.
            --newPosEnd;

            // If raw literal also skip parenthesis.
            if (isRawLiteral)
                --newPosEnd;
//.........这里部分代码省略.........
开发者ID:kai66673,项目名称:qt-creator,代码行数:101,代码来源:cppselectionchanger.cpp


注:本文中的AST::asStringLiteral方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。