📄 util.cpp
字号:
// and usingNamespaces and usingClass to determine which typedefs // are in-scope, so it will not be very efficient :-( QCString srcAType=trimTemplateSpecifiers(namespaceName,className,srcA->type); QCString dstAType=trimTemplateSpecifiers(namespaceName,className,dstA->type); if (srcAType.left(6)=="class ") srcAType=srcAType.right(srcAType.length()-6); if (dstAType.left(6)=="class ") dstAType=dstAType.right(dstAType.length()-6); // allow distingishing "const A" from "const B" even though // from a syntactic point of view they would be two names of the same // type "const". This is not fool prove ofcourse, but should at least // catch the most common cases. if ((srcAType=="const" || srcAType=="volatile") && !srcA->name.isEmpty()) { srcAType+=" "; srcAType+=srcA->name; } if ((dstAType=="const" || dstAType=="volatile") && !dstA->name.isEmpty()) { dstAType+=" "; dstAType+=dstA->name; } if (srcA->name=="const" || srcA->name=="volatile") { srcAType+=srcA->name; } if (dstA->name=="const" || dstA->name=="volatile") { dstAType+=dstA->name; } stripIrrelevantConstVolatile(srcAType); stripIrrelevantConstVolatile(dstAType); srcAType = removeRedundantWhiteSpace(srcAType); dstAType = removeRedundantWhiteSpace(dstAType); //srcAType=stripTemplateSpecifiersFromScope(srcAType,FALSE); //dstAType=stripTemplateSpecifiersFromScope(dstAType,FALSE); //printf("srcA=%s:%s dstA=%s:%s\n",srcAType.data(),srcA->name.data(), // dstAType.data(),dstA->name.data()); if (srcA->array!=dstA->array) // nomatch for char[] against char { NOMATCH return FALSE; } if (srcAType!=dstAType) // check if the argument only differs on name { // remove a namespace scope that is only in one type // (assuming a using statement was used) trimNamespaceScope(srcAType,dstAType,namespaceName); //QCString srcScope; //QCString dstScope; // strip redundant scope specifiers if (!className.isEmpty()) { srcAType=trimScope(className,srcAType); dstAType=trimScope(className,dstAType); //printf("trimScope: `%s' <=> `%s'\n",srcAType.data(),dstAType.data()); ClassDef *cd; if (!namespaceName.isEmpty()) cd=getClass(namespaceName+"::"+className); else cd=getClass(className); if (cd && cd->baseClasses()->count()>0) { trimBaseClassScope(cd->baseClasses(),srcAType); trimBaseClassScope(cd->baseClasses(),dstAType); } //printf("trimBaseClassScope: `%s' <=> `%s'\n",srcAType.data(),dstAType.data()); } if (!namespaceName.isEmpty()) { srcAType=trimScope(namespaceName,srcAType); dstAType=trimScope(namespaceName,dstAType); } if (usingNamespaces && usingNamespaces->count()>0) { NamespaceListIterator nli(*usingNamespaces); NamespaceDef *nd; for (;(nd=nli.current());++nli) { srcAType=trimScope(nd->name(),srcAType); dstAType=trimScope(nd->name(),dstAType); } } if (usingClasses && usingClasses->count()>0) { ClassListIterator cli(*usingClasses); ClassDef *cd; for (;(cd=cli.current());++cli) { srcAType=trimScope(cd->name(),srcAType); dstAType=trimScope(cd->name(),dstAType); } } if (!srcA->name.isEmpty() && !dstA->type.isEmpty() && (srcAType+" "+srcA->name)==dstAType) { MATCH return TRUE; } else if (!dstA->name.isEmpty() && !srcA->type.isEmpty() && (dstAType+" "+dstA->name)==srcAType) { MATCH return TRUE; } //printf("2. srcA=%s:%s dstA=%s:%s\n",srcAType.data(),srcA->name.data(), // dstAType.data(),dstA->name.data()); uint srcPos=0,dstPos=0; bool equal=TRUE; while (srcPos<srcAType.length() && dstPos<dstAType.length() && equal) { equal=srcAType.at(srcPos)==dstAType.at(dstPos); if (equal) srcPos++,dstPos++; } if (srcPos<srcAType.length() && dstPos<dstAType.length()) { // if nothing matches or the match ends in the middle or at the // end of a string then there is no match if (srcPos==0 || dstPos==0) { NOMATCH return FALSE; } if (isId(srcAType.at(srcPos)) && isId(dstAType.at(dstPos))) { // check if a name if already found -> if no then there is no match if (!srcA->name.isEmpty() || !dstA->name.isEmpty()) { NOMATCH return FALSE; } while (srcPos<srcAType.length() && isId(srcAType.at(srcPos))) srcPos++; while (dstPos<dstAType.length() && isId(dstAType.at(dstPos))) dstPos++; if (srcPos<srcAType.length() || dstPos<dstAType.length()) { NOMATCH return FALSE; } } else { // otherwise we assume that a name starts at the current position. while (srcPos<srcAType.length() && isId(srcAType.at(srcPos))) srcPos++; while (dstPos<dstAType.length() && isId(dstAType.at(dstPos))) dstPos++; // if nothing more follows for both types then we assume we have // found a match. Note that now `signed int' and `signed' match, but // seeing that int is not a name can only be done by looking at the // semantics. if (srcPos!=srcAType.length() || dstPos!=dstAType.length()) { NOMATCH return FALSE; } } } else if (dstPos<dstAType.length()) { if (!isspace(dstAType.at(dstPos))) // maybe the names differ { if (!dstA->name.isEmpty()) // dst has its name separated from its type { NOMATCH return FALSE; } while (dstPos<dstAType.length() && isId(dstAType.at(dstPos))) dstPos++; if (dstPos!=dstAType.length()) { NOMATCH return FALSE; // more than a difference in name -> no match } } else // maybe dst has a name while src has not { dstPos++; while (dstPos<dstAType.length() && isId(dstAType.at(dstPos))) dstPos++; if (dstPos!=dstAType.length()) { NOMATCH return FALSE; // nope not a name -> no match } } } else if (srcPos<srcAType.length()) { if (!isspace(srcAType.at(srcPos))) // maybe the names differ { if (!srcA->name.isEmpty()) // src has its name separated from its type { NOMATCH return FALSE; } while (srcPos<srcAType.length() && isId(srcAType.at(srcPos))) srcPos++; if (srcPos!=srcAType.length()) { NOMATCH return FALSE; // more than a difference in name -> no match } } else // maybe src has a name while dst has not { srcPos++; while (srcPos<srcAType.length() && isId(srcAType.at(srcPos))) srcPos++; if (srcPos!=srcAType.length()) { NOMATCH return FALSE; // nope not a name -> no match } } } } MATCH return TRUE;}static void mergeArgument(Argument *srcA,Argument *dstA, const QCString &className, const QCString &namespaceName, NamespaceList *usingNamespaces, ClassList *usingClasses){ //printf("merge argument start %s:%s <-> %s:%s\n", // srcA->type.data(),srcA->name.data(), // dstA->type.data(),dstA->name.data()); if ((srcA->type=="const" || srcA->type=="volatile") && !srcA->name.isEmpty()) { srcA->type+=" "; srcA->type+=srcA->name; srcA->name.resize(0); } if ((dstA->type=="const" || dstA->type=="volatile") && !dstA->name.isEmpty()) { dstA->type+=" "; dstA->type+=dstA->name; dstA->name.resize(0); } if (srcA->name=="const" || srcA->name=="volatile") { srcA->type+=" "; srcA->type+=srcA->name; srcA->type=removeRedundantWhiteSpace(srcA->type); srcA->name.resize(0); } if (dstA->name=="const" || dstA->name=="volatile") { dstA->type+=" "; dstA->type+=dstA->name; dstA->type=removeRedundantWhiteSpace(dstA->type); dstA->name.resize(0); } QCString srcAType=trimTemplateSpecifiers(namespaceName,className,srcA->type); QCString dstAType=trimTemplateSpecifiers(namespaceName,className,dstA->type); if (srcAType.left(6)=="class ") srcAType=srcAType.right(srcAType.length()-6); if (dstAType.left(6)=="class ") dstAType=dstAType.right(dstAType.length()-6); stripIrrelevantConstVolatile(srcAType); stripIrrelevantConstVolatile(dstAType); if (srcAType!=dstAType) // check if the argument only differs on name { //printf("scope=`%s': `%s' <=> `%s'\n",className.data(),srcAType.data(),dstAType.data()); // remove a namespace scope that is only in one type // (assuming a using statement was used) trimNamespaceScope(srcAType,dstAType,namespaceName); //QCString srcScope; //QCString dstScope; // strip redundant scope specifiers if (!className.isEmpty()) { srcAType=trimScope(className,srcAType); dstAType=trimScope(className,dstAType); //printf("trimScope: `%s' <=> `%s'\n",srcAType.data(),dstAType.data()); ClassDef *cd; if (!namespaceName.isEmpty()) cd=getClass(namespaceName+"::"+className); else cd=getClass(className); if (cd && cd->baseClasses()->count()>0) { trimBaseClassScope(cd->baseClasses(),srcAType); trimBaseClassScope(cd->baseClasses(),dstAType); } //printf("trimBaseClassScope: `%s' <=> `%s'\n",srcAType.data(),dstAType.data()); } if (!namespaceName.isEmpty()) { srcAType=trimScope(namespaceName,srcAType); dstAType=trimScope(namespaceName,dstAType); } if (usingNamespaces && usingNamespaces->count()>0) { NamespaceListIterator nli(*usingNamespaces); NamespaceDef *nd; for (;(nd=nli.current());++nli) { srcAType=trimScope(nd->name(),srcAType); dstAType=trimScope(nd->name(),dstAType); } } if (usingClasses && usingClasses->count()>0) { ClassListIterator cli(*usingClasses); ClassDef *cd; for (;(cd=cli.current());++cli) { srcAType=trimScope(cd->name(),srcAType); dstAType=trimScope(cd->name(),dstAType); } } if (!srcA->name.isEmpty() && !dstA->type.isEmpty() && (srcAType+" "+srcA->name)==dstAType) { srcA->type=srcAType+" "+srcA->name; srcA->name.resize(0); goto done; } else if (!dstA->name.isEmpty() && !srcA->type.isEmpty() && (dstAType+" "+dstA->name)==srcAType) { dstA->type=dstAType+" "+dstA->name; dstA->name.resize(0); goto done; } //printf("srcA=%s::%s dstA=%s::%s\n",srcAType.data(),srcA->name.data(), // dstAType.data(),dstA->name.data()); uint srcPos=0,dstPos=0; bool equal=TRUE; while (srcPos<srcAType.length() && dstPos<dstAType.length() && equal) { equal=srcAType.at(srcPos)==dstAType.at(dstPos); if (equal) srcPos++,dstPos++; } if (srcPos<srcAType.length() && dstPos<dstAType.length()) { // if nothing matches or the match ends in the middle or at the // end of a string then there is no match int srcStart=srcPos; int dstStart=dstPos; if (isId(srcAType.at(srcPos)) && isId(dstAType.at(dstPos))) { // find the start of the name while (srcStart>=0 && isId(srcAType.at(srcStart))) srcStart--; while (dstStart>=0 && isId(dstAType.at(dstStart))) dstStart--; if (srcStart>0) // move the name from the type to the name field { srcA->name=srcAType.right(srcAType.length()-srcStart-1); srcA->type=srcAType.left(srcStart+1).stripWhiteSpace(); } if (dstStart>0) // move the name from the type to the name field { dstA->name=dstAType.right(dstAType.length()-dstStart-1); dstA->type=dstAType.left(dstStart+1).stripWhiteSpace(); } } else { dstA->name=dstAType.right(dstAType.length()-dstStart); dstA->type=dstAType.left(dstStart).stripWhiteSpace(); srcA->name=srcAType.right(dstAType.length()-srcStart); srcA->type=srcAType.left(srcStart).stripWhiteSpace(); } } else if (dstPos<dstAType.length()) { if (!isspace(dstAType.at(dstPos))) // maybe the names differ { int startPos=dstPos; while (startPos>=0 && isId(dstAType.at(startPos))) startPos--; if (startPos>0) { dstA->name=dstAType.right(dstAType.length()-startPos-1); dstA->type=dstAType.left(startPos+1).stripWhiteSpace(); } } else // maybe dst has a name while src has not { dstPos++; int startPos=dstPos; dstA->name=dstAType.right(dstAType.length()-startPos); dstA->type=dstAType.left(startPos).stripWhiteSpace(); } } else if (srcPos<srcAType.length()) { if (!isspace(srcAType.at(srcPos))) // maybe the names differ { int startPos=srcPos; while (startPos>=0 && isId(srcAType.at(startPos))) startPos--; if (startPos>0) { srcA->name=srcAType.right(srcAType.length()-startPos-1); srcA->type=srcAType.left(startPos+1).stripWhiteSpace(); } } else // maybe src has a name while dst has not { srcPos++; int startPos=srcPos; srcA->name=srcAType.right(srcAType.length()-startPos); srcA->type=srcAType.left(startPos).stripWhiteSpace(); } } goto done; } //printf("match exactly\n"); if (srcA->name.isEmpty() && dstA->name.isEmpty()) // arguments match exactly but no name -> // see if we can find the name { int i=srcAType.length()-1; while (i>=0 && isId(srcAType.at(i))) i--; if (i>0 && i<(int)srcAType.length()-1 && srcAType.at(i)!=':') // there is (probably) a name { QCString srcAName=srcAType.right(srcAType.length()-i-1); QCString dstAName=dstAType.right(dstAType.length()-i-1); if (srcAName!="const" && srcAName!="volatile" && dstAName!="const" && dstAName!="volatile") { srcA->name=srcAName; srcA->type=srcAType.left(i+1).stripWhiteSpace(); dstA->name=dstAName; dstA->type=dstAType.left(i+1).stripWhiteSpace(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -