summaryrefslogtreecommitdiff
path: root/src/qdoc/doc.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-11-13 14:48:12 +0100
committerLiang Qi <liang.qi@qt.io>2017-11-13 14:48:12 +0100
commit2f6aaed6dc157121e95b5dd210aea8bbd1338722 (patch)
tree4899d6e15980d1bfecb462ddf637b0445877a203 /src/qdoc/doc.cpp
parent07c2c0604bbfac064c8303f2a68ac54f8b7a78fc (diff)
parent995c91cd814d47e5ac3e20aca1d70d6e66f39cf2 (diff)
downloadqttools-2f6aaed6dc157121e95b5dd210aea8bbd1338722.tar.gz
Merge remote-tracking branch 'origin/wip/qdoc-clang' into dev
Conflicts: src/qdoc/cppcodeparser.h src/qdoc/location.cpp src/qdoc/qmlcodeparser.h Change-Id: I2e579ca5d83cd1c4b42acc9a07066d800cbc02cb
Diffstat (limited to 'src/qdoc/doc.cpp')
-rw-r--r--src/qdoc/doc.cpp225
1 files changed, 102 insertions, 123 deletions
diff --git a/src/qdoc/doc.cpp b/src/qdoc/doc.cpp
index 3300da593..5f9ca669a 100644
--- a/src/qdoc/doc.cpp
+++ b/src/qdoc/doc.cpp
@@ -72,14 +72,12 @@ enum {
CMD_BRIEF,
CMD_C,
CMD_CAPTION,
- CMD_CHAPTER,
CMD_CODE,
CMD_CODELINE,
CMD_DIV,
CMD_DOTS,
CMD_E,
CMD_ELSE,
- CMD_ENDCHAPTER,
CMD_ENDCODE,
CMD_ENDDIV,
CMD_ENDFOOTNOTE,
@@ -89,7 +87,6 @@ enum {
CMD_ENDLIST,
CMD_ENDMAPREF,
CMD_ENDOMIT,
- CMD_ENDPART,
CMD_ENDQUOTATION,
CMD_ENDRAW,
CMD_ENDSECTION1,
@@ -127,7 +124,6 @@ enum {
CMD_OMIT,
CMD_OMITVALUE,
CMD_OVERLOAD,
- CMD_PART,
CMD_PRINTLINE,
CMD_PRINTTO,
CMD_PRINTUNTIL,
@@ -188,14 +184,12 @@ static struct {
{ "brief", CMD_BRIEF, 0 },
{ "c", CMD_C, 0 },
{ "caption", CMD_CAPTION, 0 },
- { "chapter", CMD_CHAPTER, 0 },
{ "code", CMD_CODE, 0 },
{ "codeline", CMD_CODELINE, 0},
{ "div", CMD_DIV, 0 },
{ "dots", CMD_DOTS, 0 },
{ "e", CMD_E, 0 },
{ "else", CMD_ELSE, 0 },
- { "endchapter", CMD_ENDCHAPTER, 0 },
{ "endcode", CMD_ENDCODE, 0 },
{ "enddiv", CMD_ENDDIV, 0 },
{ "endfootnote", CMD_ENDFOOTNOTE, 0 },
@@ -205,7 +199,6 @@ static struct {
{ "endlist", CMD_ENDLIST, 0 },
{ "endmapref", CMD_ENDMAPREF, 0 },
{ "endomit", CMD_ENDOMIT, 0 },
- { "endpart", CMD_ENDPART, 0 },
{ "endquotation", CMD_ENDQUOTATION, 0 },
{ "endraw", CMD_ENDRAW, 0 },
{ "endsection1", CMD_ENDSECTION1, 0 }, // ### don't document for now
@@ -243,7 +236,6 @@ static struct {
{ "omit", CMD_OMIT, 0 },
{ "omitvalue", CMD_OMITVALUE, 0 },
{ "overload", CMD_OVERLOAD, 0 },
- { "part", CMD_PART, 0 },
{ "printline", CMD_PRINTLINE, 0 },
{ "printto", CMD_PRINTTO, 0 },
{ "printuntil", CMD_PRINTUNTIL, 0 },
@@ -501,8 +493,10 @@ private:
QStack<int> openedInputs;
- QString in;
+ QString input_;
int pos;
+ int backslashPos;
+ int endPos;
int len;
Location cachedLoc;
int cachedPos;
@@ -554,9 +548,9 @@ void DocParser::parse(const QString& source,
const QSet<QString>& metaCommandSet,
const QSet<QString>& possibleTopics)
{
- in = source;
+ input_ = source;
pos = 0;
- len = in.length();
+ len = input_.length();
cachedLoc = docPrivate->start_loc;
cachedPos = 0;
priv = docPrivate;
@@ -583,15 +577,16 @@ void DocParser::parse(const QString& source,
int numPreprocessorSkipping = 0;
while (pos < len) {
- QChar ch = in.at(pos);
+ QChar ch = input_.at(pos);
switch (ch.unicode()) {
case '\\':
{
QString cmdStr;
+ backslashPos = pos;
pos++;
while (pos < len) {
- ch = in.at(pos);
+ ch = input_.at(pos);
if (ch.isLetterOrNumber()) {
cmdStr += ch;
pos++;
@@ -600,15 +595,16 @@ void DocParser::parse(const QString& source,
break;
}
}
+ endPos = pos;
if (cmdStr.isEmpty()) {
if (pos < len) {
enterPara();
- if (in.at(pos).isSpace()) {
+ if (input_.at(pos).isSpace()) {
skipAllSpaces();
appendChar(QLatin1Char(' '));
}
else {
- appendChar(in.at(pos++));
+ appendChar(input_.at(pos++));
}
}
}
@@ -656,9 +652,6 @@ void DocParser::parse(const QString& source,
leavePara();
enterPara(Atom::CaptionLeft, Atom::CaptionRight);
break;
- case CMD_CHAPTER:
- startSection(Doc::Chapter, cmd);
- break;
case CMD_CODE:
leavePara();
append(Atom::Code, getCode(CMD_CODE, 0));
@@ -731,9 +724,6 @@ void DocParser::parse(const QString& source,
location().warning(tr("Unexpected '\\%1'").arg(cmdName(CMD_ELSE)));
}
break;
- case CMD_ENDCHAPTER:
- endSection(Doc::Chapter, cmd);
- break;
case CMD_ENDCODE:
closeCommand(cmd);
break;
@@ -800,9 +790,6 @@ void DocParser::parse(const QString& source,
case CMD_ENDOMIT:
closeCommand(cmd);
break;
- case CMD_ENDPART:
- endSection(Doc::Part, cmd);
- break;
case CMD_ENDQUOTATION:
if (closeCommand(cmd)) {
leavePara();
@@ -1098,9 +1085,6 @@ void DocParser::parse(const QString& source,
if (!priv->omitEnumItemList.contains(p1))
priv->omitEnumItemList.append(p1);
break;
- case CMD_PART:
- startSection(Doc::Part, cmd);
- break;
case CMD_PRINTLINE:
leavePara();
{
@@ -1429,10 +1413,12 @@ void DocParser::parse(const QString& source,
"syntax definitions"));
}
else {
- location().push(macro.defaultDefLocation.filePath());
- in.insert(pos, expandMacroToString(cmdStr, macro.defaultDef, macro.numParams));
- len = in.length();
- openedInputs.push(pos + macro.defaultDef.length());
+ QString expanded = expandMacroToString(cmdStr,
+ macro.defaultDef,
+ macro.numParams);
+ input_.replace(backslashPos, endPos - backslashPos, expanded);
+ len = input_.length();
+ pos = backslashPos;
}
}
}
@@ -1488,8 +1474,8 @@ void DocParser::parse(const QString& source,
case '/':
{
if (pos + 2 < len)
- if (in.at(pos + 1) == '/')
- if (in.at(pos + 2) == '!') {
+ if (input_.at(pos + 1) == '/')
+ if (input_.at(pos + 2) == '!') {
pos += 2;
getRestOfLine();
break;
@@ -1543,7 +1529,7 @@ void DocParser::parse(const QString& source,
int numStrangeSymbols = 0;
while (pos < len) {
- unsigned char latin1Ch = in.at(pos).toLatin1();
+ unsigned char latin1Ch = input_.at(pos).toLatin1();
if (islower(latin1Ch)) {
++numLowercase;
++pos;
@@ -1566,14 +1552,14 @@ void DocParser::parse(const QString& source,
++pos;
}
else if (latin1Ch == ':' && pos < len - 1
- && in.at(pos + 1) == QLatin1Char(':')) {
+ && input_.at(pos + 1) == QLatin1Char(':')) {
++numStrangeSymbols;
pos += 2;
}
else if (latin1Ch == '(') {
if (pos > startPos) {
if (pos < len - 1 &&
- in.at(pos + 1) == QLatin1Char(')')) {
+ input_.at(pos + 1) == QLatin1Char(')')) {
++numStrangeSymbols;
pos += 2;
break;
@@ -1600,7 +1586,7 @@ void DocParser::parse(const QString& source,
}
}
else {
- QString word = in.mid(startPos, pos - startPos);
+ QString word = input_.mid(startPos, pos - startPos);
// is word a C++ symbol or an English word?
if ((numInternalUppercase >= 1 && numLowercase >= 2)
|| numStrangeSymbols > 0) {
@@ -1651,7 +1637,7 @@ Location &DocParser::location()
cachedPos = openedInputs.pop();
}
while (cachedPos < pos)
- cachedLoc.advance(in.at(cachedPos++));
+ cachedLoc.advance(input_.at(cachedPos++));
return cachedLoc;
}
@@ -1727,8 +1713,8 @@ void DocParser::include(const QString& fileName, const QString& identifier)
inFile.close();
if (identifier.isEmpty()) {
- in.insert(pos, includedStuff);
- len = in.length();
+ input_.insert(pos, includedStuff);
+ len = input_.length();
openedInputs.push(pos + includedStuff.length());
}
else {
@@ -1771,8 +1757,8 @@ void DocParser::include(const QString& fileName, const QString& identifier)
.arg(userFriendlyFilePath));
}
else {
- in.insert(pos, result);
- len = in.length();
+ input_.insert(pos, result);
+ len = input_.length();
openedInputs.push(pos + result.length());
}
}
@@ -1918,14 +1904,14 @@ void DocParser::parseAlso()
{
leavePara();
skipSpacesOnLine();
- while (pos < len && in[pos] != '\n') {
+ while (pos < len && input_[pos] != '\n') {
QString target;
QString str;
- if (in[pos] == '{') {
+ if (input_[pos] == '{') {
target = getArgument();
skipSpacesOnLine();
- if (in[pos] == '{') {
+ if (input_[pos] == '{') {
str = getArgument();
// hack for C++ to support links like \l{QString::}{count()}
@@ -1937,12 +1923,12 @@ void DocParser::parseAlso()
}
#ifdef QDOC2_COMPAT
}
- else if (in[pos] == '\\' && in.mid(pos, 5) == "\\link") {
+ else if (input_[pos] == '\\' && input_.mid(pos, 5) == "\\link") {
pos += 6;
target = getArgument();
- int endPos = in.indexOf("\\endlink", pos);
+ int endPos = input_.indexOf("\\endlink", pos);
if (endPos != -1) {
- str = in.mid(pos, endPos - pos).trimmed();
+ str = input_.mid(pos, endPos - pos).trimmed();
pos = endPos + 8;
}
#endif
@@ -1960,11 +1946,11 @@ void DocParser::parseAlso()
priv->addAlso(also);
skipSpacesOnLine();
- if (pos < len && in[pos] == ',') {
+ if (pos < len && input_[pos] == ',') {
pos++;
skipSpacesOrOneEndl();
}
- else if (in[pos] != '\n') {
+ else if (input_[pos] != '\n') {
location().warning(tr("Missing comma in '\\%1'").arg(cmdName(CMD_SA)));
}
}
@@ -2239,13 +2225,7 @@ Doc::Sections DocParser::getSectioningUnit()
{
QString name = getOptionalArgument();
- if (name == "part") {
- return Doc::Part;
- }
- else if (name == "chapter") {
- return Doc::Chapter;
- }
- else if (name == "section1") {
+ if (name == "section1") {
return Doc::Section1;
}
else if (name == "section2") {
@@ -2279,10 +2259,10 @@ QString DocParser::getBracedArgument(bool verbatim)
{
QString arg;
int delimDepth = 0;
- if (pos < (int) in.length() && in[pos] == '{') {
+ if (pos < (int) input_.length() && input_[pos] == '{') {
pos++;
- while (pos < (int) in.length() && delimDepth >= 0) {
- switch (in[pos].unicode()) {
+ while (pos < (int) input_.length() && delimDepth >= 0) {
+ switch (input_[pos].unicode()) {
case '{':
delimDepth++;
arg += QLatin1Char('{');
@@ -2296,16 +2276,16 @@ QString DocParser::getBracedArgument(bool verbatim)
break;
case '\\':
if (verbatim) {
- arg += in[pos];
+ arg += input_[pos];
pos++;
}
else {
pos++;
- if (pos < (int) in.length()) {
- if (in[pos].isLetterOrNumber())
+ if (pos < (int) input_.length()) {
+ if (input_[pos].isLetterOrNumber())
break;
- arg += in[pos];
- if (in[pos].isSpace()) {
+ arg += input_[pos];
+ if (input_[pos].isSpace()) {
skipAllSpaces();
}
else {
@@ -2315,16 +2295,17 @@ QString DocParser::getBracedArgument(bool verbatim)
}
break;
default:
- if (in[pos].isSpace() && !verbatim)
+ if (input_[pos].isSpace() && !verbatim)
arg += QChar(' ');
else
- arg += in[pos];
+ arg += input_[pos];
pos++;
}
}
if (delimDepth > 0)
location().warning(tr("Missing '}'"));
}
+ endPos = pos;
return arg;
}
@@ -2347,16 +2328,17 @@ QString DocParser::getArgument(bool verbatim)
int delimDepth = 0;
int startPos = pos;
+ endPos = pos;
QString arg = getBracedArgument(verbatim);
if (arg.isEmpty()) {
- while ((pos < in.length()) &&
- ((delimDepth > 0) || ((delimDepth == 0) && !in[pos].isSpace()))) {
- switch (in[pos].unicode()) {
+ while ((pos < input_.length()) &&
+ ((delimDepth > 0) || ((delimDepth == 0) && !input_[pos].isSpace()))) {
+ switch (input_[pos].unicode()) {
case '(':
case '[':
case '{':
delimDepth++;
- arg += in[pos];
+ arg += input_[pos];
pos++;
break;
case ')':
@@ -2364,22 +2346,22 @@ QString DocParser::getArgument(bool verbatim)
case '}':
delimDepth--;
if (pos == startPos || delimDepth >= 0) {
- arg += in[pos];
+ arg += input_[pos];
pos++;
}
break;
case '\\':
if (verbatim) {
- arg += in[pos];
+ arg += input_[pos];
pos++;
}
else {
pos++;
- if (pos < (int) in.length()) {
- if (in[pos].isLetterOrNumber())
+ if (pos < (int) input_.length()) {
+ if (input_[pos].isLetterOrNumber())
break;
- arg += in[pos];
- if (in[pos].isSpace()) {
+ arg += input_[pos];
+ if (input_[pos].isSpace()) {
skipAllSpaces();
}
else {
@@ -2389,17 +2371,18 @@ QString DocParser::getArgument(bool verbatim)
}
break;
default:
- arg += in[pos];
+ arg += input_[pos];
pos++;
}
}
+ endPos = pos;
if ((arg.length() > 1) &&
- (QString(".,:;!?").indexOf(in[pos - 1]) != -1) &&
+ (QString(".,:;!?").indexOf(input_[pos - 1]) != -1) &&
!arg.endsWith("...")) {
arg.truncate(arg.length() - 1);
pos--;
}
- if (arg.length() > 2 && in.mid(pos - 2, 2) == "'s") {
+ if (arg.length() > 2 && input_.mid(pos - 2, 2) == "'s") {
arg.truncate(arg.length() - 2);
pos -= 2;
}
@@ -2418,10 +2401,10 @@ QString DocParser::getBracketedArgument()
QString arg;
int delimDepth = 0;
skipSpacesOrOneEndl();
- if (pos < in.length() && in[pos] == '[') {
+ if (pos < input_.length() && input_[pos] == '[') {
pos++;
- while (pos < in.length() && delimDepth >= 0) {
- switch (in[pos].unicode()) {
+ while (pos < input_.length() && delimDepth >= 0) {
+ switch (input_[pos].unicode()) {
case '[':
delimDepth++;
arg += QLatin1Char('[');
@@ -2434,11 +2417,11 @@ QString DocParser::getBracketedArgument()
pos++;
break;
case '\\':
- arg += in[pos];
+ arg += input_[pos];
pos++;
break;
default:
- arg += in[pos];
+ arg += input_[pos];
pos++;
}
}
@@ -2451,8 +2434,8 @@ QString DocParser::getBracketedArgument()
QString DocParser::getOptionalArgument()
{
skipSpacesOrOneEndl();
- if (pos + 1 < (int) in.length() && in[pos] == '\\' &&
- in[pos + 1].isLetterOrNumber()) {
+ if (pos + 1 < (int) input_.length() && input_[pos] == '\\' &&
+ input_[pos + 1].isLetterOrNumber()) {
return QString();
}
else {
@@ -2471,13 +2454,13 @@ QString DocParser::getRestOfLine()
do {
int begin = pos;
- while (pos < in.size() && in[pos] != '\n') {
- if (in[pos] == '\\' && !trailingSlash) {
+ while (pos < input_.size() && input_[pos] != '\n') {
+ if (input_[pos] == '\\' && !trailingSlash) {
trailingSlash = true;
++pos;
- while ((pos < in.size()) &&
- in[pos].isSpace() &&
- (in[pos] != '\n'))
+ while ((pos < input_.size()) &&
+ input_[pos].isSpace() &&
+ (input_[pos] != '\n'))
++pos;
}
else {
@@ -2488,15 +2471,15 @@ QString DocParser::getRestOfLine()
if (!t.isEmpty())
t += QLatin1Char(' ');
- t += in.mid(begin, pos - begin).simplified();
+ t += input_.mid(begin, pos - begin).simplified();
if (trailingSlash) {
t.chop(1);
t = t.simplified();
}
- if (pos < in.size())
+ if (pos < input_.size())
++pos;
- } while (pos < in.size() && trailingSlash);
+ } while (pos < input_.size() && trailingSlash);
return t;
}
@@ -2513,20 +2496,20 @@ QString DocParser::getMetaCommandArgument(const QString &cmdStr)
int begin = pos;
int parenDepth = 0;
- while (pos < in.size() && (in[pos] != '\n' || parenDepth > 0)) {
- if (in.at(pos) == '(')
+ while (pos < input_.size() && (input_[pos] != '\n' || parenDepth > 0)) {
+ if (input_.at(pos) == '(')
++parenDepth;
- else if (in.at(pos) == ')')
+ else if (input_.at(pos) == ')')
--parenDepth;
++pos;
}
- if (pos == in.size() && parenDepth > 0) {
+ if (pos == input_.size() && parenDepth > 0) {
pos = begin;
location().warning(tr("Unbalanced parentheses in '%1'").arg(cmdStr));
}
- QString t = in.mid(begin, pos - begin).simplified();
+ QString t = input_.mid(begin, pos - begin).simplified();
skipSpacesOnLine();
return t;
}
@@ -2536,14 +2519,14 @@ QString DocParser::getUntilEnd(int cmd)
int endCmd = endCmdFor(cmd);
QRegExp rx("\\\\" + cmdName(endCmd) + "\\b");
QString t;
- int end = rx.indexIn(in, pos);
+ int end = rx.indexIn(input_, pos);
if (end == -1) {
location().warning(tr("Missing '\\%1'").arg(cmdName(endCmd)));
- pos = in.length();
+ pos = input_.length();
}
else {
- t = in.mid(pos, end - pos);
+ t = input_.mid(pos, end - pos);
pos = end + rx.matchedLength();
}
return t;
@@ -2572,8 +2555,8 @@ bool DocParser::isBlankLine()
{
int i = pos;
- while (i < len && in[i].isSpace()) {
- if (in[i] == '\n')
+ while (i < len && input_[i].isSpace()) {
+ if (input_[i] == '\n')
return true;
i++;
}
@@ -2585,13 +2568,13 @@ bool DocParser::isLeftBraceAhead()
int numEndl = 0;
int i = pos;
- while (i < len && in[i].isSpace() && numEndl < 2) {
+ while (i < len && input_[i].isSpace() && numEndl < 2) {
// ### bug with '\\'
- if (in[i] == '\n')
+ if (input_[i] == '\n')
numEndl++;
i++;
}
- return numEndl < 2 && i < len && in[i] == '{';
+ return numEndl < 2 && i < len && input_[i] == '{';
}
bool DocParser::isLeftBracketAhead()
@@ -2599,13 +2582,13 @@ bool DocParser::isLeftBracketAhead()
int numEndl = 0;
int i = pos;
- while (i < len && in[i].isSpace() && numEndl < 2) {
+ while (i < len && input_[i].isSpace() && numEndl < 2) {
// ### bug with '\\'
- if (in[i] == '\n')
+ if (input_[i] == '\n')
numEndl++;
i++;
}
- return numEndl < 2 && i < len && in[i] == '[';
+ return numEndl < 2 && i < len && input_[i] == '[';
}
/*!
@@ -2613,9 +2596,9 @@ bool DocParser::isLeftBracketAhead()
*/
void DocParser::skipSpacesOnLine()
{
- while ((pos < in.length()) &&
- in[pos].isSpace() &&
- (in[pos].unicode() != '\n'))
+ while ((pos < input_.length()) &&
+ input_[pos].isSpace() &&
+ (input_[pos].unicode() != '\n'))
++pos;
}
@@ -2625,8 +2608,8 @@ void DocParser::skipSpacesOnLine()
void DocParser::skipSpacesOrOneEndl()
{
int firstEndl = -1;
- while (pos < (int) in.length() && in[pos].isSpace()) {
- QChar ch = in[pos];
+ while (pos < (int) input_.length() && input_[pos].isSpace()) {
+ QChar ch = input_[pos];
if (ch == '\n') {
if (firstEndl == -1) {
firstEndl = pos;
@@ -2642,7 +2625,7 @@ void DocParser::skipSpacesOrOneEndl()
void DocParser::skipAllSpaces()
{
- while (pos < len && in[pos].isSpace())
+ while (pos < len && input_[pos].isSpace())
pos++;
}
@@ -2651,10 +2634,10 @@ void DocParser::skipToNextPreprocessorCommand()
QRegExp rx("\\\\(?:" + cmdName(CMD_IF) + QLatin1Char('|') +
cmdName(CMD_ELSE) + QLatin1Char('|') +
cmdName(CMD_ENDIF) + ")\\b");
- int end = rx.indexIn(in, pos + 1); // ### + 1 necessary?
+ int end = rx.indexIn(input_, pos + 1); // ### + 1 necessary?
if (end == -1)
- pos = in.length();
+ pos = input_.length();
else
pos = end;
}
@@ -2664,8 +2647,6 @@ int DocParser::endCmdFor(int cmd)
switch (cmd) {
case CMD_BADCODE:
return CMD_ENDCODE;
- case CMD_CHAPTER:
- return CMD_ENDCHAPTER;
case CMD_CODE:
return CMD_ENDCODE;
case CMD_DIV:
@@ -2690,8 +2671,6 @@ int DocParser::endCmdFor(int cmd)
return CMD_NEWCODE;
case CMD_OMIT:
return CMD_ENDOMIT;
- case CMD_PART:
- return CMD_ENDPART;
case CMD_QUOTATION:
return CMD_ENDQUOTATION;
case CMD_RAW: