1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "profilereader.h"
36 #include <coreplugin/icore.h>
37 #include <coreplugin/messagemanager.h>
39 #include <QtCore/QDir>
40 #include <QtCore/QDebug>
42 using namespace Qt4ProjectManager;
43 using namespace Qt4ProjectManager::Internal;
45 static QString format(const QString &fileName, int lineNo, const QString &msg)
48 return QString::fromLatin1("%1(%2): %3").arg(fileName, QString::number(lineNo), msg);
53 ProMessageHandler::ProMessageHandler(bool verbose)
56 QObject::connect(this, SIGNAL(errorFound(QString)),
57 Core::ICore::instance()->messageManager(), SLOT(printToOutputPane(QString)),
58 Qt::QueuedConnection);
61 void ProMessageHandler::parseError(const QString &fileName, int lineNo, const QString &msg)
63 emit errorFound(format(fileName, lineNo, msg));
66 void ProMessageHandler::configError(const QString &msg)
71 void ProMessageHandler::evalError(const QString &fileName, int lineNo, const QString &msg)
74 emit errorFound(format(fileName, lineNo, msg));
77 void ProMessageHandler::fileMessage(const QString &)
83 ProFileReader::ProFileReader(ProFileOption *option)
84 : ProFileParser(ProFileCacheManager::instance()->cache(), this)
85 , ProFileEvaluator(option, this, this)
90 ProFileReader::~ProFileReader()
92 foreach (ProFile *pf, m_proFiles)
96 void ProFileReader::aboutToEval(ProFile *, ProFile *pro, EvalFileType type)
98 if (m_ignoreLevel || (type != EvalProjectFile && type != EvalIncludeFile)) {
100 } else if (!m_includeFiles.contains(pro->fileName())) {
101 m_includeFiles.insert(pro->fileName(), pro);
102 m_proFiles.append(pro);
107 void ProFileReader::doneWithEval(ProFile *)
113 QList<ProFile*> ProFileReader::includeFiles() const
115 return m_includeFiles.values();
118 ProFile *ProFileReader::proFileFor(const QString &name)
120 return m_includeFiles.value(name);
123 ProFileCacheManager *ProFileCacheManager::s_instance = 0;
125 ProFileCacheManager::ProFileCacheManager(QObject *parent) :
131 m_timer.setInterval(5000);
132 m_timer.setSingleShot(true);
133 connect(&m_timer, SIGNAL(timeout()),
134 this, SLOT(clear()));
137 void ProFileCacheManager::incRefCount()
143 void ProFileCacheManager::decRefCount()
150 ProFileCacheManager::~ProFileCacheManager()
156 ProFileCache *ProFileCacheManager::cache()
159 m_cache = new ProFileCache;
163 void ProFileCacheManager::clear()
165 Q_ASSERT(m_refCount == 0);
166 // Just deleting the cache will be safe as long as the sequence of
167 // obtaining a cache pointer and using it is atomic as far as the main
168 // loop is concerned. Use a shared pointer once this is not true anymore.
173 void ProFileCacheManager::discardFiles(const QString &prefix)
176 m_cache->discardFiles(prefix);
179 void ProFileCacheManager::discardFile(const QString &fileName)
182 m_cache->discardFile(fileName);