📄 makefiledeps.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the qmake application of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "makefiledeps.h"#include "option.h"#include <qdir.h>#include <qdatetime.h>#include <qfileinfo.h>#include <qbuffer.h>#include <qplatformdefs.h>#if defined(Q_OS_UNIX)# include <unistd.h>#else# include <io.h>#endif#include <qdebug.h>#include <stdio.h>#include <stdlib.h>#include <time.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#if defined(_MSC_VER) && _MSC_VER >= 1400#include <share.h>#endif#if 1#define qmake_endOfLine(c) (c == '\r' || c == '\n')#elseinline bool qmake_endOfLine(const char &c) { return (c == '\r' || c == '\n'); }#endif//#define QMAKE_USE_CACHEQMakeLocalFileName::QMakeLocalFileName(const QString &name) : is_null(name.isNull()){ if(!name.isEmpty()) { if(name.at(0) == QLatin1Char('"') && name.at(name.length()-2) == QLatin1Char('"')) real_name = name.mid(1, name.length()-2); else real_name = name; }}const QString&QMakeLocalFileName::local() const{ if(!is_null && local_name.isNull()) local_name = Option::fixPathToLocalOS(real_name, true); return local_name;}struct SourceDependChildren;struct SourceFile { SourceFile() : deps(0), type(QMakeSourceFileInfo::TYPE_UNKNOWN), mocable(0), traversed(0), exists(1), moc_checked(0), dep_checked(0), included_count(0) { } ~SourceFile(); QMakeLocalFileName file; SourceDependChildren *deps; QMakeSourceFileInfo::SourceFileType type; uint mocable : 1, traversed : 1, exists : 1; uint moc_checked : 1, dep_checked : 1; uchar included_count;};struct SourceDependChildren { SourceFile **children; int num_nodes, used_nodes; SourceDependChildren() : children(0), num_nodes(0), used_nodes(0) { } ~SourceDependChildren() { if(children) free(children); children = 0; } void addChild(SourceFile *s) { if(num_nodes <= used_nodes) { num_nodes += 200; children = (SourceFile**)realloc(children, sizeof(SourceFile*)*(num_nodes)); } children[used_nodes++] = s; }};SourceFile::~SourceFile() { delete deps; }class SourceFiles { int hash(const char *);public: SourceFiles(); ~SourceFiles(); SourceFile *lookupFile(const char *); inline SourceFile *lookupFile(const QString &f) { return lookupFile(f.toLatin1().constData()); } inline SourceFile *lookupFile(const QMakeLocalFileName &f) { return lookupFile(f.local().toLatin1().constData()); } void addFile(SourceFile *, const char *k=0, bool own=true); struct SourceFileNode { SourceFileNode() : key(0), next(0), file(0), own_file(1) { } ~SourceFileNode() { delete [] key; if(own_file) delete file; } char *key; SourceFileNode *next; SourceFile *file; uint own_file : 1; } **nodes; int num_nodes;};SourceFiles::SourceFiles(){ nodes = (SourceFileNode**)malloc(sizeof(SourceFileNode*)*(num_nodes=3037)); for(int n = 0; n < num_nodes; n++) nodes[n] = 0;}SourceFiles::~SourceFiles(){ for(int n = 0; n < num_nodes; n++) { for(SourceFileNode *next = nodes[n]; next;) { SourceFileNode *next_next = next->next; delete next; next = next_next; } } free(nodes);}int SourceFiles::hash(const char *file){ uint h = 0, g; while (*file) { h = (h << 4) + *file; if ((g = (h & 0xf0000000)) != 0) h ^= g >> 23; h &= ~g; file++; } return h;}SourceFile *SourceFiles::lookupFile(const char *file){ int h = hash(file) % num_nodes; for(SourceFileNode *p = nodes[h]; p; p = p->next) { if(!strcmp(p->key, file)) return p->file; } return 0;}void SourceFiles::addFile(SourceFile *p, const char *k, bool own_file){ QByteArray ba = p->file.local().toLatin1(); if(!k) k = ba; int h = hash(k) % num_nodes; SourceFileNode *pn = new SourceFileNode; pn->own_file = own_file; pn->key = qstrdup(k); pn->file = p; pn->next = nodes[h]; nodes[h] = pn;}void QMakeSourceFileInfo::dependTreeWalker(SourceFile *node, SourceDependChildren *place){ if(node->traversed || !node->exists) return; place->addChild(node); node->traversed = true; //set flag if(node->deps) { for(int i = 0; i < node->deps->used_nodes; i++) dependTreeWalker(node->deps->children[i], place); }}void QMakeSourceFileInfo::setDependencyPaths(const QList<QMakeLocalFileName> &l){ // Ensure that depdirs does not contain the same paths several times, to minimize the stats QList<QMakeLocalFileName> ll; for (int i = 0; i < l.count(); ++i) { if (!ll.contains(l.at(i))) ll.append(l.at(i)); } depdirs = ll;}QStringList QMakeSourceFileInfo::dependencies(const QString &file){ QStringList ret; if(!files) return ret; if(SourceFile *node = files->lookupFile(QMakeLocalFileName(file))) { if(node->deps) { /* I stick them into a SourceDependChildren here because it is faster to just iterate over the list to stick them in the list, and reset the flag, then it is to loop over the tree (about 50% faster I saw) --Sam */ SourceDependChildren place; for(int i = 0; i < node->deps->used_nodes; i++) dependTreeWalker(node->deps->children[i], &place); if(place.children) { for(int i = 0; i < place.used_nodes; i++) { place.children[i]->traversed = false; //reset flag ret.append(place.children[i]->file.real()); } } } } return ret;}intQMakeSourceFileInfo::included(const QString &file){ if (!files) return 0; if(SourceFile *node = files->lookupFile(QMakeLocalFileName(file))) return node->included_count; return 0;}bool QMakeSourceFileInfo::mocable(const QString &file){ if(SourceFile *node = files->lookupFile(QMakeLocalFileName(file))) return node->mocable; return false;}QMakeSourceFileInfo::QMakeSourceFileInfo(const QString &cf){ //dep_mode dep_mode = Recursive; //quick project lookups includes = files = 0; files_changed = false; //buffer spare_buffer = 0; spare_buffer_size = 0; //cache cachefile = cf; if(!cachefile.isEmpty()) loadCache(cachefile);}QMakeSourceFileInfo::~QMakeSourceFileInfo(){ //cache if(!cachefile.isEmpty() /*&& files_changed*/) saveCache(cachefile); //buffer if(spare_buffer) { free(spare_buffer); spare_buffer = 0; spare_buffer_size = 0; } //quick project lookup delete files; delete includes;}void QMakeSourceFileInfo::setCacheFile(const QString &cf){ cachefile = cf; loadCache(cachefile);}void QMakeSourceFileInfo::addSourceFiles(const QStringList &l, uchar seek, QMakeSourceFileInfo::SourceFileType type){ for(int i=0; i<l.size(); ++i) addSourceFile(l.at(i), seek, type);}void QMakeSourceFileInfo::addSourceFile(const QString &f, uchar seek, QMakeSourceFileInfo::SourceFileType type){ if(!files) files = new SourceFiles; QMakeLocalFileName fn(f); SourceFile *file = files->lookupFile(fn); if(!file) { file = new SourceFile;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -