forked from qt-creator/qt-creator
CppEditor: Add quickfix for converting comments from C++ to C style
... and vice versa. Fixes: QTCREATORBUG-27501 Change-Id: I8584cc1e86718b3fe0f0ead2a3436495303ca3c8 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
73
src/libs/3rdparty/cplusplus/TranslationUnit.cpp
vendored
73
src/libs/3rdparty/cplusplus/TranslationUnit.cpp
vendored
@@ -105,6 +105,35 @@ int TranslationUnit::commentCount() const
|
||||
const Token &TranslationUnit::commentAt(int index) const
|
||||
{ return _comments->at(index); }
|
||||
|
||||
std::vector<Token> TranslationUnit::allTokens() const
|
||||
{
|
||||
std::vector<Token> all;
|
||||
int tokIndex = 0;
|
||||
int commentIndex = 0;
|
||||
while (true) {
|
||||
if (tokIndex == tokenCount()) {
|
||||
for (int i = commentIndex; i < commentCount(); ++i)
|
||||
all.push_back(commentAt(i));
|
||||
break;
|
||||
}
|
||||
if (commentIndex == commentCount()) {
|
||||
for (int i = tokIndex; i < tokenCount(); ++i)
|
||||
all.push_back(tokenAt(i));
|
||||
break;
|
||||
}
|
||||
const Token &tok = tokenAt(tokIndex);
|
||||
const Token &comment = commentAt(commentIndex);
|
||||
if (tok.utf16charsBegin() < comment.utf16charsBegin()) {
|
||||
all.push_back(tok);
|
||||
++tokIndex;
|
||||
} else {
|
||||
all.push_back(comment);
|
||||
++commentIndex;
|
||||
}
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
const Identifier *TranslationUnit::identifier(int index) const
|
||||
{ return tokenAt(index).identifier; }
|
||||
|
||||
@@ -381,27 +410,55 @@ int TranslationUnit::findColumnNumber(int utf16CharOffset, int lineNumber) const
|
||||
|
||||
int TranslationUnit::getTokenPositionInDocument(int index, const QTextDocument *doc) const
|
||||
{
|
||||
int line, column;
|
||||
getTokenPosition(index, &line, &column);
|
||||
return Utils::Text::positionInText(doc, line, column);
|
||||
return getTokenPositionInDocument(_tokens->at(index), doc);
|
||||
}
|
||||
|
||||
int TranslationUnit::getTokenEndPositionInDocument(int index, const QTextDocument *doc) const
|
||||
{
|
||||
int line, column;
|
||||
getTokenEndPosition(index, &line, &column);
|
||||
return Utils::Text::positionInText(doc, line, column);
|
||||
return getTokenEndPositionInDocument(_tokens->at(index), doc);
|
||||
}
|
||||
|
||||
void TranslationUnit::getTokenPosition(int index, int *line,
|
||||
int *column,
|
||||
const StringLiteral **fileName) const
|
||||
{ return getPosition(tokenAt(index).utf16charsBegin(), line, column, fileName); }
|
||||
{
|
||||
return getTokenPosition(_tokens->at(index), line, column, fileName);
|
||||
}
|
||||
|
||||
void TranslationUnit::getTokenEndPosition(int index, int *line,
|
||||
int *column,
|
||||
const StringLiteral **fileName) const
|
||||
{ return getPosition(tokenAt(index).utf16charsEnd(), line, column, fileName); }
|
||||
{
|
||||
return getTokenEndPosition(_tokens->at(index), line, column, fileName);
|
||||
}
|
||||
|
||||
void TranslationUnit::getTokenPosition(const Token &token, int *line, int *column,
|
||||
const StringLiteral **fileName) const
|
||||
{
|
||||
return getPosition(token.utf16charsBegin(), line, column, fileName);
|
||||
}
|
||||
|
||||
void TranslationUnit::getTokenEndPosition(const Token &token, int *line,
|
||||
int *column, const StringLiteral **fileName) const
|
||||
{
|
||||
return getPosition(token.utf16charsEnd(), line, column, fileName);
|
||||
}
|
||||
|
||||
int TranslationUnit::getTokenPositionInDocument(const Token token,
|
||||
const QTextDocument *doc) const
|
||||
{
|
||||
int line, column;
|
||||
getTokenPosition(token, &line, &column);
|
||||
return Utils::Text::positionInText(doc, line, column);
|
||||
}
|
||||
|
||||
int TranslationUnit::getTokenEndPositionInDocument(const Token &token,
|
||||
const QTextDocument *doc) const
|
||||
{
|
||||
int line, column;
|
||||
getTokenEndPosition(token, &line, &column);
|
||||
return Utils::Text::positionInText(doc, line, column);
|
||||
}
|
||||
|
||||
void TranslationUnit::getPosition(int utf16charOffset,
|
||||
int *line,
|
||||
|
||||
11
src/libs/3rdparty/cplusplus/TranslationUnit.h
vendored
11
src/libs/3rdparty/cplusplus/TranslationUnit.h
vendored
@@ -65,6 +65,9 @@ public:
|
||||
int commentCount() const;
|
||||
const Token &commentAt(int index) const;
|
||||
|
||||
// Including comments.
|
||||
std::vector<Token> allTokens() const;
|
||||
|
||||
int matchingBrace(int index) const;
|
||||
const Identifier *identifier(int index) const;
|
||||
const Literal *literal(int index) const;
|
||||
@@ -120,9 +123,17 @@ public:
|
||||
int *line,
|
||||
int *column = nullptr,
|
||||
const StringLiteral **fileName = nullptr) const;
|
||||
|
||||
int getTokenPositionInDocument(int index, const QTextDocument *doc) const;
|
||||
int getTokenEndPositionInDocument(int index, const QTextDocument *doc) const;
|
||||
|
||||
void getTokenPosition(const Token &token, int *line, int *column = nullptr,
|
||||
const StringLiteral **fileName = nullptr) const;
|
||||
void getTokenEndPosition(const Token &token, int *line, int *column = nullptr,
|
||||
const StringLiteral **fileName = nullptr) const;
|
||||
int getTokenPositionInDocument(const Token token, const QTextDocument *doc) const;
|
||||
int getTokenEndPositionInDocument(const Token &token, const QTextDocument *doc) const;
|
||||
|
||||
void pushLineOffset(int offset);
|
||||
void pushPreprocessorLine(int utf16charOffset,
|
||||
int line,
|
||||
|
||||
Reference in New Issue
Block a user