~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/cpptools/cpppointerdeclarationformatter.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-11-15 12:25:23 UTC
  • mfrom: (1.1.28)
  • Revision ID: timo.jyrinki@canonical.com-20131115122523-i2kyamsu4gs2mu1m
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
using namespace CppTools;
52
52
 
53
53
/*!
54
 
   \brief Skip not type relevant specifiers and return the index of the
 
54
   Skips specifiers that are not type relevant and returns the index of the
55
55
          first specifier token which is not followed by __attribute__
56
56
          ((T___ATTRIBUTE__)).
57
57
 
60
60
 
61
61
   Consider these cases:
62
62
 
63
 
        static char *s = 0;
64
 
        typedef char *s cp;
65
 
        __attribute__((visibility("default"))) char *f();
 
63
    \list
 
64
        \li \c {static char *s = 0;}
 
65
        \li \c {typedef char *s cp;}
 
66
        \li \c {__attribute__((visibility("default"))) char *f();}
 
67
    \endlist
66
68
 
67
 
   For all cases we want to skip all the not type relevant specifer
 
69
   For all these cases we want to skip all the specifiers that are not type
 
70
   relevant
68
71
   (since these are not part of the type and thus are not rewritten).
69
72
 
70
 
   \param list The specifier list to iterate
71
 
   \param translationUnit The TranslationUnit
72
 
   \param endToken Do not check further than this token
73
 
   \param found Output parameter, must not be 0.
 
73
   \a list is the specifier list to iterate and \a translationUnit is the
 
74
   translation unit.
 
75
   \a endToken is the last token to check.
 
76
   \a found is an output parameter that must not be 0.
74
77
 */
75
78
static unsigned firstTypeSpecifierWithoutFollowingAttribute(
76
79
    SpecifierListAST *list, TranslationUnit *translationUnit, unsigned endToken, bool *found)
77
80
{
78
81
    *found = false;
79
 
    if (! list || ! translationUnit || ! endToken)
 
82
    if (!list || !translationUnit || !endToken)
80
83
        return 0;
81
84
 
82
85
    for (SpecifierListAST *it = list; it; it = it->next) {
156
159
        // characters from the beginning since our rewritten declaration
157
160
        // will contain all type specifiers.
158
161
        int charactersToRemove = 0;
159
 
        if (! isFirstDeclarator) {
 
162
        if (!isFirstDeclarator) {
160
163
            const int startAST = m_cppRefactoringFile->startOf(ast);
161
164
            const int startFirstDeclarator = m_cppRefactoringFile->startOf(firstDeclarator);
162
165
            CHECK_RV(startAST < startFirstDeclarator, "No specifier", true);
188
191
                        m_cppRefactoringFile->cppDocument()->translationUnit(),
189
192
                        lastActivationToken,
190
193
                        &foundBegin);
191
 
            if (! foundBegin) {
192
 
                CHECK_RV(! isFirstDeclarator, "Declaration without attributes not supported", true);
 
194
            if (!foundBegin) {
 
195
                CHECK_RV(!isFirstDeclarator, "Declaration without attributes not supported", true);
193
196
                firstActivationToken = declarator->firstToken();
194
197
            }
195
198
 
363
366
}
364
367
 
365
368
/*!
366
 
   \brief Do some further checks and rewrite the symbol's type and
367
 
          name into the given range
368
 
 
369
 
   \param symbol the symbol to be rewritten
370
 
   \param range the substitution range in the file
 
369
    Performs some further checks and rewrites the type and name of \a symbol
 
370
    into the substitution range in the file specified by \a tokenRange.
371
371
 */
372
372
void PointerDeclarationFormatter::checkAndRewrite(DeclaratorAST *declarator,
373
373
                                                  Symbol *symbol,
380
380
 
381
381
    // Check for expanded tokens
382
382
    for (unsigned token = tokenRange.start; token <= tokenRange.end; ++token)
383
 
        CHECK_R(! tokenAt(token).expanded(), "Token is expanded");
 
383
        CHECK_R(!tokenAt(token).expanded(), "Token is expanded");
384
384
 
385
385
    Range range(m_cppRefactoringFile->startOf(tokenRange.start),
386
386
                m_cppRefactoringFile->endOf(tokenRange.end));