diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2011-08-24 09:05:19 +0200 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2011-08-25 13:20:19 +0200 |
commit | 142bce94fb0cf3f439738a3dcb411265310c4b5c (patch) | |
tree | bf3fa36370fd660f6d50410d50ac708f042c4859 /src/libs/3rdparty/cplusplus/TranslationUnit.cpp | |
parent | 93e367ed0cd064a47649aa08e2722a02346530fc (diff) |
C++: Store comment tokens in the translation unit.
Change-Id: I904123bdbbd675e9f018236c1fed13528d83f87f
Reviewed-on: http://codereview.qt.nokia.com/3481
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/libs/3rdparty/cplusplus/TranslationUnit.cpp')
-rw-r--r-- | src/libs/3rdparty/cplusplus/TranslationUnit.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp index c512b4edc0..678a22384f 100644 --- a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp +++ b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp @@ -48,6 +48,7 @@ TranslationUnit::TranslationUnit(Control *control, const StringLiteral *fileId) _flags(0) { _tokens = new std::vector<Token>(); + _comments = new std::vector<Token>(); _previousTranslationUnit = control->switchTranslationUnit(this); _pool = new MemoryPool(); } @@ -56,6 +57,7 @@ TranslationUnit::~TranslationUnit() { (void) _control->switchTranslationUnit(_previousTranslationUnit); delete _tokens; + delete _comments; delete _pool; } @@ -121,6 +123,12 @@ const char *TranslationUnit::spell(unsigned index) const return _tokens->at(index).spell(); } +unsigned TranslationUnit::commentCount() const +{ return _comments->size(); } + +const Token &TranslationUnit::commentAt(unsigned index) const +{ return _comments->at(index); } + const Identifier *TranslationUnit::identifier(unsigned index) const { return _tokens->at(index).identifier; } @@ -159,6 +167,7 @@ void TranslationUnit::tokenize() lex.setQtMocRunEnabled(f._qtMocRunEnabled); lex.setCxxOxEnabled(f._cxx0xEnabled); lex.setObjCEnabled(f._objCEnabled); + lex.setScanCommentTokens(true); std::stack<unsigned> braces; _tokens->push_back(Token()); // the first token needs to be invalid! @@ -212,6 +221,9 @@ void TranslationUnit::tokenize() const unsigned open_brace_index = braces.top(); braces.pop(); (*_tokens)[open_brace_index].close_brace = _tokens->size(); + } else if (tk.isComment()) { + _comments->push_back(tk); + continue; // comments are not in the regular token stream } tk.f.generated = generated; _tokens->push_back(tk); @@ -475,6 +487,8 @@ void TranslationUnit::release() resetAST(); delete _tokens; _tokens = 0; + delete _comments; + _comments = 0; } |