diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2009-02-20 11:52:27 +0100 |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2009-02-20 11:52:27 +0100 |
commit | 4c5ff047f0a1831d1247ca73d889b283d01fd3fb (patch) | |
tree | b6de5bfcf63aa22bc0a8265a7cc055a70ce132ae /src/shared | |
parent | 4a259547fc5a8e456ca47c1fd218dae028c9e271 (diff) | |
download | qt-creator-4c5ff047f0a1831d1247ca73d889b283d01fd3fb.tar.gz |
Initial support for doxygen comments.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/cplusplus/Lexer.cpp | 42 | ||||
-rw-r--r-- | src/shared/cplusplus/Lexer.h | 5 | ||||
-rw-r--r-- | src/shared/cplusplus/Token.cpp | 2 | ||||
-rw-r--r-- | src/shared/cplusplus/Token.h | 4 |
4 files changed, 40 insertions, 13 deletions
diff --git a/src/shared/cplusplus/Lexer.cpp b/src/shared/cplusplus/Lexer.cpp index 73c12524d7..4d0b2b6e80 100644 --- a/src/shared/cplusplus/Lexer.cpp +++ b/src/shared/cplusplus/Lexer.cpp @@ -60,7 +60,7 @@ CPLUSPLUS_BEGIN_NAMESPACE Lexer::Lexer(TranslationUnit *unit) : _translationUnit(unit), - _state(Lexer::DefaultState), + _state(State_Default), _flags(0), _currentLine(1) { @@ -71,7 +71,7 @@ Lexer::Lexer(TranslationUnit *unit) Lexer::Lexer(const char *firstChar, const char *lastChar) : _translationUnit(0), - _state(Lexer::DefaultState), + _state(State_Default), _flags(0), _currentLine(1) { @@ -196,7 +196,7 @@ void Lexer::scan_helper(Token *tok) _tokenStart = _currentChar; tok->offset = _currentChar - _firstChar; - if (_state == MultiLineCommentState) { + if (_state == State_MultiLineComment || _state == State_MultiLineDoxyComment) { if (! _yychar) { tok->kind = T_EOF_SYMBOL; return; @@ -209,7 +209,7 @@ void Lexer::scan_helper(Token *tok) yyinp(); if (_yychar == '/') { yyinp(); - _state = DefaultState; + _state = State_Default; break; } } @@ -218,7 +218,11 @@ void Lexer::scan_helper(Token *tok) if (! _scanCommentTokens) goto _Lagain; - tok->kind = T_COMMENT; + else if (_state == State_MultiLineComment) + tok->kind = T_COMMENT; + + else + tok->kind = T_DOXY_COMMENT; return; // done } @@ -402,14 +406,30 @@ void Lexer::scan_helper(Token *tok) case '/': if (_yychar == '/') { - do { + yyinp(); + + bool doxy = false; + + if (_yychar == '/' || _yychar == '!') { + yyinp(); + + if (_yychar != '\n' && std::isspace(_yychar)) + doxy = true; + } + + while (_yychar && _yychar != '\n') yyinp(); - } while (_yychar && _yychar != '\n'); + if (! _scanCommentTokens) goto _Lagain; - tok->kind = T_COMMENT; + + tok->kind = doxy ? T_DOXY_COMMENT : T_COMMENT; + } else if (_yychar == '*') { yyinp(); + + const bool doxy = _yychar == '*' || _yychar == '!'; + while (_yychar) { if (_yychar != '*') { yyinp(); @@ -423,11 +443,13 @@ void Lexer::scan_helper(Token *tok) if (_yychar) yyinp(); else - _state = MultiLineCommentState; + _state = doxy ? State_MultiLineDoxyComment : State_MultiLineComment; if (! _scanCommentTokens) goto _Lagain; - tok->kind = T_COMMENT; + + tok->kind = doxy ? T_DOXY_COMMENT : T_COMMENT; + } else if (_yychar == '=') { yyinp(); tok->kind = T_SLASH_EQUAL; diff --git a/src/shared/cplusplus/Lexer.h b/src/shared/cplusplus/Lexer.h index 4cb62493db..fb9c80ef98 100644 --- a/src/shared/cplusplus/Lexer.h +++ b/src/shared/cplusplus/Lexer.h @@ -66,8 +66,9 @@ class CPLUSPLUS_EXPORT Lexer public: enum State { - DefaultState, - MultiLineCommentState + State_Default, + State_MultiLineComment, + State_MultiLineDoxyComment }; Lexer(TranslationUnit *unit); diff --git a/src/shared/cplusplus/Token.cpp b/src/shared/cplusplus/Token.cpp index eb672958cd..e47a1573d9 100644 --- a/src/shared/cplusplus/Token.cpp +++ b/src/shared/cplusplus/Token.cpp @@ -58,7 +58,7 @@ CPLUSPLUS_BEGIN_NAMESPACE static const char *token_names[] = { (""), ("<error>"), - ("<comment>"), + ("<comment>"), ("<doxy comment>"), ("<identifier>"), ("<int literal>"), ("<float literal>"), ("<char literal>"), ("<wide char literal>"), ("<string literal>"), ("<wide char literal>"), diff --git a/src/shared/cplusplus/Token.h b/src/shared/cplusplus/Token.h index f48654aa77..55cacf7379 100644 --- a/src/shared/cplusplus/Token.h +++ b/src/shared/cplusplus/Token.h @@ -64,6 +64,7 @@ enum Kind { T_ERROR, T_COMMENT, + T_DOXY_COMMENT, T_IDENTIFIER, T_FIRST_LITERAL, @@ -297,6 +298,9 @@ public: inline bool isKeyword() const { return kind >= T_FIRST_KEYWORD && kind < T_FIRST_QT_KEYWORD; } + inline bool isComment() const + { return kind == T_COMMENT || kind == T_DOXY_COMMENT; } + inline bool isObjCAtKeyword() const { return kind >= T_FIRST_OBJC_AT_KEYWORD && kind < T_LAST_OBJC_AT_KEYWORD; } |