~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/libs/3rdparty/cplusplus/TranslationUnit.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-12-02 09:16:15 UTC
  • mfrom: (1.1.29)
  • Revision ID: timo.jyrinki@canonical.com-20131202091615-xbj1os1f604ber1m
New upstream release candidate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <algorithm>
33
33
#include <utility>
34
34
 
35
 
#ifdef _MSC_VER
 
35
#if defined(_MSC_VER) && (_MSC_VER < 1800)
36
36
#    define va_copy(dst, src) ((dst) = (src))
37
37
#elif defined(__INTEL_COMPILER) && !defined(va_copy)
38
38
#    define va_copy __va_copy
40
40
 
41
41
using namespace CPlusPlus;
42
42
 
 
43
const Token TranslationUnit::nullToken;
 
44
 
43
45
TranslationUnit::TranslationUnit(Control *control, const StringLiteral *fileId)
44
46
    : _control(control),
45
47
      _fileId(fileId),
58
60
TranslationUnit::~TranslationUnit()
59
61
{
60
62
    (void) _control->switchTranslationUnit(_previousTranslationUnit);
61
 
    delete _tokens;
62
 
    delete _comments;
63
 
    delete _pool;
 
63
    release();
64
64
}
65
65
 
66
66
Control *TranslationUnit::control() const
95
95
    if (! index)
96
96
        return 0;
97
97
 
98
 
    return _tokens->at(index).spell();
 
98
    return tokenAt(index).spell();
99
99
}
100
100
 
101
101
unsigned TranslationUnit::commentCount() const
105
105
{ return _comments->at(index); }
106
106
 
107
107
const Identifier *TranslationUnit::identifier(unsigned index) const
108
 
{ return _tokens->at(index).identifier; }
 
108
{ return tokenAt(index).identifier; }
109
109
 
110
110
const Literal *TranslationUnit::literal(unsigned index) const
111
 
{ return _tokens->at(index).literal; }
 
111
{ return tokenAt(index).literal; }
112
112
 
113
113
const StringLiteral *TranslationUnit::stringLiteral(unsigned index) const
114
 
{ return _tokens->at(index).string; }
 
114
{ return tokenAt(index).string; }
115
115
 
116
116
const NumericLiteral *TranslationUnit::numericLiteral(unsigned index) const
117
 
{ return _tokens->at(index).number; }
 
117
{ return tokenAt(index).number; }
118
118
 
119
119
unsigned TranslationUnit::matchingBrace(unsigned index) const
120
 
{ return _tokens->at(index).close_brace; }
 
120
{ return tokenAt(index).close_brace; }
121
121
 
122
122
MemoryPool *TranslationUnit::memoryPool() const
123
123
{ return _pool; }
143
143
    lex.setScanCommentTokens(true);
144
144
 
145
145
    std::stack<unsigned> braces;
146
 
    _tokens->push_back(Token()); // the first token needs to be invalid!
 
146
    _tokens->push_back(nullToken); // the first token needs to be invalid!
147
147
 
148
148
    pushLineOffset(0);
149
149
    pushPreprocessorLine(0, 1, fileId());
250
250
        } else if (tk.f.kind == T_RBRACE && ! braces.empty()) {
251
251
            const unsigned open_brace_index = braces.top();
252
252
            braces.pop();
253
 
            (*_tokens)[open_brace_index].close_brace = unsigned(_tokens->size());
 
253
            if (open_brace_index < tokenCount())
 
254
                (*_tokens)[open_brace_index].close_brace = unsigned(_tokens->size());
254
255
        } else if (tk.isComment()) {
255
256
            _comments->push_back(tk);
256
257
            continue; // comments are not in the regular token stream
448
449
    if (DiagnosticClient *client = control()->diagnosticClient()) {
449
450
        client->report(level, fileName, line, column, format, args);
450
451
    } else {
451
 
        fprintf(stderr, "%s:%d: ", fileName->chars(), line);
 
452
        fprintf(stderr, "%s:%u: ", fileName->chars(), line);
452
453
        const char *l = "error";
453
454
        if (level == DiagnosticClient::Warning)
454
455
            l = "warning";
507
508
 
508
509
unsigned TranslationUnit::findPreviousLineOffset(unsigned tokenIndex) const
509
510
{
510
 
    unsigned lineOffset = _lineOffsets[findLineNumber(_tokens->at(tokenIndex).offset)];
 
511
    unsigned lineOffset = _lineOffsets[findLineNumber(tokenAt(tokenIndex).offset)];
511
512
    return lineOffset;
512
513
}
513
514
 
514
515
bool TranslationUnit::maybeSplitGreaterGreaterToken(unsigned tokenIndex)
515
516
{
516
 
    Token &tok = _tokens->at(tokenIndex);
 
517
    if (tokenIndex >= tokenCount())
 
518
        return false;
 
519
    Token &tok = (*_tokens)[tokenIndex];
517
520
    if (tok.kind() != T_GREATER_GREATER)
518
521
        return false;
519
522
 
538
541
    return true;
539
542
}
540
543
 
 
544
void TranslationUnit::releaseTokensAndComments()
 
545
{
 
546
    delete _tokens;
 
547
    _tokens = 0;
 
548
    delete _comments;
 
549
    _comments = 0;
 
550
}
 
551
 
541
552
void TranslationUnit::showErrorLine(unsigned index, unsigned column, FILE *out)
542
553
{
543
 
    unsigned lineOffset = _lineOffsets[findLineNumber(_tokens->at(index).offset)];
 
554
    unsigned lineOffset = _lineOffsets[findLineNumber(tokenAt(index).offset)];
544
555
    for (const char *cp = _firstSourceChar + lineOffset + 1; *cp && *cp != '\n'; ++cp) {
545
556
        fputc(*cp, out);
546
557
    }
567
578
void TranslationUnit::release()
568
579
{
569
580
    resetAST();
570
 
    delete _tokens;
571
 
    _tokens = 0;
572
 
    delete _comments;
573
 
    _comments = 0;
 
581
    releaseTokensAndComments();
574
582
}
575
 
 
576