logic: multiple fixes and improvements
* showing project name in main window title * keep reference count visible when maximizing code file * show first node in db when no main function is available * log Storage stats after parse * fixed macro locations saved multiply * using NameHierarchy when retrieving ids
This commit is contained in:
+11
-7
@@ -24,6 +24,8 @@ std::shared_ptr<Application> Application::create(ViewFactory* viewFactory)
|
||||
ptr->m_componentManager = ComponentManager::create(viewFactory, ptr->m_storageCache.get());
|
||||
|
||||
ptr->m_mainView = viewFactory->createMainView();
|
||||
ptr->m_mainView->setTitle("Coati");
|
||||
|
||||
ptr->m_componentManager->setup(ptr->m_mainView.get());
|
||||
ptr->m_mainView->loadLayout();
|
||||
|
||||
@@ -71,6 +73,8 @@ void Application::loadProject(const FilePath& projectSettingsFilePath)
|
||||
|
||||
updateRecentProjects(projectSettingsFilePath);
|
||||
|
||||
m_mainView->setTitle(projectSettingsFilePath.fileName());
|
||||
|
||||
m_storageCache->clear();
|
||||
m_componentManager->refreshViews();
|
||||
|
||||
@@ -109,20 +113,20 @@ void Application::handleMessage(MessageFinishedParsing* message)
|
||||
|
||||
m_isInitialParse = false;
|
||||
|
||||
Id mainId = m_storageCache->getIdForNodeWithNameHierarchy(NameHierarchy("main"));
|
||||
Id nodeId = m_storageCache->getIdForNodeWithNameHierarchy(NameHierarchy("main"));
|
||||
|
||||
if (!mainId)
|
||||
if (!nodeId)
|
||||
{
|
||||
mainId = 1;
|
||||
nodeId = m_storageCache->getIdForFirstNode();
|
||||
}
|
||||
|
||||
if (mainId)
|
||||
if (nodeId)
|
||||
{
|
||||
MessageActivateNodes message;
|
||||
message.addNode(
|
||||
mainId,
|
||||
m_storageCache->getNodeTypeForNodeWithId(mainId),
|
||||
m_storageCache->getNameHierarchyForNodeWithId(mainId)
|
||||
nodeId,
|
||||
m_storageCache->getNodeTypeForNodeWithId(nodeId),
|
||||
m_storageCache->getNameHierarchyForNodeWithId(nodeId)
|
||||
);
|
||||
message.isFromSystem = true;
|
||||
message.dispatch();
|
||||
|
||||
@@ -131,8 +131,6 @@ void Project::parseCode()
|
||||
|
||||
void Project::logStats() const
|
||||
{
|
||||
// m_storage->logGraph();
|
||||
// m_storage->logLocations();
|
||||
m_storage->logStats();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
|
||||
std::shared_ptr<TokenLocationFile> locationFile;
|
||||
|
||||
uint refCount;
|
||||
int refCount;
|
||||
|
||||
bool isActive;
|
||||
bool isDeclaration;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef MAIN_VIEW_H
|
||||
#define MAIN_VIEW_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "component/view/ViewLayout.h"
|
||||
|
||||
class MainView: public ViewLayout
|
||||
@@ -10,6 +12,7 @@ public:
|
||||
virtual ~MainView();
|
||||
|
||||
virtual void showStartScreen() = 0;
|
||||
virtual void setTitle(const std::string& title) = 0;
|
||||
};
|
||||
|
||||
#endif // MAIN_VIEW_H
|
||||
|
||||
@@ -188,6 +188,17 @@ void SqliteStorage::removeUnusedNameHierarchyElements()
|
||||
);
|
||||
}
|
||||
|
||||
StorageNode SqliteStorage::getFirstNode() const
|
||||
{
|
||||
std::vector<StorageNode> nodes = getAllNodes("LIMIT 1");
|
||||
if (nodes.size())
|
||||
{
|
||||
return nodes[0];
|
||||
}
|
||||
|
||||
return StorageNode(0, 0, 0);
|
||||
}
|
||||
|
||||
std::vector<StorageNode> SqliteStorage::getAllNodes() const
|
||||
{
|
||||
std::vector<StorageNode> nodes;
|
||||
@@ -680,17 +691,27 @@ Id SqliteStorage::getNodeIdBySignature(const std::string& signature) const
|
||||
|
||||
int SqliteStorage::getNodeCount() const
|
||||
{
|
||||
return m_database.execScalar("SELECT COUNT(*) from node;");
|
||||
return m_database.execScalar("SELECT COUNT(*) FROM node;");
|
||||
}
|
||||
|
||||
int SqliteStorage::getEdgeCount() const
|
||||
{
|
||||
return m_database.execScalar("SELECT COUNT(*) from edge;");
|
||||
return m_database.execScalar("SELECT COUNT(*) FROM edge;");
|
||||
}
|
||||
|
||||
int SqliteStorage::getFileCount() const
|
||||
{
|
||||
return m_database.execScalar("SELECT COUNT(*) FROM file;");
|
||||
}
|
||||
|
||||
int SqliteStorage::getNameHierarchyElementCount() const
|
||||
{
|
||||
return m_database.execScalar("SELECT COUNT(*) from name_hierarchy_element;");
|
||||
return m_database.execScalar("SELECT COUNT(*) FROM name_hierarchy_element;");
|
||||
}
|
||||
|
||||
int SqliteStorage::getSourceLocationCount() const
|
||||
{
|
||||
return m_database.execScalar("SELECT COUNT(*) FROM source_location;");
|
||||
}
|
||||
|
||||
void SqliteStorage::clearTables()
|
||||
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
void removeFile(Id id);
|
||||
void removeUnusedNameHierarchyElements();
|
||||
|
||||
StorageNode getFirstNode() const;
|
||||
std::vector<StorageNode> getAllNodes() const;
|
||||
|
||||
bool isEdge(Id elementId) const;
|
||||
@@ -97,7 +98,9 @@ public:
|
||||
|
||||
int getNodeCount() const;
|
||||
int getEdgeCount() const;
|
||||
int getFileCount() const;
|
||||
int getNameHierarchyElementCount() const;
|
||||
int getSourceLocationCount() const;
|
||||
|
||||
private:
|
||||
void clearTables();
|
||||
|
||||
+40
-30
@@ -93,20 +93,51 @@ void Storage::removeUnusedNames()
|
||||
clearCaches();
|
||||
}
|
||||
|
||||
void Storage::logGraph() const
|
||||
std::vector<FileInfo> Storage::getInfoOnAllFiles() const
|
||||
{
|
||||
std::vector<FileInfo> fileInfos;
|
||||
|
||||
std::vector<StorageFile> storageFiles = m_sqliteStorage.getAllFiles();
|
||||
for (size_t i = 0; i < storageFiles.size(); i++)
|
||||
{
|
||||
boost::posix_time::ptime modificationTime = boost::posix_time::not_a_date_time;
|
||||
if (storageFiles[i].modificationTime != "not-a-date-time")
|
||||
{
|
||||
modificationTime = boost::posix_time::time_from_string(storageFiles[i].modificationTime);
|
||||
}
|
||||
fileInfos.push_back(FileInfo(
|
||||
FilePath(storageFiles[i].filePath),
|
||||
modificationTime
|
||||
));
|
||||
}
|
||||
|
||||
return fileInfos;
|
||||
}
|
||||
|
||||
void Storage::logLocations() const
|
||||
{
|
||||
}
|
||||
|
||||
void Storage::logIndex() const
|
||||
const SearchIndex& Storage::getSearchIndex() const
|
||||
{
|
||||
return m_tokenIndex;
|
||||
}
|
||||
|
||||
void Storage::logStats() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "\nGraph:\n";
|
||||
ss << "\t" << m_sqliteStorage.getNodeCount() << " Nodes\n";
|
||||
ss << "\t" << m_sqliteStorage.getEdgeCount() << " Edges\n";
|
||||
|
||||
ss << "\nSearch:\n";
|
||||
ss << "\t" << m_tokenIndex.getCharCount() << " Characters\n";
|
||||
ss << "\t" << m_tokenIndex.getWordCount() << " Words\n";
|
||||
ss << "\t" << m_tokenIndex.getNodeCount() << " SearchNodes\n";
|
||||
ss << "\t" << m_sqliteStorage.getNameHierarchyElementCount() << " NameHierarchyElements\n";
|
||||
|
||||
ss << "\nCode:\n";
|
||||
ss << "\t" << m_sqliteStorage.getFileCount() << " Files\n";
|
||||
ss << "\t" << m_sqliteStorage.getSourceLocationCount() << " Source Locations\n";
|
||||
|
||||
LOG_WARNING(ss.str());
|
||||
}
|
||||
|
||||
void Storage::startParsing()
|
||||
@@ -704,25 +735,9 @@ Id Storage::getIdForEdge(
|
||||
return m_sqliteStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id;
|
||||
}
|
||||
|
||||
std::vector<FileInfo> Storage::getInfoOnAllFiles() const
|
||||
Id Storage::getIdForFirstNode() const
|
||||
{
|
||||
std::vector<FileInfo> fileInfos;
|
||||
|
||||
std::vector<StorageFile> storageFiles = m_sqliteStorage.getAllFiles();
|
||||
for (size_t i = 0; i < storageFiles.size(); i++)
|
||||
{
|
||||
boost::posix_time::ptime modificationTime = boost::posix_time::not_a_date_time;
|
||||
if (storageFiles[i].modificationTime != "not-a-date-time")
|
||||
{
|
||||
modificationTime = boost::posix_time::time_from_string(storageFiles[i].modificationTime);
|
||||
}
|
||||
fileInfos.push_back(FileInfo(
|
||||
FilePath(storageFiles[i].filePath),
|
||||
modificationTime
|
||||
));
|
||||
}
|
||||
|
||||
return fileInfos;
|
||||
return m_sqliteStorage.getFirstNode().id;
|
||||
}
|
||||
|
||||
NameHierarchy Storage::getNameHierarchyForNodeWithId(Id nodeId) const
|
||||
@@ -796,7 +811,7 @@ std::shared_ptr<Graph> Storage::getGraphForActiveTokenIds(const std::vector<Id>&
|
||||
|
||||
addAggregationEdgesToGraph(elementId, graph);
|
||||
}
|
||||
else
|
||||
else if (m_sqliteStorage.isEdge(elementId))
|
||||
{
|
||||
addEdgeAndAllChildrenToGraph(elementId, graph);
|
||||
}
|
||||
@@ -1129,11 +1144,6 @@ std::shared_ptr<TextAccess> Storage::getFileContent(const FilePath& filePath) co
|
||||
return m_sqliteStorage.getFileContentByPath(filePath.str());
|
||||
}
|
||||
|
||||
const SearchIndex& Storage::getSearchIndex() const
|
||||
{
|
||||
return m_tokenIndex;
|
||||
}
|
||||
|
||||
Id Storage::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, bool distinct)
|
||||
{
|
||||
addNameHierarchyElements(nameHierarchy);
|
||||
|
||||
@@ -32,9 +32,9 @@ public:
|
||||
void clearFileElement(const FilePath& filePath);
|
||||
void removeUnusedNames();
|
||||
|
||||
void logGraph() const;
|
||||
void logLocations() const;
|
||||
void logIndex() const;
|
||||
std::vector<FileInfo> getInfoOnAllFiles() const;
|
||||
const SearchIndex& getSearchIndex() const;
|
||||
|
||||
void logStats() const;
|
||||
|
||||
// ParserClient implementation
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
virtual Id getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const;
|
||||
|
||||
virtual std::vector<FileInfo> getInfoOnAllFiles() const;
|
||||
virtual Id getIdForFirstNode() const;
|
||||
|
||||
virtual NameHierarchy getNameHierarchyForNodeWithId(Id nodeId) const;
|
||||
virtual Node::NodeType getNodeTypeForNodeWithId(Id nodeId) const;
|
||||
@@ -156,8 +156,6 @@ public:
|
||||
|
||||
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
|
||||
|
||||
const SearchIndex& getSearchIndex() const;
|
||||
|
||||
private:
|
||||
Id addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, bool distinct = false);
|
||||
Id addNodeHierarchyWithDistinctSignature(Node::NodeType type, const ParseFunction& function);
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
virtual Id getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const = 0;
|
||||
|
||||
virtual std::vector<FileInfo> getInfoOnAllFiles() const = 0;
|
||||
virtual Id getIdForFirstNode() const = 0;
|
||||
|
||||
virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const = 0;
|
||||
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const = 0;
|
||||
|
||||
@@ -53,19 +53,19 @@ Id StorageAccessProxy::getIdForEdge(
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<FileInfo> StorageAccessProxy::getInfoOnAllFiles() const
|
||||
Id StorageAccessProxy::getIdForFirstNode() const
|
||||
{
|
||||
std::vector<FileInfo> fileInfos;
|
||||
if (hasSubject())
|
||||
{
|
||||
fileInfos = m_subject->getInfoOnAllFiles();
|
||||
return m_subject->getIdForFirstNode();
|
||||
}
|
||||
return fileInfos;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Node::NodeType StorageAccessProxy::getNodeTypeForNodeWithId(Id id) const
|
||||
{
|
||||
if(hasSubject())
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getNodeTypeForNodeWithId(id);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
virtual Id getIdForEdge(
|
||||
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const;
|
||||
|
||||
virtual std::vector<FileInfo> getInfoOnAllFiles() const;
|
||||
virtual Id getIdForFirstNode() const;
|
||||
|
||||
virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const;
|
||||
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const;
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
virtual ~Parser();
|
||||
|
||||
virtual void parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments) = 0;
|
||||
virtual void parseFile(std::shared_ptr<TextAccess> textAccess, const Arguments& arguments) = 0;
|
||||
virtual void parseFile(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess, const Arguments& arguments) = 0;
|
||||
|
||||
protected:
|
||||
ParserClient* m_client;
|
||||
|
||||
@@ -83,8 +83,10 @@ void CxxParser::parseFiles(const std::vector<FilePath>& filePaths, const Argumen
|
||||
}
|
||||
}
|
||||
|
||||
void CxxParser::parseFile(std::shared_ptr<TextAccess> textAccess, const Arguments& arguments)
|
||||
void CxxParser::parseFile(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess, const Arguments& arguments)
|
||||
{
|
||||
setupParsing(std::vector<FilePath>(1, filePath), arguments);
|
||||
|
||||
std::vector<std::string> args = getCommandlineArguments(arguments);
|
||||
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(arguments);
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
|
||||
// ParserClient implementation
|
||||
virtual void parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments);
|
||||
virtual void parseFile(std::shared_ptr<TextAccess> textAccess, const Arguments& arguments);
|
||||
virtual void parseFile(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess, const Arguments& arguments);
|
||||
|
||||
private:
|
||||
std::vector<std::string> getCommandlineArguments(const Arguments& arguments) const;
|
||||
|
||||
@@ -57,7 +57,7 @@ void PreprocessorCallbacks::InclusionDirective(
|
||||
|
||||
const FileManager* fileManager = m_fileRegister->getFileManager();
|
||||
if (fileManager->hasFilePath(baseFilePath) && fileManager->hasFilePath(includedFilePath) &&
|
||||
!m_fileRegister->includeFileIsParsed(baseFilePath))
|
||||
!m_fileRegister->fileIsParsed(baseFilePath))
|
||||
{
|
||||
m_client->onFileIncludeParsed(
|
||||
getParseLocation(fileNameRange.getAsRange()),
|
||||
@@ -77,7 +77,7 @@ void PreprocessorCallbacks::MacroDefined(const clang::Token& macroNameToken, con
|
||||
}
|
||||
|
||||
FilePath filePath = FilePath(fileStr);
|
||||
if (m_fileRegister->getFileManager()->hasFilePath(filePath) && !m_fileRegister->includeFileIsParsed(filePath))
|
||||
if (m_fileRegister->getFileManager()->hasFilePath(filePath) && !m_fileRegister->fileIsParsed(filePath))
|
||||
{
|
||||
// ignore builtin macros
|
||||
if (m_sourceManager.getSpellingLoc(macroNameToken.getLocation()).printToString(m_sourceManager)[0] == '<')
|
||||
@@ -103,7 +103,7 @@ void PreprocessorCallbacks::MacroExpands(
|
||||
}
|
||||
|
||||
FilePath filePath = FilePath(fileStr);
|
||||
if (m_fileRegister->getFileManager()->hasFilePath(filePath) && !m_fileRegister->includeFileIsParsed(filePath))
|
||||
if (m_fileRegister->getFileManager()->hasFilePath(filePath) && !m_fileRegister->fileIsParsed(filePath))
|
||||
{
|
||||
NameHierarchy nameHierarchy;
|
||||
nameHierarchy.push(std::make_shared<NameElement>(macroNameToken.getIdentifierInfo()->getName().str()));
|
||||
|
||||
@@ -18,8 +18,10 @@ void FileRegister::setFilePaths(const std::vector<FilePath>& filePaths)
|
||||
m_sourceFilePaths.clear();
|
||||
m_includeFilePaths.clear();
|
||||
|
||||
for (const FilePath& path : filePaths)
|
||||
for (const FilePath& p : filePaths)
|
||||
{
|
||||
FilePath path = p.exists() ? p.absolute() : p;
|
||||
|
||||
if (m_fileManager->hasSourceExtension(path))
|
||||
{
|
||||
m_sourceFilePaths.emplace(path, STATE_UNPARSED);
|
||||
@@ -41,6 +43,23 @@ std::vector<FilePath> FileRegister::getUnparsedIncludeFilePaths() const
|
||||
return getUnparsedFilePaths(m_includeFilePaths);
|
||||
}
|
||||
|
||||
bool FileRegister::fileIsParsed(const FilePath& filePath) const
|
||||
{
|
||||
std::map<FilePath, ParseState>::const_iterator it = m_includeFilePaths.find(filePath);
|
||||
if (it != m_includeFilePaths.end())
|
||||
{
|
||||
return it->second == STATE_PARSED;
|
||||
}
|
||||
|
||||
it = m_sourceFilePaths.find(filePath);
|
||||
if (it != m_sourceFilePaths.end())
|
||||
{
|
||||
return it->second == STATE_PARSED;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileRegister::includeFileIsParsing(const FilePath& filePath) const
|
||||
{
|
||||
std::map<FilePath, ParseState>::const_iterator it = m_includeFilePaths.find(filePath);
|
||||
|
||||
@@ -21,6 +21,8 @@ public:
|
||||
std::vector<FilePath> getUnparsedSourceFilePaths() const;
|
||||
std::vector<FilePath> getUnparsedIncludeFilePaths() const;
|
||||
|
||||
bool fileIsParsed(const FilePath& filePath) const;
|
||||
|
||||
bool includeFileIsParsing(const FilePath& filePath) const;
|
||||
bool includeFileIsParsed(const FilePath& filePath) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user