void PPToken::squeeze() { std::set<wxString> alreadyReplacedMacros; // perform the squeeze 5 times max for(size_t count=0; count < 5; count++) { bool modified(false); // get list of possible macros in the replacement wxArrayString tmpWords = TokenizeWords(replacement); wxArrayString words; // make sure that a word is not been replaced more than once // this will avoid recursion // an example (taken from qglobal.h of the Qt library): // // #define qDebug QT_NO_QDEBUG_MACRO // #define QT_NO_QDEBUG_MACRO if(1); else qDebug // for(size_t i=0; i<tmpWords.size(); i++) { if(alreadyReplacedMacros.find(tmpWords.Item(i)) == alreadyReplacedMacros.end()){ alreadyReplacedMacros.insert(tmpWords[i]); words.Add(tmpWords[i]); } } for(size_t i=0; i<words.size(); i++) { PPToken tok = PPTable::Instance()->Token(words.Item(i)); if(tok.flags & IsValid) { if(tok.flags & IsFunctionLike) { int where = replacement.Find(words.Item(i)); if(where != wxNOT_FOUND) { wxString initList; wxArrayString initListArr; if(readInitList( replacement, where + words.Item(i).Length(), initList, initListArr )) { tok.expandOnce(initListArr); replacement.Remove(where, words.Item(i).Length() + initList.Length()); tok.replacement.Replace(wxT("##"), wxT("")); replacement.insert(where, tok.replacement); modified = true; } } } else { if(replacement.Replace(words.Item(i), tok.replacement)) { modified = true; } } } } if(!modified) break; } replacement.Replace(wxT("##"), wxT("")); }
wxString TagEntry::NameFromTyperef(wxString& templateInitList, bool nameIncludeTemplate) { wxString typeref = GetTyperef(); if(typeref.IsEmpty() == false) { wxString name = typeref.AfterFirst(wxT(':')); return name; } // incase our entry is a typedef, and it is not marked as typeref, // try to get the real name from the pattern if(GetKind() == wxT("typedef")) { wxString pat(GetPattern()); if(!GetPattern().Contains(wxT("typedef"))) { // The pattern does not contain 'typedef' however this *is* a typedef // try to see if this is a macro pat.StartsWith(wxT("/^"), &pat); pat.Trim().Trim(false); // we take the first token CppScanner scanner; scanner.SetText(pat.To8BitData()); int type = scanner.yylex(); if(type == IDENTIFIER) { wxString token = wxString::From8BitData(scanner.YYText()); PPToken tok = TagsManagerST::Get()->GetDatabase()->GetMacro(token); if(tok.flags & PPToken::IsValid) { // we found a match! if(tok.flags & PPToken::IsFunctionLike) { wxArrayString argList; if(GetMacroArgList(scanner, argList)) { tok.expandOnce(argList); } } pat = tok.replacement; pat << wxT(";"); // Remove double spaces while(pat.Replace(wxT(" "), wxT(" "))) { } } } } wxString name; if(TypedefFromPattern(pat, GetName(), name, templateInitList, nameIncludeTemplate)) return name; } return wxEmptyString; }