Browse Source

Changed a bunch of for loops into the new Qt4 foreach construct.

git-svn-id: file:///var/svn/tigccpp/trunk@1064 9552661e-59e3-4036-b4f2-dbe53926924f
konrad_m 17 years ago
parent
commit
7bc77fe7d5
4 changed files with 45 additions and 96 deletions
  1. 20 44
      ktigcc/completion.cpp
  2. 4 7
      ktigcc/parsing.cpp
  3. 17 37
      ktigcc/preferences.cpp
  4. 4 8
      ktigcc/preferencesdlg.cpp

+ 20 - 44
ktigcc/completion.cpp

@@ -60,9 +60,7 @@ static void findSymbolInSystemHeaders(const QString &symbol,
                                       unsigned &symbolLine,
                                       bool &systemHeader)
 {
-  for (QStringList::ConstIterator it=systemHeaders.begin();
-       it!=systemHeaders.end(); ++it) {
-    const QString &headerName=*it;
+  foreach (QString headerName, systemHeaders) {
     // Avoid infinite recursion.
     if (systemHeaderCompletion.contains(headerName)
         && !systemHeaderCompletion[headerName].searched) {
@@ -108,9 +106,7 @@ static bool findSymbolInFileRecursive(const QString &symbol,
     symbolLine=completionInfo.lineNumbers[symbol];
     return true;
   }
-  for (QStringList::ConstIterator it=completionInfo.included.begin();
-       it!=completionInfo.included.end(); ++it) {
-    const QString &headerName=*it;
+  foreach (QString headerName, completionInfo.included) {
     QString headerText=mainForm->textForHeader(headerName);
     if (!headerText.isNull()) {
       if (!findSymbolInFile(symbol,headerText,headerName,mainForm,symbolFile,
@@ -140,17 +136,13 @@ bool findSymbolInFile(const QString &symbol,
 static void mergeCompletionEntries(QLinkedList<CompletionEntry> &dest,
                                    const QLinkedList<CompletionEntry> &src)
 {
-  for (QLinkedList<CompletionEntry>::ConstIterator it=src.begin();
-       it!=src.end(); ++it)
-    dest.append(*it);
+  foreach (CompletionEntry zod, src) dest.append(zod);
 }
 
 static void completionEntriesForSystemHeaders(const QStringList &systemHeaders,
                                               QLinkedList<CompletionEntry> &result)
 {
-  for (QStringList::ConstIterator it=systemHeaders.begin();
-       it!=systemHeaders.end(); ++it) {
-    const QString &headerName=*it;
+  foreach (QString headerName, systemHeaders) {
     // Avoid infinite recursion.
     if (systemHeaderCompletion.contains(headerName)
         && !systemHeaderCompletion[headerName].searched) {
@@ -180,9 +172,7 @@ static bool completionEntriesForFileRecursive(const QString &fileText,
   completionInfo.searched=true;
   mergeCompletionEntries(result,completionInfo.entries);
   completionEntriesForSystemHeaders(completionInfo.includedSystem,result);
-  for (QStringList::ConstIterator it=completionInfo.included.begin();
-       it!=completionInfo.included.end(); ++it) {
-    const QString &headerName=*it;
+  foreach (QString headerName, completionInfo.included) {
     QString headerText=mainForm->textForHeader(headerName);
     if (!headerText.isNull())
       if (!completionEntriesForFile(headerText,headerName,mainForm,result))
@@ -204,12 +194,10 @@ static QLinkedList<CompletionEntry> sortCompletionEntries(
   const QLinkedList<CompletionEntry> &entries)
 {
   QMap<QString,QLinkedList<CompletionEntry> > map;
-  for (QLinkedList<CompletionEntry>::ConstIterator it=entries.begin();
-       it!=entries.end(); ++it) {
-    const CompletionEntry &entry=*it;
+  foreach (CompletionEntry entry, entries) {
     QLinkedList<CompletionEntry> &list=map[entry.text];
-    if (list.find(entry)==list.end()) list.append(entry);  // TODO QLinkedList::find()
-  }                                                        // doesn't exist AFAICS
+    if (!list.contains(entry)) list.append(entry);
+  }
   QLinkedList<CompletionEntry> result;
   for (QMap<QString,QLinkedList<CompletionEntry> >::ConstIterator
        it=map.begin(); it!=map.end(); ++it)
@@ -268,9 +256,7 @@ static QStringList prototypesForIdentifier(const QString &identifier,
                                           "volatile\n"
                                           "while\n").split('\n',QString::SkipEmptyParts);
   if (!reservedIdentifiers.contains(identifier)) {
-    for (QLinkedList<CompletionEntry>::ConstIterator it=entries.begin();
-         it!=entries.end(); ++it) {
-      const CompletionEntry &entry=*it;
+    foreach (CompletionEntry entry, entries) {
       if (entry.text==identifier) {
         QString prototype=entry.prefix+' '+entry.text+entry.postfix;
         if (result.find(prototype)==result.end()) result.append(prototype);
@@ -282,9 +268,7 @@ static QStringList prototypesForIdentifier(const QString &identifier,
       if (identifierLength>=4) {
         QString identifierUpper=identifier.toUpper();
         QLinkedList<unsigned> distances;
-        for (QLinkedList<CompletionEntry>::ConstIterator it=entries.begin();
-             it!=entries.end(); ++it) {
-          const CompletionEntry &entry=*it;
+        foreach (CompletionEntry entry, entries) {
           QString entryText=entry.text;
           unsigned entryTextLength=entryText.length();
           unsigned minLength=qMin(identifierLength,entryTextLength);
@@ -314,14 +298,12 @@ bool parseHelpSources(QWidget *parent, const QString &directory,
 {
   QDir qdir(directory);
   QStringList headers=qdir.entryList("*.h",QDir::Dirs);
-  for (QStringList::ConstIterator it=headers.begin(); it!=headers.end(); ++it) {
-    const QString &header=*it;
+  foreach (QString header, headers) {
     CompletionInfo &completionInfo=sysHdrCompletion[header];
     QLinkedList<CompletionEntry> &entries=completionInfo.entries;
     QDir hdrQdir(QFileInfo(qdir,header).filePath());
     QStringList hsfs=hdrQdir.entryList("*.hsf *.ref",QDir::Files);
-    for (QStringList::ConstIterator it=hsfs.begin(); it!=hsfs.end(); ++it) {
-      const QString &hsf=*it;
+	foreach (QString hsf, hsfs) {
       QString fileText=loadFileText(QFileInfo(hdrQdir,hsf).filePath());
       if (fileText.isNull()) {
         KMessageBox::error(parent,QString("Can't open \'%1/%2\'.").arg(header)
@@ -342,16 +324,14 @@ bool parseHelpSources(QWidget *parent, const QString &directory,
       }
       CompletionEntry entry;
       QStringList lines=fileText.split('\n');
-      for (QStringList::ConstIterator it=lines.begin(); it!=lines.end(); ++it) {
-        const QString &line=*it;
+      foreach (QString line, lines) {
         if (line.startsWith("Name=")) {
           entry.text=line.mid(5);
           break;
         }
       }
       bool isType=false;
-      for (QStringList::ConstIterator it=lines.begin(); it!=lines.end(); ++it) {
-        const QString &line=*it;
+      foreach (QString line, lines) {
         if (line.startsWith("Type=")) {
           QString hsfType=line.mid(5);
           if (hsfType=="Type") isType=true;
@@ -365,8 +345,7 @@ bool parseHelpSources(QWidget *parent, const QString &directory,
       QRegExp comments("/\\*.*\\*/");
       comments.setMinimal(true);
       QString definition;
-      for (QStringList::ConstIterator it=lines.begin(); it!=lines.end(); ++it) {
-        const QString &line=*it;
+      foreach (QString line, lines) {
         if (line.startsWith("Definition=")) {
           definition=line.mid(11);
           definition.remove(comments);
@@ -466,8 +445,7 @@ bool parseSystemHeaders(QWidget *parent, const QString &directory,
 {
   QDir qdir(directory);
   QStringList headers=qdir.entryList("*.h",QDir::Files);
-  for (QStringList::ConstIterator it=headers.begin(); it!=headers.end(); ++it) {
-    const QString &header=*it;
+  foreach (QString header, headers) {
     QString fileText=loadFileText(QFileInfo(qdir,header).filePath());
     if (fileText.isNull()) {
       KMessageBox::error(parent,QString("Can't open \'%1\'.").arg(header));
@@ -502,8 +480,7 @@ void loadSystemHeaderCompletion(void)
       KMessageBox::Notify|KMessageBox::AllowLink);
   }
   systemHeaderCompletion.clear();
-  for (QStringList::ConstIterator it=groupList.begin(); it!=groupList.end(); ++it) {
-    const QString &key=*it;
+  foreach (QString key, groupList) {
     if (key.endsWith(" Lines")) continue;
     CompletionInfo completionInfo;
     config.setGroup(key);
@@ -541,10 +518,7 @@ void saveSystemHeaderCompletion(void)
     config.setGroup(key);
     config.writeEntry("Included",completionInfo.includedSystem);
     unsigned i=0;
-    for (QLinkedList<CompletionEntry>::ConstIterator it
-         =completionInfo.entries.begin(); it!=completionInfo.entries.end();
-         ++it, i++) {
-      const CompletionEntry &entry=*it;
+	foreach (CompletionEntry entry, completionInfo.entries) {
       config.writeEntry(QString("Entry %1 Type").arg(i),entry.type);
       config.writeEntry(QString("Entry %1 Text").arg(i),entry.text);
       config.writeEntry(QString("Entry %1 Prefix").arg(i),entry.prefix);
@@ -569,6 +543,8 @@ TemplatePopup::TemplatePopup(KTextEditor::View *parent)
   for (QLinkedList<QPair<QString,QString> >::ConstIterator it=preferences.templates.begin();
        it!=preferences.templates.end(); ++it, i++)
     insertItem((*it).first,i);
+//  foreach ((QPair<QString,QString>)zod, preferences.templates) //FIXME: Kevin, I want to do
+//    insertItem(zod.first, i++);                                // this instead, but I get errors
   QPoint pos=parent->cursorPositionCoordinates();
   if (pos.x()<0 || pos.y()<0) {
     // Cursor outside of the view, so center on view instead.

+ 4 - 7
ktigcc/parsing.cpp

@@ -104,8 +104,7 @@ SourceFileFunctions getASMFunctions(const QString &text)
   QStringList lines=text.split('\n');
   unsigned lineno=0;
   SourceFileFunctions result;
-  for (QStringList::Iterator it=lines.begin(); it!=lines.end(); ++it,++lineno) {
-    QString line=*it;
+  foreach (QString line, lines) {
     if (line.isEmpty()) continue;
     QString identifier;
     unsigned col=0, l=line.length();
@@ -130,8 +129,7 @@ CompletionInfo parseFileCompletion(const QString &fileText,
   QStringList lines=fileText.split('\n',QString::SkipEmptyParts);
   bool inComment=false;
   bool isSystemHeader=pathInProject.isNull();
-  for (QStringList::ConstIterator it=lines.begin(); it!=lines.end(); ++it) {
-    const QString &line=(*it);
+  foreach (QString line, lines) {
     if (!inComment) {
       QString strippedLine=line.trimmed();
       if (strippedLine.startsWith("#include")) {
@@ -228,9 +226,8 @@ CompletionInfo parseFileCompletion(const QString &fileText,
         // better information extracted from the .hsf files. However, .hsf files
         // obviously don't contain line number information.
         if (isSystemHeader) {
-          for (QLinkedList<CompletionEntry>::ConstIterator it
-               =result.entries.begin(); it!=result.entries.end(); ++it) {
-            if ((*it).text==identifier) {
+          foreach (CompletionEntry zod, result.entries) {
+            if (zod.text == identifier) {
               alreadyKnown=true;
               break;
             }

+ 17 - 37
ktigcc/preferences.cpp

@@ -101,11 +101,8 @@ static void writeSyntaxXML(const Syn_SettingsForDoc &synprefs,
     (node).appendChild(child)
 
   bool allWordListsCaseInsensitive=TRUE;
-  for (QLinkedList<Syn_WordList>::ConstIterator it=synprefs.wordLists.begin();
-       it!=synprefs.wordLists.end(); ++it) {
-    const Syn_WordList &wordList=*it;
+  foreach (Syn_WordList wordList, synprefs.wordLists)
     if (wordList.caseSensitive) allWordListsCaseInsensitive=FALSE;
-  }
 
   ADD_ATTR(root,"name","TIGCC "+name);
   ADD_ATTR(root,"section","KTIGCC");
@@ -140,9 +137,7 @@ static void writeSyntaxXML(const Syn_SettingsForDoc &synprefs,
           stringList.append(keyword);
       }
     }
-    for (QStringList::ConstIterator it=stringList.begin(); it!=stringList.end();
-         ++it) {
-      const QString &keyword=*it;
+	foreach (QString keyword, stringList) {
       CHILD_NODE(item,list,"item");
       ADD_TEXT(item,keyword);
     }
@@ -153,9 +148,7 @@ static void writeSyntaxXML(const Syn_SettingsForDoc &synprefs,
   ADD_ATTR(defaultContext,"name","Default");
   ADD_ATTR(defaultContext,"attribute","Normal");
   ADD_ATTR(defaultContext,"lineEndContext","#stay");
-  for (QLinkedList<Syn_CustomStyle>::ConstIterator it=synprefs.customStyles.begin();
-       it!=synprefs.customStyles.end(); ++it) {
-    const Syn_CustomStyle &customStyle=*it;
+  foreach (Syn_CustomStyle customStyle, synprefs.customStyles) {
     switch (customStyle.beginning.length()) {
       case 0: // Ignore these ones altogether.
         break;
@@ -192,9 +185,7 @@ static void writeSyntaxXML(const Syn_SettingsForDoc &synprefs,
         break;
     }
   }
-  for (QLinkedList<Syn_WordList>::ConstIterator it=synprefs.wordLists.begin();
-       it!=synprefs.wordLists.end(); ++it) {
-    const Syn_WordList &wordList=*it;
+  foreach (Syn_WordList wordList, synprefs.wordLists) {
     CHILD_NODE(detectWordList,defaultContext,"keyword");
     ADD_ATTR(detectWordList,"attribute",wordList.name);
     ADD_ATTR(detectWordList,"context","#stay");
@@ -392,20 +383,12 @@ static void writeSyntaxXML(const Syn_SettingsForDoc &synprefs,
   DEF_ITEM_DATA("Number",synprefs.numberColor,synprefs.numberStyle);
   DEF_ITEM_DATA("Symbol",synprefs.symbolColor,synprefs.symbolStyle);
   unsigned i=0;
-  for (QLinkedList<QColor>::ConstIterator it=synprefs.parenthesisColors.begin();
-       it!=synprefs.parenthesisColors.end(); ++it, i++) {
-    DEF_ITEM_DATA(QString("Paren%1").arg(i),*it,synprefs.parenthesisStyle);
-  }
-  for (QLinkedList<Syn_CustomStyle>::ConstIterator it=synprefs.customStyles.begin();
-       it!=synprefs.customStyles.end(); ++it) {
-    const Syn_CustomStyle &customStyle=*it;
+  foreach (QColor zod, synprefs.parenthesisColors)
+    DEF_ITEM_DATA(QString("Paren%1").arg(i++),zod,synprefs.parenthesisStyle);
+  foreach (Syn_CustomStyle customStyle, synprefs.customStyles)
     DEF_ITEM_DATA(customStyle.name,customStyle.color,customStyle.style);
-  }
-  for (QLinkedList<Syn_WordList>::ConstIterator it=synprefs.wordLists.begin();
-       it!=synprefs.wordLists.end(); ++it) {
-    const Syn_WordList &wordList=*it;
+  foreach (Syn_WordList wordList, synprefs.wordLists)
     DEF_ITEM_DATA(wordList.name,wordList.color,wordList.style);
-  }
   #undef DEF_ITEM_DATA
 
   CHILD_NODE(keywords,general,"keywords");
@@ -551,17 +534,15 @@ static void saveSyntaxPreference(const Syn_SettingsForDoc &synprefs, const QStri
   pconfig->writeEntry("Enabled",synprefs.enabled);
   pconfig->writeEntry("Number Color",synprefs.numberColor);
   pconfig->writeEntry("Symbol Color",synprefs.symbolColor);
-  for (QLinkedList<QColor>::ConstIterator it=(i=0,synprefs.parenthesisColors.begin());
-       it!=synprefs.parenthesisColors.end(); ++it, i++) {
-    pconfig->writeEntry(QString("Parenthesis Color %1").arg(i),*it);
-  }
+  i=0;
+  foreach (QColor zod, synprefs.parenthesisColors)
+    pconfig->writeEntry(QString("Parenthesis Color %1").arg(i++),zod);
   pconfig->writeEntry("Num Parenthesis Colors",i);
   pconfig->writeEntry("Number Style",(unsigned)synprefs.numberStyle);
   pconfig->writeEntry("Symbol Style",(unsigned)synprefs.symbolStyle);
   pconfig->writeEntry("Parenthesis Style",(unsigned)synprefs.parenthesisStyle);
-  for (QLinkedList<Syn_CustomStyle>::ConstIterator it=(i=0,synprefs.customStyles.begin());
-       it!=synprefs.customStyles.end(); ++it, i++) {
-    const Syn_CustomStyle &customStyle=*it;
+  i=0;
+  foreach (Syn_CustomStyle customStyle, synprefs.customStyles) {
     pconfig->writeEntry(QString("Custom Style %1 Name").arg(i),customStyle.name);
     pconfig->writeEntry(QString("Custom Style %1 Beginning").arg(i),customStyle.beginning);
     pconfig->writeEntry(QString("Custom Style %1 Ending").arg(i),customStyle.ending);
@@ -569,17 +550,16 @@ static void saveSyntaxPreference(const Syn_SettingsForDoc &synprefs, const QStri
     pconfig->writeEntry(QString("Custom Style %1 Switchable").arg(i),customStyle.switchable);
     pconfig->writeEntry(QString("Custom Style %1 Line Start Only").arg(i),customStyle.lineStartOnly);
     pconfig->writeEntry(QString("Custom Style %1 Color").arg(i),customStyle.color);
-    pconfig->writeEntry(QString("Custom Style %1 Style").arg(i),(unsigned)customStyle.style);
+    pconfig->writeEntry(QString("Custom Style %1 Style").arg(i++),(unsigned)customStyle.style);
   }
   pconfig->writeEntry("Num Custom Styles",i);
-  for (QLinkedList<Syn_WordList>::ConstIterator it=(i=0,synprefs.wordLists.begin());
-       it!=synprefs.wordLists.end(); ++it, i++) {
-    const Syn_WordList &wordList=*it;
+  i=0;
+  foreach (Syn_WordList wordList, synprefs.wordLists) {
     pconfig->writeEntry(QString("Word List %1 Name").arg(i),wordList.name);
     pconfig->writeEntry(QString("Word List %1 List").arg(i),wordList.list);
     pconfig->writeEntry(QString("Word List %1 Color").arg(i),wordList.color);
     pconfig->writeEntry(QString("Word List %1 Style").arg(i),(unsigned)wordList.style);
-    pconfig->writeEntry(QString("Word List %1 Case Sensitive").arg(i),wordList.caseSensitive);
+    pconfig->writeEntry(QString("Word List %1 Case Sensitive").arg(i++),wordList.caseSensitive);
   }
   pconfig->writeEntry("Num Word Lists",i);
 }

+ 4 - 8
ktigcc/preferencesdlg.cpp

@@ -329,11 +329,8 @@ void Preferences::syntaxLanguage_activated(int index)
     delete item;
   }  
   item=static_cast<Q3ListViewItem *>(NULL);
-  for (QLinkedList<Syn_WordList>::ConstIterator it=
-         preferences.syn->wordLists.begin();
-       it!=preferences.syn->wordLists.end(); ++it) {
-    item=new RenamableKListViewItem(wordListsItem,item,(*it).name);
-  }
+  foreach (Syn_WordList zod, preferences.syn->wordLists)
+    item=new RenamableKListViewItem(wordListsItem,item,zod.name);
 }
 
 void Preferences::syntaxEnabled_toggled(bool on)
@@ -423,9 +420,8 @@ void Preferences::parenthesisColorsButton_clicked()
 {
   SelectColors selectColors(this);
   selectColors.colorList->clear();
-  for (QLinkedList<QColor>::ConstIterator it=preferences.syn->parenthesisColors.begin();
-       it!=preferences.syn->parenthesisColors.end(); ++it)
-    new ColorListItem(selectColors.colorList,*it);
+  foreach (QColor zod, preferences.syn->parenthesisColors)
+    new ColorListItem(selectColors.colorList,zod);
   selectColors.exec();
   if (selectColors.result()==QDialog::Accepted) {
     preferences.syn->parenthesisColors.clear();