summaryrefslogtreecommitdiffstats
path: root/src/tools/qdoc/cppcodeparser.cpp
diff options
context:
space:
mode:
authorMartin Smith <martin.smith@digia.com>2015-02-26 10:34:47 +0100
committerMartin Smith <martin.smith@digia.com>2015-02-26 13:24:13 +0000
commit99120ca3cf2a22f89fd7ec46ff483882fc3a2bbe (patch)
treeb3f91f86565049a4de6490481cb41edef0d55864 /src/tools/qdoc/cppcodeparser.cpp
parentcd46d94906ec0d10acd0fcb086d9177a1b282691 (diff)
qdoc: Correct parsing of the using clause
qdoc could only parse the using clause where the 'using' keyword was followed by 'namespace'. Now it can parse using clauses with or without 'namespace'. Change-Id: Ic4aad025c00b3bda2bc1cbd52d0ba8dbbad653e5 Task-number: QTBUG-44553 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com> Reviewed-by: Topi Reiniƶ <topi.reinio@digia.com>
Diffstat (limited to 'src/tools/qdoc/cppcodeparser.cpp')
-rw-r--r--src/tools/qdoc/cppcodeparser.cpp85
1 files changed, 63 insertions, 22 deletions
diff --git a/src/tools/qdoc/cppcodeparser.cpp b/src/tools/qdoc/cppcodeparser.cpp
index 405be6f500..6cb86a7515 100644
--- a/src/tools/qdoc/cppcodeparser.cpp
+++ b/src/tools/qdoc/cppcodeparser.cpp
@@ -1692,35 +1692,76 @@ bool CppCodeParser::matchNamespaceDecl(InnerNode *parent)
return matched && match(Tok_RightBrace);
}
-bool CppCodeParser::matchUsingDecl()
+/*!
+ Match a C++ \c using clause. Return \c true if the match
+ is successful. Otherwise false.
+
+ If the \c using clause is for a namespace, an open namespace
+ <is inserted for qdoc to look in to find things.
+
+ If the \c using clause is a base class member function, the
+ member function is added to \a parent as an unresolved
+ \c using clause.
+ */
+bool CppCodeParser::matchUsingDecl(InnerNode* parent)
{
+ bool usingNamespace = false;
readToken(); // skip 'using'
- // 'namespace'
- if (tok != Tok_namespace)
- return false;
-
- readToken();
- // identifier
- if (tok != Tok_Ident)
- return false;
+ if (tok == Tok_namespace) {
+ usingNamespace = true;
+ readToken();
+ }
+ int openLeftAngles = 0;
+ int openLeftParens = 0;
+ bool usingOperator = false;
QString name;
- while (tok == Tok_Ident) {
+ while (tok != Tok_Semicolon) {
+ if ((tok != Tok_Ident) && (tok != Tok_Gulbrandsen)) {
+ if (tok == Tok_LeftAngle) {
+ ++openLeftAngles;
+ }
+ else if (tok == Tok_RightAngle) {
+ if (openLeftAngles <= 0)
+ return false;
+ --openLeftAngles;
+ }
+ else if (tok == Tok_Comma) {
+ if (openLeftAngles <= 0)
+ return false;
+ }
+ else if (tok == Tok_operator) {
+ usingOperator = true;
+ }
+ else if (tok == Tok_SomeOperator) {
+ if (!usingOperator)
+ return false;
+ }
+ else if (tok == Tok_LeftParen) {
+ ++openLeftParens;
+ }
+ else if (tok == Tok_RightParen) {
+ if (openLeftParens <= 0)
+ return false;
+ --openLeftParens;
+ }
+ else {
+ return false;
+ }
+ }
name += lexeme();
readToken();
- if (tok == Tok_Semicolon)
- break;
- else if (tok != Tok_Gulbrandsen)
- return false;
- name += "::";
- readToken();
}
- /*
- So far, so good. We have 'using namespace Foo;'.
- */
- qdb_->insertOpenNamespace(name);
+ if (usingNamespace) {
+ // 'using namespace Foo;'.
+ qdb_->insertOpenNamespace(name);
+ }
+ else if (parent && parent->isClass()) {
+ ClassNode* cn = static_cast<ClassNode*>(parent);
+ cn->addUnresolvedUsingClause(name);
+ }
return true;
}
@@ -1961,7 +2002,7 @@ bool CppCodeParser::matchDeclList(InnerNode *parent)
matchNamespaceDecl(parent);
break;
case Tok_using:
- matchUsingDecl();
+ matchUsingDecl(parent);
break;
case Tok_template:
{
@@ -2221,7 +2262,7 @@ bool CppCodeParser::matchDocsAndStuff()
}
}
else if (tok == Tok_using) {
- matchUsingDecl();
+ matchUsingDecl(0);
}
else {
QStringList parentPath;