summaryrefslogtreecommitdiff
path: root/src/qdoc/cppcodeparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qdoc/cppcodeparser.cpp')
-rw-r--r--src/qdoc/cppcodeparser.cpp219
1 files changed, 83 insertions, 136 deletions
diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp
index b700823e5..0904ebc4e 100644
--- a/src/qdoc/cppcodeparser.cpp
+++ b/src/qdoc/cppcodeparser.cpp
@@ -68,7 +68,6 @@ CppCodeParser::CppCodeParser()
<< COMMAND_ENUM
<< COMMAND_EXAMPLE
<< COMMAND_EXTERNALPAGE
- << COMMAND_FILE
<< COMMAND_FN
<< COMMAND_GROUP
<< COMMAND_HEADERFILE
@@ -110,7 +109,6 @@ CppCodeParser::CppCodeParser()
<< COMMAND_CONTENTSPAGE
<< COMMAND_NEXTPAGE
<< COMMAND_PREVIOUSPAGE
- << COMMAND_INDEXPAGE
<< COMMAND_STARTPAGE
<< COMMAND_QMLINHERITS
<< COMMAND_QMLINSTANTIATES
@@ -122,14 +120,6 @@ CppCodeParser::CppCodeParser()
}
/*!
- The destructor is trivial.
- */
-CppCodeParser::~CppCodeParser()
-{
- // nothing.
-}
-
-/*!
The constructor initializes a map of special node types
for identifying important nodes. And it initializes
some filters for identifying and excluding certain kinds of files.
@@ -186,14 +176,6 @@ void CppCodeParser::terminateParser()
}
/*!
- Returns "Cpp".
- */
-QString CppCodeParser::language()
-{
- return "Cpp";
-}
-
-/*!
Returns a list of extensions for header files.
*/
QStringList CppCodeParser::headerFileNameFilter()
@@ -240,9 +222,14 @@ Node* CppCodeParser::processTopicCommand(const Doc& doc,
*/
Node::NodeType type = nodeTypeMap[command];
QStringList words = arg.first.split(QLatin1Char(' '));
- QStringList path = words[0].split("::");
+ QStringList path;
+ int idx = 0;
Node *node = 0;
+ if (type == Node::Variable && words.size() > 1)
+ idx = words.size() - 1;
+ path = words[idx].split("::");
+
node = qdb_->findNodeInOpenNamespace(path, type);
if (node == 0)
node = qdb_->findNodeByNameAndType(path, type);
@@ -277,33 +264,19 @@ Node* CppCodeParser::processTopicCommand(const Doc& doc,
if (Config::generateExamples) {
ExampleNode* en = new ExampleNode(qdb_->primaryTreeRoot(), arg.first);
en->setLocation(doc.startLocation());
- createExampleFileNodes(en);
+ setExampleFileLists(en);
return en;
}
}
else if (command == COMMAND_EXTERNALPAGE) {
- DocumentNode* dn = new DocumentNode(qdb_->primaryTreeRoot(),
- arg.first,
- Node::ExternalPage,
- Node::ArticlePage);
- dn->setLocation(doc.startLocation());
- return dn;
- }
- else if (command == COMMAND_FILE) {
- DocumentNode* dn = new DocumentNode(qdb_->primaryTreeRoot(),
- arg.first,
- Node::File,
- Node::NoPageType);
- dn->setLocation(doc.startLocation());
- return dn;
+ ExternalPageNode* epn = new ExternalPageNode(qdb_->primaryTreeRoot(), arg.first);
+ epn->setLocation(doc.startLocation());
+ return epn;
}
else if (command == COMMAND_HEADERFILE) {
- DocumentNode* dn = new DocumentNode(qdb_->primaryTreeRoot(),
- arg.first,
- Node::HeaderFile,
- Node::ApiPage);
- dn->setLocation(doc.startLocation());
- return dn;
+ HeaderNode* hn = new HeaderNode(qdb_->primaryTreeRoot(), arg.first);
+ hn->setLocation(doc.startLocation());
+ return hn;
}
else if (command == COMMAND_GROUP) {
CollectionNode* cn = qdb_->addGroup(arg.first);
@@ -350,35 +323,26 @@ Node* CppCodeParser::processTopicCommand(const Doc& doc,
ptype = Node::TutorialPage;
else if (t == "faq")
ptype = Node::FAQPage;
- else if (t == "ditamap")
- ptype = Node::DitaMapPage;
else if (t == "attribution")
ptype = Node::AttributionPage;
}
- DocumentNode* dn = 0;
- if (ptype == Node::DitaMapPage)
- dn = new DitaMapNode(qdb_->primaryTreeRoot(), args[0]);
- else
- dn = new DocumentNode(qdb_->primaryTreeRoot(), args[0], Node::Page, ptype);
- dn->setLocation(doc.startLocation());
- return dn;
- }
- else if (command == COMMAND_DITAMAP) {
- DocumentNode* dn = new DitaMapNode(qdb_->primaryTreeRoot(), arg.first);
- dn->setLocation(doc.startLocation());
- return dn;
- }
- else if ((command == COMMAND_QMLTYPE) || (command == COMMAND_JSTYPE)) {
+ PageNode* pn = new PageNode(qdb_->primaryTreeRoot(), args[0], ptype);
+ pn->setLocation(doc.startLocation());
+ return pn;
+ } else if (command == COMMAND_QMLTYPE) {
QmlTypeNode* qcn = new QmlTypeNode(qdb_->primaryTreeRoot(), arg.first);
- if (command == COMMAND_JSTYPE)
- qcn->setGenus(Node::JS);
qcn->setLocation(doc.startLocation());
return qcn;
- }
- else if ((command == COMMAND_QMLBASICTYPE) || (command == COMMAND_JSBASICTYPE)) {
+ } else if (command == COMMAND_JSTYPE) {
+ QmlTypeNode* qcn = new QmlTypeNode(qdb_->primaryTreeRoot(), arg.first, Node::JsType);
+ qcn->setLocation(doc.startLocation());
+ return qcn;
+ } else if (command == COMMAND_QMLBASICTYPE) {
QmlBasicTypeNode* n = new QmlBasicTypeNode(qdb_->primaryTreeRoot(), arg.first);
- if (command == COMMAND_JSBASICTYPE)
- n->setGenus(Node::JS);
+ n->setLocation(doc.startLocation());
+ return n;
+ } else if (command == COMMAND_JSBASICTYPE) {
+ QmlBasicTypeNode* n = new QmlBasicTypeNode(qdb_->primaryTreeRoot(), arg.first, Node::JsBasicType);
n->setLocation(doc.startLocation());
return n;
}
@@ -554,8 +518,7 @@ void CppCodeParser::processQmlProperties(const Doc& doc,
arg = topics.at(i).args;
if ((topic == COMMAND_QMLPROPERTY) || (topic == COMMAND_QMLATTACHEDPROPERTY) ||
(topic == COMMAND_JSPROPERTY) || (topic == COMMAND_JSATTACHEDPROPERTY)) {
- bool attached = ((topic == COMMAND_QMLATTACHEDPROPERTY) ||
- (topic == COMMAND_JSATTACHEDPROPERTY));
+ bool attached = topic.contains(QLatin1String("attached"));
if (splitQmlPropertyArg(arg, type, module, qmlTypeName, property, doc.location())) {
Aggregate* aggregate = qdb_->findQmlType(module, qmlTypeName);
if (!aggregate)
@@ -625,7 +588,7 @@ void CppCodeParser::processOtherMetaCommand(const Doc& doc,
}
else if (command == COMMAND_REIMP) {
if (node != 0 && node->parent() && !node->parent()->isInternal()) {
- if (node->type() == Node::Function) {
+ if (node->isFunction()) {
FunctionNode *func = (FunctionNode *) node;
if (func->reimplementedFrom().isEmpty() && isWorthWarningAbout(doc)) {
doc.location().warning(tr("Cannot find base function for '\\%1' in %2()")
@@ -653,7 +616,7 @@ void CppCodeParser::processOtherMetaCommand(const Doc& doc,
}
else if (node->parent() != n)
- node->setRelates(static_cast<Aggregate*>(n));
+ node->setRelates(static_cast<PageNode*>(n));
else
doc.location().warning(tr("Invalid use of '\\%1' (already a member of '%2')")
.arg(COMMAND_RELATES, arg));
@@ -667,9 +630,6 @@ void CppCodeParser::processOtherMetaCommand(const Doc& doc,
else if (command == COMMAND_PREVIOUSPAGE) {
setLink(node, Node::PreviousLink, arg);
}
- else if (command == COMMAND_INDEXPAGE) {
- setLink(node, Node::IndexLink, arg);
- }
else if (command == COMMAND_STARTPAGE) {
setLink(node, Node::StartLink, arg);
}
@@ -693,15 +653,15 @@ void CppCodeParser::processOtherMetaCommand(const Doc& doc,
doc.location().warning(tr("\\instantiates is only allowed in \\qmltype"));
}
else if (command == COMMAND_QMLDEFAULT) {
- if (node->type() == Node::QmlProperty) {
+ if (node->nodeType() == Node::QmlProperty) {
QmlPropertyNode* qpn = static_cast<QmlPropertyNode*>(node);
qpn->setDefault();
}
- else if (node->type() == Node::QmlPropertyGroup) {
+ else if (node->nodeType() == Node::QmlPropertyGroup) {
QmlPropertyGroupNode* qpgn = static_cast<QmlPropertyGroupNode*>(node);
NodeList::ConstIterator p = qpgn->childNodes().constBegin();
while (p != qpgn->childNodes().constEnd()) {
- if ((*p)->type() == Node::QmlProperty) {
+ if ((*p)->nodeType() == Node::QmlProperty) {
QmlPropertyNode* qpn = static_cast<QmlPropertyNode*>(*p);
qpn->setDefault();
}
@@ -710,15 +670,15 @@ void CppCodeParser::processOtherMetaCommand(const Doc& doc,
}
}
else if (command == COMMAND_QMLREADONLY) {
- if (node->type() == Node::QmlProperty) {
+ if (node->nodeType() == Node::QmlProperty) {
QmlPropertyNode* qpn = static_cast<QmlPropertyNode*>(node);
qpn->setReadOnly(1);
}
- else if (node->type() == Node::QmlPropertyGroup) {
+ else if (node->nodeType() == Node::QmlPropertyGroup) {
QmlPropertyGroupNode* qpgn = static_cast<QmlPropertyGroupNode*>(node);
NodeList::ConstIterator p = qpgn->childNodes().constBegin();
while (p != qpgn->childNodes().constEnd()) {
- if ((*p)->type() == Node::QmlProperty) {
+ if ((*p)->nodeType() == Node::QmlProperty) {
QmlPropertyNode* qpn = static_cast<QmlPropertyNode*>(*p);
qpn->setReadOnly(1);
}
@@ -1185,9 +1145,7 @@ bool CppCodeParser::parseParameters(const QString& parameters,
/*!
Parse QML/JS signal/method topic commands.
*/
-Node* CppCodeParser::parseOtherFuncArg(const QString& topic,
- const Location& location,
- const QString& funcArg)
+Node* CppCodeParser::parseOtherFuncArg(const QString& topic, const Location& location, const QString& funcArg)
{
QString funcName;
QString returnType;
@@ -1220,24 +1178,11 @@ Node* CppCodeParser::parseOtherFuncArg(const QString& topic,
funcName = colonSplit.last();
Aggregate *aggregate = qdb_->findQmlType(moduleName, elementName);
- bool attached = false;
if (!aggregate)
aggregate = qdb_->findQmlBasicType(moduleName, elementName);
if (!aggregate)
return 0;
- Node::NodeType nodeType = Node::QmlMethod;
- if (topic == COMMAND_QMLSIGNAL || topic == COMMAND_JSSIGNAL) {
- nodeType = Node::QmlSignal;
- } else if (topic == COMMAND_QMLATTACHEDSIGNAL || topic == COMMAND_JSATTACHEDSIGNAL) {
- nodeType = Node::QmlSignal;
- attached = true;
- } else if (topic == COMMAND_QMLATTACHEDMETHOD || topic == COMMAND_JSATTACHEDMETHOD) {
- attached = true;
- } else {
- Q_ASSERT(topic == COMMAND_QMLMETHOD || topic == COMMAND_JSMETHOD);
- }
-
QString params;
QStringList leftParenSplit = funcArg.split('(');
if (leftParenSplit.size() > 1) {
@@ -1245,12 +1190,15 @@ Node* CppCodeParser::parseOtherFuncArg(const QString& topic,
if (rightParenSplit.size() > 0)
params = rightParenSplit[0];
}
- FunctionNode *funcNode = static_cast<FunctionNode*>(new FunctionNode(nodeType, aggregate, funcName, attached));
- funcNode->setAccess(Node::Public);
- funcNode->setLocation(location);
- funcNode->setReturnType(returnType);
- funcNode->setParameters(params);
- return funcNode;
+
+ FunctionNode::Metaness metaness = FunctionNode::getMetanessFromTopic(topic);
+ bool attached = topic.contains(QLatin1String("attached"));
+ FunctionNode *fn = new FunctionNode(metaness, aggregate, funcName, attached);
+ fn->setAccess(Node::Public);
+ fn->setLocation(location);
+ fn->setReturnType(returnType);
+ fn->setParameters(params);
+ return fn;
}
/*!
@@ -1287,13 +1235,12 @@ Node* CppCodeParser::parseMacroArg(const Location& location, const QString& macr
returnType += QChar(' ') + macroName.left(i);
macroName = macroName.mid(i);
}
- newMacroNode = static_cast<FunctionNode*>(new FunctionNode(qdb_->primaryTreeRoot(), macroName));
+ FunctionNode::Metaness metaness = FunctionNode::MacroWithParams;
+ if (params.isEmpty())
+ metaness = FunctionNode::MacroWithoutParams;
+ newMacroNode = new FunctionNode(metaness, qdb_->primaryTreeRoot(), macroName);
newMacroNode->setAccess(Node::Public);
newMacroNode->setLocation(location);
- if (params.isEmpty())
- newMacroNode->setMetaness(FunctionNode::MacroWithoutParams);
- else
- newMacroNode->setMetaness(FunctionNode::MacroWithParams);
newMacroNode->setReturnType(returnType);
newMacroNode->setParameters(params);
if (oldMacroNode && newMacroNode->compare(oldMacroNode)) {
@@ -1304,11 +1251,11 @@ Node* CppCodeParser::parseMacroArg(const Location& location, const QString& macr
return newMacroNode;
}
-void CppCodeParser::createExampleFileNodes(DocumentNode *dn)
+void CppCodeParser::setExampleFileLists(PageNode *pn)
{
- QString examplePath = dn->name();
+ QString examplePath = pn->name();
QString proFileName = examplePath + QLatin1Char('/') + examplePath.split(QLatin1Char('/')).last() + ".pro";
- QString fullPath = Config::findFile(dn->doc().location(),
+ QString fullPath = Config::findFile(pn->doc().location(),
exampleFiles,
exampleDirs,
proFileName);
@@ -1316,13 +1263,13 @@ void CppCodeParser::createExampleFileNodes(DocumentNode *dn)
if (fullPath.isEmpty()) {
QString tmp = proFileName;
proFileName = examplePath + QLatin1Char('/') + "qbuild.pro";
- fullPath = Config::findFile(dn->doc().location(),
+ fullPath = Config::findFile(pn->doc().location(),
exampleFiles,
exampleDirs,
proFileName);
if (fullPath.isEmpty()) {
proFileName = examplePath + QLatin1Char('/') + examplePath.split(QLatin1Char('/')).last() + ".qmlproject";
- fullPath = Config::findFile(dn->doc().location(),
+ fullPath = Config::findFile(pn->doc().location(),
exampleFiles,
exampleDirs,
proFileName);
@@ -1330,8 +1277,8 @@ void CppCodeParser::createExampleFileNodes(DocumentNode *dn)
QString details = QLatin1String("Example directories: ") + exampleDirs.join(QLatin1Char(' '));
if (!exampleFiles.isEmpty())
details += QLatin1String(", example files: ") + exampleFiles.join(QLatin1Char(' '));
- dn->location().warning(tr("Cannot find file '%1' or '%2'").arg(tmp).arg(proFileName), details);
- dn->location().warning(tr(" EXAMPLE PATH DOES NOT EXIST: %1").arg(examplePath), details);
+ pn->location().warning(tr("Cannot find file '%1' or '%2'").arg(tmp).arg(proFileName), details);
+ pn->location().warning(tr(" EXAMPLE PATH DOES NOT EXIST: %1").arg(examplePath), details);
return;
}
}
@@ -1369,20 +1316,15 @@ void CppCodeParser::createExampleFileNodes(DocumentNode *dn)
exampleFiles += Config::getFilesHere(fullPath, "*.qrc *.pro *.qmlproject qmldir");
}
- foreach (const QString &exampleFile, exampleFiles) {
- DocumentNode *fileNode = new DocumentNode(dn,
- exampleFile.mid(sizeOfBoringPartOfName),
- Node::File,
- Node::NoPageType);
- if (fileNode->name().endsWith(".qml"))
- fileNode->setGenus(Node::QML);
- }
- foreach (const QString &imageFile, imageFiles) {
- new DocumentNode(dn,
- imageFile.mid(sizeOfBoringPartOfName),
- Node::Image,
- Node::NoPageType);
- }
+ int i = 0;
+ foreach (const QString &exampleFile, exampleFiles)
+ exampleFiles[i++] = exampleFile.mid(sizeOfBoringPartOfName);
+ i = 0;
+ foreach (const QString &imageFile, imageFiles)
+ imageFiles[i++] = imageFile.mid(sizeOfBoringPartOfName);
+ ExampleNode* en = static_cast<ExampleNode*>(pn);
+ en->setFiles(exampleFiles);
+ en->setImages(imageFiles);
}
/*!
@@ -1439,17 +1381,19 @@ void CppCodeParser::processTopicArgs(const Doc &doc, const QString &topic, NodeL
processQmlProperties(doc, nodes, docs, true);
} else {
ArgList args = doc.metaCommandArgs(topic);
- Node *node = 0;
+ Node *node = nullptr;
if (args.size() == 1) {
- if (topic == COMMAND_FN)
- node = parserForLanguage("Clang")->parseFnArg(doc.location(), args[0].first);
- else if (topic == COMMAND_MACRO)
+ if (topic == COMMAND_FN) {
+ if (showInternal() || !doc.isInternal())
+ node = parserForLanguage("Clang")->parseFnArg(doc.location(), args[0].first);
+ } else if (topic == COMMAND_MACRO) {
node = parseMacroArg(doc.location(), args[0].first);
- else if (isQMLMethodTopic(topic) || isJSMethodTopic(topic))
+ } else if (isQMLMethodTopic(topic) || isJSMethodTopic(topic)) {
node = parseOtherFuncArg(topic, doc.location(), args[0].first);
- else
+ } else {
node = processTopicCommand(doc, topic, args[0]);
- if (node != 0) {
+ }
+ if (node != nullptr) {
nodes.append(node);
docs.append(doc);
}
@@ -1457,15 +1401,18 @@ void CppCodeParser::processTopicArgs(const Doc &doc, const QString &topic, NodeL
QVector<SharedCommentNode*> sharedCommentNodes;
ArgList::ConstIterator arg = args.constBegin();
while (arg != args.constEnd()) {
- if (topic == COMMAND_FN)
- node = parserForLanguage("Clang")->parseFnArg(doc.location(), arg->first);
- else if (topic == COMMAND_MACRO)
+ node = nullptr;
+ if (topic == COMMAND_FN) {
+ if (showInternal() || !doc.isInternal())
+ node = parserForLanguage("Clang")->parseFnArg(doc.location(), arg->first);
+ } else if (topic == COMMAND_MACRO) {
node = parseMacroArg(doc.location(), arg->first);
- else if (isQMLMethodTopic(topic) || isJSMethodTopic(topic))
+ } else if (isQMLMethodTopic(topic) || isJSMethodTopic(topic)) {
node = parseOtherFuncArg(topic, doc.location(), arg->first);
- else
+ } else {
node = processTopicCommand(doc, topic, *arg);
- if (node != 0) {
+ }
+ if (node != nullptr) {
bool found = false;
for (SharedCommentNode *scn : sharedCommentNodes) {
if (scn->parent() == node->parent()) {