data: indexing java
* expanded appsettings to include java specific stuff * added java indexer as separate project that can be build via its build script * added dependencies for java indexer to the setup folder * added license files for these dependencies. * added sample project for java. this is just to test java on other machines and can be removed again in the future. * the java parser test suite is currently uncommented because java is not running on every machine. * added some more node types * removed TokenComponentAccess::AccessType and replaced all its usages by using AccessKind * moved access components from edges to nodes * using recordReference of ParserClient for java * removed recording access specifier of inheritance edges. * added styles for new node types
This commit is contained in:
+15
-2
@@ -128,7 +128,15 @@ add_files(
|
||||
|
||||
data/parser/cxx/TaskParseCxx.h
|
||||
data/parser/cxx/TaskParseWrapper.h
|
||||
|
||||
|
||||
data/parser/java/JavaEnvironment.cpp
|
||||
data/parser/java/JavaEnvironment.h
|
||||
data/parser/java/JavaEnvironmentFactory.cpp
|
||||
data/parser/java/JavaEnvironmentFactory.h
|
||||
data/parser/java/TaskParseJava.h
|
||||
|
||||
data/parser/AccessKind.cpp
|
||||
data/parser/AccessKind.h
|
||||
data/parser/ParseLocation.cpp
|
||||
data/parser/ParseLocation.h
|
||||
data/parser/Parser.cpp
|
||||
@@ -137,7 +145,10 @@ add_files(
|
||||
data/parser/ParserClient.h
|
||||
data/parser/ParserClientImpl.cpp
|
||||
data/parser/ParserClientImpl.h
|
||||
data/parser/SymbolType.h
|
||||
data/parser/ReferenceKind.cpp
|
||||
data/parser/ReferenceKind.h
|
||||
data/parser/SymbolKind.cpp
|
||||
data/parser/SymbolKind.h
|
||||
|
||||
data/search/SearchIndex.cpp
|
||||
data/search/SearchIndex.h
|
||||
@@ -279,6 +290,8 @@ add_files(
|
||||
|
||||
utility/scheduling/Task.cpp
|
||||
utility/scheduling/Task.h
|
||||
utility/scheduling/TaskDecorator.cpp
|
||||
utility/scheduling/TaskDecorator.h
|
||||
utility/scheduling/TaskGroup.cpp
|
||||
utility/scheduling/TaskGroup.h
|
||||
utility/scheduling/TaskGroupParallel.cpp
|
||||
|
||||
+67
-11
@@ -4,6 +4,8 @@
|
||||
#include "data/graph/Token.h"
|
||||
#include "data/parser/cxx/TaskParseCxx.h"
|
||||
#include "data/parser/cxx/TaskParseWrapper.h"
|
||||
#include "data/parser/java/JavaEnvironmentFactory.h"
|
||||
#include "data/parser/java/TaskParseJava.h"
|
||||
#include "data/PersistentStorage.h"
|
||||
#include "data/TaskCleanStorage.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
@@ -16,6 +18,7 @@
|
||||
#include "utility/scheduling/TaskGroupSequential.h"
|
||||
#include "utility/scheduling/TaskGroupParallel.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/Version.h"
|
||||
|
||||
std::shared_ptr<Project> Project::create(StorageAccessProxy* storageAccessProxy)
|
||||
@@ -144,24 +147,78 @@ void Project::parseCode()
|
||||
std::shared_ptr<FileRegister> fileRegister = std::make_shared<FileRegister>(&m_fileManager, indexerThreadCount > 1);
|
||||
fileRegister->setFilePaths(filesToParse);
|
||||
|
||||
std::shared_ptr<TaskGroupParallel> taskParallel = std::make_shared<TaskGroupParallel>();
|
||||
if (ProjectSettings::getInstance()->getLanguage() == "Java")
|
||||
{
|
||||
if (!JavaEnvironmentFactory::getInstance())
|
||||
{
|
||||
JavaEnvironmentFactory::createInstance(
|
||||
"data/java/asm-5.0.3.jar;"
|
||||
"data/java/cglib-3.1.jar;"
|
||||
"data/java/easymock-3.3.1.jar;"
|
||||
"data/java/guava-18.0.jar;"
|
||||
"data/java/hamcrest-core-1.3.jar;"
|
||||
"data/java/java-indexer.jar;"
|
||||
"data/java/javaparser-core-2.4.1-SNAPSHOT.jar;"
|
||||
"data/java/javaslang-2.0.0-beta.jar;"
|
||||
"data/java/javassist-3.19.0-GA.jar;"
|
||||
"data/java/java-symbol-solver-core-0.2.0-SNAPSHOT.jar;"
|
||||
"data/java/java-symbol-solver-logic-0.2.0-SNAPSHOT.jar;"
|
||||
"data/java/java-symbol-solver-model-0.2.0-SNAPSHOT.jar;"
|
||||
"data/java/objenesis-2.1.jar;"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
taskSequential->addTask(std::make_shared<TaskParseWrapper>(
|
||||
taskParallel,
|
||||
std::shared_ptr<TaskParseWrapper> taskParserWrapper = std::make_shared<TaskParseWrapper>(
|
||||
m_storage.get(),
|
||||
fileRegister
|
||||
));
|
||||
);
|
||||
taskSequential->addTask(taskParserWrapper);
|
||||
|
||||
std::shared_ptr<TaskGroupParallel> taskParallelIndexing = std::make_shared<TaskGroupParallel>();
|
||||
taskParserWrapper->setTask(taskParallelIndexing);
|
||||
|
||||
std::shared_ptr<std::mutex> storageMutex = std::make_shared<std::mutex>();
|
||||
|
||||
for (int i = 0; i < indexerThreadCount; i++)
|
||||
{
|
||||
taskParallel->addTask(std::make_shared<TaskParseCxx>(
|
||||
m_storage.get(),
|
||||
storageMutex,
|
||||
fileRegister,
|
||||
getParserArguments()
|
||||
));
|
||||
if (ProjectSettings::getInstance()->getLanguage() == "Java")
|
||||
{
|
||||
std::shared_ptr<ProjectSettings> projSettings = ProjectSettings::getInstance();
|
||||
|
||||
Parser::Arguments arguments;
|
||||
|
||||
for (FilePath classpath: projSettings->getAbsoluteJavaClasspaths())
|
||||
{
|
||||
arguments.javaClassPaths.push_back(classpath.str());
|
||||
}
|
||||
|
||||
for (FilePath sourcePath: projSettings->getAbsoluteSourcePaths())
|
||||
{
|
||||
if (sourcePath.extension().empty())
|
||||
{
|
||||
arguments.javaClassPaths.push_back(sourcePath.str());
|
||||
}
|
||||
}
|
||||
|
||||
taskParallelIndexing->addTask(
|
||||
std::make_shared<TaskParseJava>(
|
||||
m_storage.get(),
|
||||
storageMutex,
|
||||
fileRegister,
|
||||
arguments
|
||||
)
|
||||
);
|
||||
}
|
||||
else // c or cxx
|
||||
{
|
||||
taskParallelIndexing->addTask(std::make_shared<TaskParseCxx>(
|
||||
m_storage.get(),
|
||||
storageMutex,
|
||||
fileRegister,
|
||||
getParserArguments()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Task::dispatch(taskSequential);
|
||||
@@ -247,7 +304,6 @@ Parser::Arguments Project::getParserArguments() const
|
||||
Parser::Arguments args;
|
||||
|
||||
utility::append(args.compilerFlags, projSettings->getCompilerFlags());
|
||||
utility::append(args.compilerFlags, appSettings->getCompilerFlags());
|
||||
|
||||
// Add the source paths as HeaderSearchPaths as well, so clang will also look here when searching include files.
|
||||
utility::append(args.systemHeaderSearchPaths, m_fileManager.getSourcePaths());
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "component/view/GraphView.h"
|
||||
#include "component/view/GraphViewStyle.h"
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "data/parser/AccessKind.h"
|
||||
#include "data/graph/Graph.h"
|
||||
|
||||
GraphController::GraphController(StorageAccess* storageAccess)
|
||||
@@ -278,31 +279,14 @@ std::shared_ptr<DummyNode> GraphController::createDummyNodeTopDown(Node* node, I
|
||||
{
|
||||
DummyNode* parent = nullptr;
|
||||
|
||||
Edge* edge = child->getMemberEdge();
|
||||
TokenComponentAccess* access = edge->getComponent<TokenComponentAccess>();
|
||||
TokenComponentAccess::AccessType accessType = TokenComponentAccess::ACCESS_NONE;
|
||||
TokenComponentAccess* access = child->getComponent<TokenComponentAccess>();
|
||||
|
||||
if (access)
|
||||
{
|
||||
accessType = access->getAccess();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (node->isType(Node::NODE_TYPE | Node::NODE_CLASS | Node::NODE_STRUCT))
|
||||
{
|
||||
accessType = TokenComponentAccess::ACCESS_PUBLIC;
|
||||
}
|
||||
else
|
||||
{
|
||||
parent = result.get();
|
||||
}
|
||||
}
|
||||
|
||||
if (accessType != TokenComponentAccess::ACCESS_NONE)
|
||||
if (access && access->getAccess() != ACCESS_NONE)
|
||||
{
|
||||
AccessKind accessKind = access->getAccess();
|
||||
for (std::shared_ptr<DummyNode> dummy : result->subNodes)
|
||||
{
|
||||
if (dummy->accessType == accessType)
|
||||
if (dummy->accessKind == accessKind)
|
||||
{
|
||||
parent = dummy.get();
|
||||
break;
|
||||
@@ -312,12 +296,15 @@ std::shared_ptr<DummyNode> GraphController::createDummyNodeTopDown(Node* node, I
|
||||
if (!parent)
|
||||
{
|
||||
std::shared_ptr<DummyNode> accessNode = std::make_shared<DummyNode>();
|
||||
accessNode->accessType = accessType;
|
||||
accessNode->accessKind = accessKind;
|
||||
result->subNodes.push_back(accessNode);
|
||||
parent = accessNode.get();
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
parent = result.get();
|
||||
}
|
||||
parent->subNodes.push_back(createDummyNodeTopDown(child, parentId));
|
||||
}
|
||||
);
|
||||
@@ -853,7 +840,10 @@ void GraphController::bundleNodesByType()
|
||||
}
|
||||
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_NAMESPACE, "Namespaces");
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_PACKAGE, "Packages");
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_BUILTIN_TYPE, "Builtin Types");
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_CLASS, "Classes");
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_INTERFACE, "Interfaces");
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_STRUCT, "Structs");
|
||||
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_FUNCTION, "Functions");
|
||||
@@ -872,6 +862,7 @@ void GraphController::bundleNodesByType()
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_FIELD, "Fields");
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_ENUM_CONSTANT, "Enum Constants");
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_TEMPLATE_PARAMETER_TYPE, "Template Parameter Types");
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_TYPE_PARAMETER, "Type Parameters");
|
||||
BUNDLE_BY_TYPE(nodes, Node::NODE_UNDEFINED, "Undefined Symbols");
|
||||
|
||||
for (std::shared_ptr<DummyNode> node : m_dummyNodes)
|
||||
@@ -918,7 +909,7 @@ void GraphController::layoutNestingRecursive(DummyNode* node) const
|
||||
}
|
||||
else if (node->isAccessNode())
|
||||
{
|
||||
margins = GraphViewStyle::getMarginsOfAccessNode(node->accessType);
|
||||
margins = GraphViewStyle::getMarginsOfAccessNode(node->accessKind);
|
||||
}
|
||||
else if (node->isExpandToggleNode())
|
||||
{
|
||||
@@ -944,7 +935,7 @@ void GraphController::layoutNestingRecursive(DummyNode* node) const
|
||||
|
||||
width = margins.charWidth * node->name.size();
|
||||
|
||||
if (node->data->isType(Node::NODE_TYPE | Node::NODE_CLASS | Node::NODE_STRUCT | Node::NODE_ENUM) &&
|
||||
if (node->data->isType(Node::NODE_TYPE | Node::NODE_BUILTIN_TYPE | Node::NODE_CLASS | Node::NODE_STRUCT | Node::NODE_ENUM) &&
|
||||
node->subNodes.size())
|
||||
{
|
||||
addExpandToggleNode(node);
|
||||
@@ -1178,6 +1169,9 @@ void GraphController::forEachDummyEdge(std::function<void(DummyEdge*)> func)
|
||||
|
||||
void GraphController::handleMessage(MessageColorSchemeTest* message)
|
||||
{
|
||||
// todo: add nodes: package, interface, type_parameter, builtin_type
|
||||
// todo: add edges: EDGE_TYPE_ARGUMENT, EDGE_IMPORT
|
||||
// todo: add access: TYPE_PARAMETER
|
||||
clear();
|
||||
|
||||
std::shared_ptr<Graph> graph = std::make_shared<Graph>();
|
||||
@@ -1205,15 +1199,15 @@ void GraphController::handleMessage(MessageColorSchemeTest* message)
|
||||
createNodes(60, Node::NODE_FILE);
|
||||
createNodes(70, Node::NODE_MACRO);
|
||||
|
||||
std::function<Node*(Node*, Id, Node::NodeType, std::string, TokenComponentAccess::AccessType)> createChild(
|
||||
[&](Node* parent, Id id, Node::NodeType type, std::string name, TokenComponentAccess::AccessType access)
|
||||
std::function<Node*(Node*, Id, Node::NodeType, std::string, AccessKind)> createChild(
|
||||
[&](Node* parent, Id id, Node::NodeType type, std::string name, AccessKind access)
|
||||
{
|
||||
Node* node = graph->createNode(id + 1000, type, NameHierarchy(name), true);
|
||||
Edge* edge = graph->createEdge(id + 10000, Edge::EDGE_MEMBER, parent, node);
|
||||
|
||||
if (access != TokenComponentAccess::ACCESS_NONE)
|
||||
if (access != ACCESS_NONE)
|
||||
{
|
||||
edge->addComponentAccess(std::make_shared<TokenComponentAccess>(access));
|
||||
node->addComponentAccess(std::make_shared<TokenComponentAccess>(access));
|
||||
}
|
||||
|
||||
return node;
|
||||
@@ -1225,8 +1219,7 @@ void GraphController::handleMessage(MessageColorSchemeTest* message)
|
||||
{
|
||||
Node* enumNode = graph->createNode(id, Node::NODE_ENUM,
|
||||
NameHierarchy(name + Node::getTypeString(Node::NODE_ENUM)), true);
|
||||
createChild(enumNode, id + 10, Node::NODE_ENUM_CONSTANT, name + Node::getTypeString(Node::NODE_ENUM_CONSTANT),
|
||||
TokenComponentAccess::ACCESS_NONE);
|
||||
createChild(enumNode, id + 10, Node::NODE_ENUM_CONSTANT, name + Node::getTypeString(Node::NODE_ENUM_CONSTANT), ACCESS_NONE);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1245,17 +1238,15 @@ void GraphController::handleMessage(MessageColorSchemeTest* message)
|
||||
|
||||
if (type == Node::NODE_CLASS)
|
||||
{
|
||||
createChild(classNode, id, Node::NODE_TEMPLATE_PARAMETER_TYPE, name + "temp_param",
|
||||
TokenComponentAccess::ACCESS_TEMPLATE);
|
||||
createChild(classNode, id, Node::NODE_TEMPLATE_PARAMETER_TYPE, name + "temp_param", ACCESS_TEMPLATE_PARAMETER);
|
||||
}
|
||||
|
||||
createChild(classNode, id + 10, Node::NODE_METHOD, name + "method", TokenComponentAccess::ACCESS_PUBLIC);
|
||||
createChild(classNode, id + 10, Node::NODE_METHOD, name + "method", ACCESS_PUBLIC);
|
||||
if (type == Node::NODE_CLASS)
|
||||
{
|
||||
createChild(classNode, id + 30, Node::NODE_METHOD, name + "method",
|
||||
TokenComponentAccess::ACCESS_PROTECTED);
|
||||
createChild(classNode, id + 30, Node::NODE_METHOD, name + "method", ACCESS_PROTECTED);
|
||||
}
|
||||
createChild(classNode, id + 60, Node::NODE_FIELD, name + "field", TokenComponentAccess::ACCESS_PRIVATE);
|
||||
createChild(classNode, id + 60, Node::NODE_FIELD, name + "field", ACCESS_PRIVATE);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1284,8 +1275,7 @@ void GraphController::handleMessage(MessageColorSchemeTest* message)
|
||||
{
|
||||
Node* classNode = graph->createNode(id + 101, Node::NODE_CLASS,
|
||||
NameHierarchy(name + Node::getTypeString(Node::NODE_CLASS)), true);
|
||||
originNode = createChild(classNode, id + 111, Node::NODE_METHOD, name + Edge::getTypeString(type),
|
||||
TokenComponentAccess::ACCESS_PUBLIC);
|
||||
originNode = createChild(classNode, id + 111, Node::NODE_METHOD, name + Edge::getTypeString(type), ACCESS_PUBLIC);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1297,8 +1287,7 @@ void GraphController::handleMessage(MessageColorSchemeTest* message)
|
||||
{
|
||||
Node* classNode = graph->createNode(id + 201, Node::NODE_CLASS,
|
||||
NameHierarchy(name + Node::getTypeString(Node::NODE_CLASS)), true);
|
||||
targetNode = createChild(classNode, id + 211, Node::NODE_METHOD, name + Edge::getTypeString(type),
|
||||
TokenComponentAccess::ACCESS_PUBLIC);
|
||||
targetNode = createChild(classNode, id + 211, Node::NODE_METHOD, name + Edge::getTypeString(type), ACCESS_PUBLIC);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1331,20 +1320,18 @@ void GraphController::handleMessage(MessageColorSchemeTest* message)
|
||||
createEdges( 100000, Edge::EDGE_CALL, Node::NODE_FUNCTION, Node::NODE_FUNCTION);
|
||||
createEdges( 200000, Edge::EDGE_USAGE, Node::NODE_GLOBAL_VARIABLE, Node::NODE_GLOBAL_VARIABLE);
|
||||
createEdges( 300000, Edge::EDGE_TYPE_USAGE, Node::NODE_FUNCTION, Node::NODE_TYPE);
|
||||
createEdges( 400000, Edge::EDGE_TYPE_OF, Node::NODE_GLOBAL_VARIABLE, Node::NODE_TYPE);
|
||||
|
||||
createEdges( 500000, Edge::EDGE_TYPEDEF_OF, Node::NODE_TYPEDEF, Node::NODE_TYPE);
|
||||
createEdges( 600000, Edge::EDGE_AGGREGATION, Node::NODE_TYPE, Node::NODE_TYPE);
|
||||
createEdges( 700000, Edge::EDGE_INCLUDE, Node::NODE_FILE, Node::NODE_FILE);
|
||||
createEdges( 800000, Edge::EDGE_MACRO_USAGE, Node::NODE_MACRO, Node::NODE_MACRO);
|
||||
createEdges( 400000, Edge::EDGE_AGGREGATION, Node::NODE_TYPE, Node::NODE_TYPE);
|
||||
createEdges( 500000, Edge::EDGE_INCLUDE, Node::NODE_FILE, Node::NODE_FILE);
|
||||
createEdges( 600000, Edge::EDGE_MACRO_USAGE, Node::NODE_MACRO, Node::NODE_MACRO);
|
||||
|
||||
createEdges( 900000, Edge::EDGE_INHERITANCE, Node::NODE_CLASS, Node::NODE_CLASS);
|
||||
createEdges(1000000, Edge::EDGE_OVERRIDE, Node::NODE_METHOD, Node::NODE_METHOD);
|
||||
createEdges( 700000, Edge::EDGE_INHERITANCE, Node::NODE_CLASS, Node::NODE_CLASS);
|
||||
createEdges( 800000, Edge::EDGE_OVERRIDE, Node::NODE_METHOD, Node::NODE_METHOD);
|
||||
|
||||
createEdges(1100000, Edge::EDGE_TEMPLATE_ARGUMENT, Node::NODE_TYPE, Node::NODE_TYPE);
|
||||
createEdges(1200000, Edge::EDGE_TEMPLATE_DEFAULT_ARGUMENT, Node::NODE_TYPE, Node::NODE_TYPE);
|
||||
createEdges(1300000, Edge::EDGE_TEMPLATE_SPECIALIZATION_OF, Node::NODE_TYPE, Node::NODE_TYPE);
|
||||
createEdges(1400000, Edge::EDGE_TEMPLATE_MEMBER_SPECIALIZATION_OF, Node::NODE_METHOD, Node::NODE_METHOD);
|
||||
createEdges( 900000, Edge::EDGE_TEMPLATE_ARGUMENT, Node::NODE_TYPE, Node::NODE_TYPE);
|
||||
createEdges(1000000, Edge::EDGE_TEMPLATE_DEFAULT_ARGUMENT, Node::NODE_TYPE, Node::NODE_TYPE);
|
||||
createEdges(1100000, Edge::EDGE_TEMPLATE_SPECIALIZATION_OF, Node::NODE_TYPE, Node::NODE_TYPE);
|
||||
createEdges(1200000, Edge::EDGE_TEMPLATE_MEMBER_SPECIALIZATION_OF, Node::NODE_METHOD, Node::NODE_METHOD);
|
||||
|
||||
std::vector<Id> focusedTokenIds;
|
||||
std::vector<Id> activeTokenIds;
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
, connected(false)
|
||||
, expanded(false)
|
||||
, hasParent(true)
|
||||
, accessType(TokenComponentAccess::ACCESS_NONE)
|
||||
, accessKind(ACCESS_NONE)
|
||||
, invisibleSubNodeCount(0)
|
||||
, layoutBucket(0, 0)
|
||||
, bundledNodeCount(0)
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
|
||||
bool isAccessNode() const
|
||||
{
|
||||
return accessType != TokenComponentAccess::ACCESS_NONE;
|
||||
return accessKind != ACCESS_NONE;
|
||||
}
|
||||
|
||||
bool isExpandToggleNode() const
|
||||
@@ -223,7 +223,7 @@ public:
|
||||
bool hasParent;
|
||||
|
||||
// AccessNode
|
||||
TokenComponentAccess::AccessType accessType;
|
||||
AccessKind accessKind;
|
||||
|
||||
// ExpandToggleNode
|
||||
size_t invisibleSubNodeCount;
|
||||
|
||||
@@ -130,12 +130,16 @@ size_t GraphViewStyle::getFontSizeForNodeType(Node::NodeType type)
|
||||
{
|
||||
case Node::NODE_UNDEFINED:
|
||||
case Node::NODE_NAMESPACE:
|
||||
case Node::NODE_PACKAGE:
|
||||
case Node::NODE_TYPE:
|
||||
case Node::NODE_BUILTIN_TYPE:
|
||||
case Node::NODE_STRUCT:
|
||||
case Node::NODE_CLASS:
|
||||
case Node::NODE_INTERFACE:
|
||||
case Node::NODE_ENUM:
|
||||
case Node::NODE_TYPEDEF:
|
||||
case Node::NODE_TEMPLATE_PARAMETER_TYPE:
|
||||
case Node::NODE_TYPE_PARAMETER:
|
||||
case Node::NODE_FILE:
|
||||
case Node::NODE_MACRO:
|
||||
return s_fontSize;
|
||||
@@ -194,10 +198,14 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType
|
||||
margins.iconWidth = s_fontSize + 11;
|
||||
case Node::NODE_UNDEFINED:
|
||||
case Node::NODE_NAMESPACE:
|
||||
case Node::NODE_PACKAGE:
|
||||
case Node::NODE_TYPE:
|
||||
case Node::NODE_BUILTIN_TYPE:
|
||||
case Node::NODE_STRUCT:
|
||||
case Node::NODE_CLASS:
|
||||
case Node::NODE_INTERFACE:
|
||||
case Node::NODE_TEMPLATE_PARAMETER_TYPE:
|
||||
case Node::NODE_TYPE_PARAMETER:
|
||||
if (hasChildren)
|
||||
{
|
||||
margins.left = margins.right = 10;
|
||||
@@ -237,7 +245,7 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType
|
||||
return margins;
|
||||
}
|
||||
|
||||
GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode(TokenComponentAccess::AccessType type)
|
||||
GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode(AccessKind access)
|
||||
{
|
||||
NodeMargins margins;
|
||||
margins.spacingX = margins.spacingY = 8;
|
||||
@@ -246,21 +254,22 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode(TokenComponen
|
||||
margins.top = 40;
|
||||
margins.bottom = 10;
|
||||
|
||||
switch (type)
|
||||
switch (access)
|
||||
{
|
||||
case TokenComponentAccess::ACCESS_NONE:
|
||||
case ACCESS_NONE:
|
||||
margins.minWidth = 30;
|
||||
break;
|
||||
case TokenComponentAccess::ACCESS_PUBLIC:
|
||||
case ACCESS_PUBLIC:
|
||||
margins.minWidth = 56;
|
||||
break;
|
||||
case TokenComponentAccess::ACCESS_PROTECTED:
|
||||
case ACCESS_PROTECTED:
|
||||
margins.minWidth = 72;
|
||||
break;
|
||||
case TokenComponentAccess::ACCESS_PRIVATE:
|
||||
case ACCESS_PRIVATE:
|
||||
margins.minWidth = 58;
|
||||
break;
|
||||
case TokenComponentAccess::ACCESS_TEMPLATE:
|
||||
case ACCESS_TEMPLATE_PARAMETER:
|
||||
case ACCESS_TYPE_PARAMETER:
|
||||
margins.minWidth = 133;
|
||||
break;
|
||||
}
|
||||
@@ -299,12 +308,16 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
|
||||
style.borderDashed = true;
|
||||
|
||||
case Node::NODE_NAMESPACE:
|
||||
case Node::NODE_PACKAGE:
|
||||
case Node::NODE_TYPE:
|
||||
case Node::NODE_BUILTIN_TYPE:
|
||||
case Node::NODE_STRUCT:
|
||||
case Node::NODE_CLASS:
|
||||
case Node::NODE_INTERFACE:
|
||||
case Node::NODE_ENUM:
|
||||
case Node::NODE_TYPEDEF:
|
||||
case Node::NODE_TEMPLATE_PARAMETER_TYPE:
|
||||
case Node::NODE_TYPE_PARAMETER:
|
||||
case Node::NODE_FILE:
|
||||
case Node::NODE_MACRO:
|
||||
if (hasChildren)
|
||||
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
static std::string getFontNameOfExpandToggleNode();
|
||||
|
||||
static NodeMargins getMarginsForNodeType(Node::NodeType type, bool hasChildren);
|
||||
static NodeMargins getMarginsOfAccessNode(TokenComponentAccess::AccessType type);
|
||||
static NodeMargins getMarginsOfAccessNode(AccessKind access);
|
||||
static NodeMargins getMarginsOfExpandToggleNode();
|
||||
static NodeMargins getMarginsOfBundleNode();
|
||||
|
||||
|
||||
@@ -121,9 +121,9 @@ void IntermediateStorage::addSourceLocation(Id elementId, Id fileNodeId, uint st
|
||||
));
|
||||
}
|
||||
|
||||
void IntermediateStorage::addComponentAccess(Id edgeId, int type)
|
||||
void IntermediateStorage::addComponentAccess(Id nodeId, int type)
|
||||
{
|
||||
m_componentAccesses.push_back(StorageComponentAccess(edgeId, type));
|
||||
m_componentAccesses.push_back(StorageComponentAccess(nodeId, type));
|
||||
}
|
||||
|
||||
void IntermediateStorage::addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol)
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
virtual Id addEdge(int type, Id sourceId, Id targetId);
|
||||
virtual Id addLocalSymbol(const std::string& name);
|
||||
virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
virtual void addComponentAccess(Id edgeId , int type);
|
||||
virtual void addComponentAccess(Id nodeId , int type);
|
||||
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
|
||||
virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol);
|
||||
|
||||
|
||||
@@ -119,9 +119,9 @@ void PersistentStorage::addSourceLocation(
|
||||
);
|
||||
}
|
||||
|
||||
void PersistentStorage::addComponentAccess(Id edgeId , int type)
|
||||
void PersistentStorage::addComponentAccess(Id nodeId , int type)
|
||||
{
|
||||
m_sqliteStorage.addComponentAccess(edgeId, type);
|
||||
m_sqliteStorage.addComponentAccess(nodeId, type);
|
||||
}
|
||||
|
||||
void PersistentStorage::addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol)
|
||||
@@ -668,8 +668,14 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForAll() const
|
||||
for (StorageNode node: m_sqliteStorage.getAllNodes())
|
||||
{
|
||||
if (intToDefinitionType(node.definitionType) == DEFINITION_EXPLICIT &&
|
||||
(!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(node.id) ||
|
||||
Node::intToType(node.type) == Node::NODE_NAMESPACE))
|
||||
(
|
||||
!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(node.id) ||
|
||||
(
|
||||
Node::intToType(node.type) == Node::NODE_NAMESPACE || // TODO: use & here
|
||||
Node::intToType(node.type) == Node::NODE_PACKAGE
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
tokenIds.push_back(node.id);
|
||||
}
|
||||
@@ -701,7 +707,8 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(const std::v
|
||||
|
||||
if (node.id > 0)
|
||||
{
|
||||
if (Node::intToType(node.type) == Node::NODE_NAMESPACE)
|
||||
if (Node::intToType(node.type) == Node::NODE_NAMESPACE || // TODO: use & here
|
||||
Node::intToType(node.type) == Node::NODE_PACKAGE)
|
||||
{
|
||||
ids.clear();
|
||||
m_hierarchyCache.addFirstChildIdsForNodeId(elementId, &ids);
|
||||
@@ -1352,27 +1359,21 @@ void PersistentStorage::addComponentAccessToGraph(Graph* graph) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::vector<Id> memberEdgeIds;
|
||||
|
||||
graph->forEachEdge(
|
||||
[&memberEdgeIds](Edge* edge)
|
||||
std::vector<Id> nodeIds;
|
||||
graph->forEachNode(
|
||||
[&nodeIds](Node* node)
|
||||
{
|
||||
if (!edge->isType(Edge::EDGE_MEMBER))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
memberEdgeIds.push_back(edge->getId());
|
||||
nodeIds.push_back(node->getId());
|
||||
}
|
||||
);
|
||||
|
||||
std::vector<StorageComponentAccess> accesses = m_sqliteStorage.getComponentAccessByMemberEdgeIds(memberEdgeIds);
|
||||
std::vector<StorageComponentAccess> accesses = m_sqliteStorage.getComponentAccessesByNodeIds(nodeIds);
|
||||
for (const StorageComponentAccess& access : accesses)
|
||||
{
|
||||
if (access.memberEdgeId && access.type)
|
||||
if (access.nodeId != 0)
|
||||
{
|
||||
graph->getEdgeById(access.memberEdgeId)->addComponentAccess(
|
||||
std::make_shared<TokenComponentAccess>(TokenComponentAccess::intToType(access.type)));
|
||||
graph->getNodeById(access.nodeId)->addComponentAccess(
|
||||
std::make_shared<TokenComponentAccess>(intToAccessKind(access.type)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
virtual Id addEdge(int type, Id sourceId, Id targetId);
|
||||
virtual Id addLocalSymbol(const std::string& name);
|
||||
virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
virtual void addComponentAccess(Id edgeId , int type);
|
||||
virtual void addComponentAccess(Id nodeId , int type);
|
||||
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
|
||||
virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/Version.h"
|
||||
|
||||
const size_t SqliteStorage::STORAGE_VERSION = 1;
|
||||
const size_t SqliteStorage::STORAGE_VERSION = 2;
|
||||
|
||||
SqliteStorage::SqliteStorage(const FilePath& dbFilePath)
|
||||
: m_dbFilePath(dbFilePath)
|
||||
@@ -178,11 +178,11 @@ Id SqliteStorage::addSourceLocation(
|
||||
return m_database.lastRowId();
|
||||
}
|
||||
|
||||
Id SqliteStorage::addComponentAccess(Id memberEdgeId, int type)
|
||||
Id SqliteStorage::addComponentAccess(Id nodeId, int type)
|
||||
{
|
||||
m_database.execDML((
|
||||
"INSERT INTO component_access(id, edge_id, type) "
|
||||
"VALUES (NULL, " + std::to_string(memberEdgeId) + ", " + std::to_string(type) + ");"
|
||||
"INSERT INTO component_access(id, node_id, type) "
|
||||
"VALUES (NULL, " + std::to_string(nodeId) + ", " + std::to_string(type) + ");"
|
||||
).c_str());
|
||||
|
||||
return m_database.lastRowId();
|
||||
@@ -534,14 +534,14 @@ Id SqliteStorage::getElementIdByLocationId(Id locationId) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
StorageComponentAccess SqliteStorage::getComponentAccessByMemberEdgeId(Id memberEdgeId) const
|
||||
StorageComponentAccess SqliteStorage::getComponentAccessByNodeId(Id nodeId) const
|
||||
{
|
||||
return getFirst<StorageComponentAccess>("WHERE edge_id == " + std::to_string(memberEdgeId));
|
||||
return getFirst<StorageComponentAccess>("WHERE node_id == " + std::to_string(nodeId));
|
||||
}
|
||||
|
||||
std::vector<StorageComponentAccess> SqliteStorage::getComponentAccessByMemberEdgeIds(const std::vector<Id>& memberEdgeIds) const
|
||||
std::vector<StorageComponentAccess> SqliteStorage::getComponentAccessesByNodeIds(const std::vector<Id>& nodeIds) const
|
||||
{
|
||||
return getAll<StorageComponentAccess>("WHERE edge_id IN (" + utility::join(utility::toStrings(memberEdgeIds), ',') + ")");
|
||||
return getAll<StorageComponentAccess>("WHERE node_id IN (" + utility::join(utility::toStrings(nodeIds), ',') + ")");
|
||||
}
|
||||
|
||||
std::vector<StorageCommentLocation> SqliteStorage::getCommentLocationsInFile(const FilePath& filePath) const
|
||||
@@ -722,13 +722,13 @@ void SqliteStorage::setupTables()
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS component_access("
|
||||
"id INTEGER NOT NULL, "
|
||||
"edge_id INTEGER, "
|
||||
"node_id INTEGER, "
|
||||
"type INTEGER NOT NULL, "
|
||||
"PRIMARY KEY(id), "
|
||||
"FOREIGN KEY(edge_id) REFERENCES edge(id) ON DELETE CASCADE);"
|
||||
"FOREIGN KEY(node_id) REFERENCES node(id) ON DELETE CASCADE);"
|
||||
);
|
||||
|
||||
SqliteIndex("component_access_edge_id_index", "component_access(edge_id)").createOnDatabase(m_database);
|
||||
SqliteIndex("component_access_node_id_index", "component_access(node_id)").createOnDatabase(m_database);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS comment_location("
|
||||
@@ -965,7 +965,7 @@ template <>
|
||||
std::vector<StorageComponentAccess> SqliteStorage::getAll<StorageComponentAccess>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT id, edge_id, type FROM component_access " + query + ";"
|
||||
"SELECT id, node_id, type FROM component_access " + query + ";"
|
||||
).c_str());
|
||||
|
||||
std::vector<StorageComponentAccess> componentAccesses;
|
||||
@@ -973,12 +973,12 @@ std::vector<StorageComponentAccess> SqliteStorage::getAll<StorageComponentAccess
|
||||
while (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const Id edgeId = q.getIntField(1, 0);
|
||||
const Id nodeId = q.getIntField(1, 0);
|
||||
const int type = q.getIntField(2, -1);
|
||||
|
||||
if (id != 0 && edgeId != 0 && type != -1)
|
||||
if (id != 0 && nodeId != 0 && type != -1)
|
||||
{
|
||||
componentAccesses.push_back(StorageComponentAccess(edgeId, type));
|
||||
componentAccesses.push_back(StorageComponentAccess(nodeId, type));
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
Id addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime);
|
||||
Id addLocalSymbol(const std::string& name);
|
||||
Id addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
|
||||
Id addComponentAccess(Id memberEdgeId, int type);
|
||||
Id addComponentAccess(Id nodeId, int type);
|
||||
Id addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
|
||||
Id addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint lineNumber, uint columnNumber);
|
||||
|
||||
@@ -94,8 +94,8 @@ public:
|
||||
|
||||
Id getElementIdByLocationId(Id locationId) const;
|
||||
|
||||
StorageComponentAccess getComponentAccessByMemberEdgeId(Id memberEdgeId) const;
|
||||
std::vector<StorageComponentAccess> getComponentAccessByMemberEdgeIds(const std::vector<Id>& memberEdgeIds) const;
|
||||
StorageComponentAccess getComponentAccessByNodeId(Id memberEdgeId) const;
|
||||
std::vector<StorageComponentAccess> getComponentAccessesByNodeIds(const std::vector<Id>& memberEdgeIds) const;
|
||||
|
||||
void optimizeMemory() const;
|
||||
|
||||
|
||||
@@ -132,14 +132,14 @@ void Storage::inject(Storage* injected)
|
||||
[&](const StorageComponentAccess& injectedData)
|
||||
{
|
||||
std::unordered_map<Id, Id>::const_iterator it;
|
||||
it = injectedIdToOwnId.find(injectedData.memberEdgeId);
|
||||
it = injectedIdToOwnId.find(injectedData.nodeId);
|
||||
if (it == injectedIdToOwnId.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Id ownMemberEdgeId = it->second;
|
||||
Id ownNodeId = it->second;
|
||||
|
||||
addComponentAccess(ownMemberEdgeId, injectedData.type);
|
||||
addComponentAccess(ownNodeId, injectedData.type);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
virtual Id addEdge(int type, Id sourceId, Id targetId) = 0;
|
||||
virtual Id addLocalSymbol(const std::string& name) = 0;
|
||||
virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) = 0;
|
||||
virtual void addComponentAccess(Id edgeId , int type) = 0;
|
||||
virtual void addComponentAccess(Id nodeId , int type) = 0;
|
||||
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) = 0;
|
||||
virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol) = 0;
|
||||
|
||||
|
||||
@@ -125,16 +125,16 @@ struct StorageSourceLocation
|
||||
struct StorageComponentAccess
|
||||
{
|
||||
StorageComponentAccess()
|
||||
: memberEdgeId(0)
|
||||
: nodeId(0)
|
||||
, type(0)
|
||||
{}
|
||||
|
||||
StorageComponentAccess(Id memberEdgeId, int type)
|
||||
: memberEdgeId(memberEdgeId)
|
||||
StorageComponentAccess(Id nodeId, int type)
|
||||
: nodeId(nodeId)
|
||||
, type(type)
|
||||
{}
|
||||
|
||||
Id memberEdgeId;
|
||||
Id nodeId;
|
||||
int type;
|
||||
};
|
||||
|
||||
|
||||
+28
-63
@@ -17,45 +17,39 @@ Edge::EdgeType Edge::intToType(int value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 0x1:
|
||||
case EDGE_MEMBER:
|
||||
return EDGE_MEMBER;
|
||||
case 0x2:
|
||||
return EDGE_TYPE_OF;
|
||||
case 0x4:
|
||||
return EDGE_RETURN_TYPE_OF;
|
||||
case 0x8:
|
||||
return EDGE_PARAMETER_TYPE_OF;
|
||||
case 0x10:
|
||||
case EDGE_TYPE_USAGE:
|
||||
return EDGE_TYPE_USAGE;
|
||||
case 0x20:
|
||||
case EDGE_USAGE:
|
||||
return EDGE_USAGE;
|
||||
case 0x40:
|
||||
case EDGE_CALL:
|
||||
return EDGE_CALL;
|
||||
case 0x80:
|
||||
case EDGE_INHERITANCE:
|
||||
return EDGE_INHERITANCE;
|
||||
case 0x100:
|
||||
case EDGE_OVERRIDE:
|
||||
return EDGE_OVERRIDE;
|
||||
case 0x200:
|
||||
return EDGE_TYPEDEF_OF;
|
||||
case 0x400:
|
||||
return EDGE_TEMPLATE_PARAMETER;
|
||||
case 0x800:
|
||||
case EDGE_TEMPLATE_ARGUMENT:
|
||||
return EDGE_TEMPLATE_ARGUMENT;
|
||||
case 0x1000:
|
||||
case EDGE_TYPE_ARGUMENT:
|
||||
return EDGE_TYPE_ARGUMENT;
|
||||
case EDGE_TEMPLATE_DEFAULT_ARGUMENT:
|
||||
return EDGE_TEMPLATE_DEFAULT_ARGUMENT;
|
||||
case 0x2000:
|
||||
case EDGE_TEMPLATE_SPECIALIZATION_OF:
|
||||
return EDGE_TEMPLATE_SPECIALIZATION_OF;
|
||||
case 0x4000:
|
||||
case EDGE_TEMPLATE_MEMBER_SPECIALIZATION_OF:
|
||||
return EDGE_TEMPLATE_MEMBER_SPECIALIZATION_OF;
|
||||
case 0x8000:
|
||||
case EDGE_INCLUDE:
|
||||
return EDGE_INCLUDE;
|
||||
case 0x10000:
|
||||
case EDGE_IMPORT:
|
||||
return EDGE_IMPORT;
|
||||
case EDGE_AGGREGATION:
|
||||
return EDGE_AGGREGATION;
|
||||
case 0x20000:
|
||||
case EDGE_MACRO_USAGE:
|
||||
return EDGE_MACRO_USAGE;
|
||||
}
|
||||
|
||||
return EDGE_NONE;
|
||||
return EDGE_UNDEFINED;
|
||||
}
|
||||
|
||||
Edge::Edge(Id id, EdgeType type, Node* from, Node* to)
|
||||
@@ -141,53 +135,28 @@ void Edge::addComponentAggregation(std::shared_ptr<TokenComponentAggregation> co
|
||||
}
|
||||
}
|
||||
|
||||
void Edge::addComponentAccess(std::shared_ptr<TokenComponentAccess> component)
|
||||
{
|
||||
if (getComponent<TokenComponentAccess>())
|
||||
{
|
||||
// LOG_ERROR("TokenComponentAccess has been set before!");
|
||||
return;
|
||||
}
|
||||
else if (m_type != EDGE_MEMBER && m_type != EDGE_INHERITANCE)
|
||||
{
|
||||
LOG_ERROR("TokenComponentAccess can't be set on edge of type: " + getTypeString());
|
||||
}
|
||||
else
|
||||
{
|
||||
addComponent(component);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Edge::getTypeString(EdgeType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case EDGE_NONE:
|
||||
return "none";
|
||||
case EDGE_UNDEFINED:
|
||||
return "undefined";
|
||||
case EDGE_MEMBER:
|
||||
return "child";
|
||||
case EDGE_TYPE_OF:
|
||||
return "type_of";
|
||||
case EDGE_RETURN_TYPE_OF:
|
||||
return "return_type";
|
||||
case EDGE_PARAMETER_TYPE_OF:
|
||||
return "parameter_type";
|
||||
case EDGE_TYPE_USAGE:
|
||||
return "type_use";
|
||||
case EDGE_USAGE:
|
||||
return "use";
|
||||
case EDGE_CALL:
|
||||
return "call";
|
||||
case EDGE_INHERITANCE:
|
||||
return "inheritance";
|
||||
case EDGE_OVERRIDE:
|
||||
return "override";
|
||||
case EDGE_CALL:
|
||||
return "call";
|
||||
case EDGE_USAGE:
|
||||
return "use";
|
||||
case EDGE_TYPEDEF_OF:
|
||||
return "typedef";
|
||||
case EDGE_TEMPLATE_PARAMETER:
|
||||
return "template_parameter";
|
||||
case EDGE_TEMPLATE_ARGUMENT:
|
||||
return "template_argument";
|
||||
case EDGE_TYPE_ARGUMENT:
|
||||
return "type_argument";
|
||||
case EDGE_TEMPLATE_DEFAULT_ARGUMENT:
|
||||
return "template_default_argument";
|
||||
case EDGE_TEMPLATE_SPECIALIZATION_OF:
|
||||
@@ -196,6 +165,8 @@ std::string Edge::getTypeString(EdgeType type)
|
||||
return "template_member_specialization";
|
||||
case EDGE_INCLUDE:
|
||||
return "include";
|
||||
case EDGE_IMPORT:
|
||||
return "import";
|
||||
case EDGE_AGGREGATION:
|
||||
return "aggregation";
|
||||
case EDGE_MACRO_USAGE:
|
||||
@@ -215,12 +186,6 @@ std::string Edge::getAsString() const
|
||||
std::stringstream str;
|
||||
str << "[" << getId() << "] " << getTypeString() << ": \"" << m_from->getName() << "\" -> \"" + m_to->getName() << "\"";
|
||||
|
||||
TokenComponentAccess* access = getComponent<TokenComponentAccess>();
|
||||
if (access)
|
||||
{
|
||||
str << " " << access->getAccessString();
|
||||
}
|
||||
|
||||
TokenComponentAggregation* aggregation = getComponent<TokenComponentAggregation>();
|
||||
if (aggregation)
|
||||
{
|
||||
|
||||
+15
-21
@@ -18,27 +18,22 @@ public:
|
||||
typedef int EdgeTypeMask;
|
||||
enum EdgeType : EdgeTypeMask
|
||||
{
|
||||
EDGE_NONE = 0x0,
|
||||
EDGE_UNDEFINED = 0x0,
|
||||
EDGE_MEMBER = 0x1,
|
||||
EDGE_TYPE_OF = 0x2,
|
||||
EDGE_RETURN_TYPE_OF = 0x4, // unused: see Storage::addFunctionNode()
|
||||
EDGE_PARAMETER_TYPE_OF = 0x8, // unused: see Storage::addFunctionNode()
|
||||
EDGE_TYPE_USAGE = 0x10,
|
||||
EDGE_USAGE = 0x20,
|
||||
EDGE_CALL = 0x40,
|
||||
EDGE_INHERITANCE = 0x80,
|
||||
EDGE_OVERRIDE = 0x100,
|
||||
EDGE_TYPEDEF_OF = 0x200,
|
||||
EDGE_TEMPLATE_PARAMETER = 0x400, // unused since template parameters are children
|
||||
EDGE_TEMPLATE_ARGUMENT = 0x800,
|
||||
EDGE_TEMPLATE_DEFAULT_ARGUMENT = 0x1000,
|
||||
EDGE_TEMPLATE_SPECIALIZATION_OF = 0x2000,
|
||||
EDGE_TEMPLATE_MEMBER_SPECIALIZATION_OF = 0x4000,
|
||||
|
||||
EDGE_INCLUDE = 0x8000,
|
||||
|
||||
EDGE_AGGREGATION = 0x10000,
|
||||
EDGE_MACRO_USAGE = 0x20000,
|
||||
EDGE_TYPE_USAGE = 0x2,
|
||||
EDGE_USAGE = 0x4,
|
||||
EDGE_CALL = 0x8,
|
||||
EDGE_INHERITANCE = 0x10,
|
||||
EDGE_OVERRIDE = 0x20,
|
||||
EDGE_TEMPLATE_ARGUMENT = 0x40,
|
||||
EDGE_TYPE_ARGUMENT = 0x80,
|
||||
EDGE_TEMPLATE_DEFAULT_ARGUMENT = 0x100,
|
||||
EDGE_TEMPLATE_SPECIALIZATION_OF = 0x200,
|
||||
EDGE_TEMPLATE_MEMBER_SPECIALIZATION_OF = 0x400,
|
||||
EDGE_INCLUDE = 0x800,
|
||||
EDGE_IMPORT = 0x1000,
|
||||
EDGE_AGGREGATION = 0x2000,
|
||||
EDGE_MACRO_USAGE = 0x4000
|
||||
};
|
||||
|
||||
static int typeToInt(EdgeType type);
|
||||
@@ -62,7 +57,6 @@ public:
|
||||
|
||||
// Component setters
|
||||
void addComponentAggregation(std::shared_ptr<TokenComponentAggregation> component);
|
||||
void addComponentAccess(std::shared_ptr<TokenComponentAccess> component);
|
||||
|
||||
// Logging.
|
||||
static std::string getTypeString(EdgeType type);
|
||||
|
||||
@@ -164,25 +164,6 @@ void Graph::removeEdge(Edge* edge)
|
||||
m_edges.erase(it);
|
||||
}
|
||||
|
||||
bool Graph::removeNodeIfUnreferencedRecursive(Node* node)
|
||||
{
|
||||
if (!node->hasReferences())
|
||||
{
|
||||
Node* parent = node->getParentNode();
|
||||
|
||||
removeNode(node);
|
||||
|
||||
if (parent)
|
||||
{
|
||||
removeNodeIfUnreferencedRecursive(parent);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Node* Graph::findNode(std::function<bool(Node*)> func) const
|
||||
{
|
||||
std::map<Id, std::shared_ptr<Node>>::const_iterator it = find_if(m_nodes.begin(), m_nodes.end(),
|
||||
|
||||
@@ -34,7 +34,6 @@ public:
|
||||
|
||||
void removeNode(Node* node);
|
||||
void removeEdge(Edge* edge);
|
||||
bool removeNodeIfUnreferencedRecursive(Node* node);
|
||||
|
||||
Node* findNode(std::function<bool(Node*)> func) const;
|
||||
Edge* findEdge(std::function<bool(Edge*)> func) const;
|
||||
|
||||
+53
-48
@@ -5,12 +5,13 @@
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
#include "data/graph/token_component/TokenComponentAbstraction.h"
|
||||
#include "data/graph/token_component/TokenComponentAccess.h"
|
||||
#include "data/graph/token_component/TokenComponentConst.h"
|
||||
#include "data/graph/token_component/TokenComponentStatic.h"
|
||||
#include "data/graph/token_component/TokenComponentFilePath.h"
|
||||
#include "data/graph/token_component/TokenComponentSignature.h"
|
||||
|
||||
const Node::NodeTypeMask Node::NODE_NOT_VISIBLE = Node::NODE_UNDEFINED | Node::NODE_NAMESPACE;
|
||||
const Node::NodeTypeMask Node::NODE_NOT_VISIBLE = Node::NODE_UNDEFINED | Node::NODE_NAMESPACE | Node::NODE_PACKAGE;
|
||||
|
||||
std::string Node::getTypeString(NodeType type)
|
||||
{
|
||||
@@ -18,14 +19,20 @@ std::string Node::getTypeString(NodeType type)
|
||||
{
|
||||
case NODE_UNDEFINED:
|
||||
return "undefined";
|
||||
case NODE_BUILTIN_TYPE:
|
||||
return "builtin_type";
|
||||
case NODE_TYPE:
|
||||
return "type";
|
||||
case NODE_NAMESPACE:
|
||||
return "namespace";
|
||||
case NODE_CLASS:
|
||||
return "class";
|
||||
case NODE_PACKAGE:
|
||||
return "package";
|
||||
case NODE_STRUCT:
|
||||
return "struct";
|
||||
case NODE_CLASS:
|
||||
return "class";
|
||||
case NODE_INTERFACE:
|
||||
return "interface";
|
||||
case NODE_GLOBAL_VARIABLE:
|
||||
return "global_variable";
|
||||
case NODE_FIELD:
|
||||
@@ -42,6 +49,8 @@ std::string Node::getTypeString(NodeType type)
|
||||
return "typedef";
|
||||
case NODE_TEMPLATE_PARAMETER_TYPE:
|
||||
return "template_parameter_type";
|
||||
case NODE_TYPE_PARAMETER:
|
||||
return "type_parameter";
|
||||
case NODE_FILE:
|
||||
return "file";
|
||||
case NODE_MACRO:
|
||||
@@ -60,33 +69,41 @@ Node::NodeType Node::intToType(int value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 0x2:
|
||||
case NODE_TYPE:
|
||||
return NODE_TYPE;
|
||||
case 0x4:
|
||||
case NODE_BUILTIN_TYPE:
|
||||
return NODE_BUILTIN_TYPE;
|
||||
case NODE_NAMESPACE:
|
||||
return NODE_NAMESPACE;
|
||||
case 0x8:
|
||||
case NODE_PACKAGE:
|
||||
return NODE_PACKAGE;
|
||||
case NODE_STRUCT:
|
||||
return NODE_STRUCT;
|
||||
case 0x10:
|
||||
case NODE_CLASS:
|
||||
return NODE_CLASS;
|
||||
case 0x20:
|
||||
case NODE_INTERFACE:
|
||||
return NODE_INTERFACE;
|
||||
case NODE_GLOBAL_VARIABLE:
|
||||
return NODE_GLOBAL_VARIABLE;
|
||||
case 0x40:
|
||||
case NODE_FIELD:
|
||||
return NODE_FIELD;
|
||||
case 0x80:
|
||||
case NODE_FUNCTION:
|
||||
return NODE_FUNCTION;
|
||||
case 0x100:
|
||||
case NODE_METHOD:
|
||||
return NODE_METHOD;
|
||||
case 0x200:
|
||||
case NODE_ENUM:
|
||||
return NODE_ENUM;
|
||||
case 0x400:
|
||||
case NODE_ENUM_CONSTANT:
|
||||
return NODE_ENUM_CONSTANT;
|
||||
case 0x800:
|
||||
case NODE_TYPEDEF:
|
||||
return NODE_TYPEDEF;
|
||||
case 0x1000:
|
||||
case NODE_TEMPLATE_PARAMETER_TYPE:
|
||||
return NODE_TEMPLATE_PARAMETER_TYPE;
|
||||
case 0x2000:
|
||||
case NODE_TYPE_PARAMETER:
|
||||
return NODE_TYPE_PARAMETER;
|
||||
case NODE_FILE:
|
||||
return NODE_FILE;
|
||||
case 0x4000:
|
||||
case NODE_MACRO:
|
||||
return NODE_MACRO;
|
||||
}
|
||||
|
||||
@@ -324,37 +341,6 @@ void Node::forEachNodeRecursive(std::function<void(const Node*)> func) const
|
||||
);
|
||||
}
|
||||
|
||||
bool Node::hasReferences() const
|
||||
{
|
||||
if (getLocationIds().size() > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hasChildrenWithReferences = false;
|
||||
size_t childNodeCount = 0;
|
||||
|
||||
forEachEdgeOfType(
|
||||
Edge::EDGE_MEMBER,
|
||||
[&](Edge* edge)
|
||||
{
|
||||
childNodeCount++;
|
||||
|
||||
if (!hasChildrenWithReferences && edge->getTo() != this && edge->getTo()->hasReferences())
|
||||
{
|
||||
hasChildrenWithReferences = true;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (hasChildrenWithReferences || getEdges().size() > childNodeCount)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Node::isNode() const
|
||||
{
|
||||
return true;
|
||||
@@ -450,6 +436,19 @@ void Node::addComponentSignature(std::shared_ptr<TokenComponentSignature> compon
|
||||
}
|
||||
}
|
||||
|
||||
void Node::addComponentAccess(std::shared_ptr<TokenComponentAccess> component)
|
||||
{
|
||||
if (getComponent<TokenComponentAccess>())
|
||||
{
|
||||
LOG_ERROR("TokenComponentAccess has been set before!");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
addComponent(component);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Node::getTypeString() const
|
||||
{
|
||||
return getTypeString(m_type);
|
||||
@@ -460,6 +459,12 @@ std::string Node::getAsString() const
|
||||
std::stringstream str;
|
||||
str << "[" << getId() << "] " << getTypeString() << ": " << "\"" << getName() << "\"";
|
||||
|
||||
TokenComponentAccess* access = getComponent<TokenComponentAccess>();
|
||||
if (access)
|
||||
{
|
||||
str << " " << access->getAccessString();
|
||||
}
|
||||
|
||||
if (getComponent<TokenComponentStatic>())
|
||||
{
|
||||
str << " static";
|
||||
|
||||
+20
-16
@@ -11,6 +11,7 @@
|
||||
#include "data/name/NameHierarchy.h"
|
||||
|
||||
class TokenComponentAbstraction;
|
||||
class TokenComponentAccess;
|
||||
class TokenComponentConst;
|
||||
class TokenComponentStatic;
|
||||
class TokenComponentFilePath;
|
||||
@@ -22,25 +23,29 @@ class Node
|
||||
public:
|
||||
typedef int NodeTypeMask;
|
||||
enum NodeType : NodeTypeMask
|
||||
{
|
||||
{ // make sure that the value of 0x0 is not used here because it doesn't work for bitmasking.
|
||||
NODE_UNDEFINED = 0x1,
|
||||
NODE_TYPE = 0x2,
|
||||
NODE_BUILTIN_TYPE = 0x4,
|
||||
|
||||
NODE_NAMESPACE = 0x4,
|
||||
NODE_STRUCT = 0x8,
|
||||
NODE_CLASS = 0x10,
|
||||
NODE_GLOBAL_VARIABLE = 0x20,
|
||||
NODE_FIELD = 0x40,
|
||||
NODE_FUNCTION = 0x80,
|
||||
NODE_METHOD = 0x100,
|
||||
NODE_NAMESPACE = 0x8,
|
||||
NODE_PACKAGE = 0x10,
|
||||
NODE_STRUCT = 0x20,
|
||||
NODE_CLASS = 0x40,
|
||||
NODE_INTERFACE = 0x80,
|
||||
NODE_GLOBAL_VARIABLE = 0x100,
|
||||
NODE_FIELD = 0x200,
|
||||
NODE_FUNCTION = 0x400,
|
||||
NODE_METHOD = 0x800,
|
||||
|
||||
NODE_ENUM = 0x200,
|
||||
NODE_ENUM_CONSTANT = 0x400,
|
||||
NODE_TYPEDEF = 0x800,
|
||||
NODE_TEMPLATE_PARAMETER_TYPE = 0x1000,
|
||||
NODE_ENUM = 0x1000,
|
||||
NODE_ENUM_CONSTANT = 0x2000,
|
||||
NODE_TYPEDEF = 0x4000,
|
||||
NODE_TEMPLATE_PARAMETER_TYPE = 0x8000,
|
||||
NODE_TYPE_PARAMETER = 0x10000,
|
||||
|
||||
NODE_FILE = 0x2000,
|
||||
NODE_MACRO = 0x4000
|
||||
NODE_FILE = 0x20000,
|
||||
NODE_MACRO = 0x40000
|
||||
};
|
||||
|
||||
static std::string getTypeString(NodeType type);
|
||||
@@ -88,8 +93,6 @@ public:
|
||||
void forEachChildNode(std::function<void(Node*)> func) const;
|
||||
void forEachNodeRecursive(std::function<void(const Node*)> func) const;
|
||||
|
||||
bool hasReferences() const;
|
||||
|
||||
// Token implementation.
|
||||
virtual bool isNode() const;
|
||||
virtual bool isEdge() const;
|
||||
@@ -100,6 +103,7 @@ public:
|
||||
void addComponentStatic(std::shared_ptr<TokenComponentStatic> component);
|
||||
void addComponentFilePath(std::shared_ptr<TokenComponentFilePath> component);
|
||||
void addComponentSignature(std::shared_ptr<TokenComponentSignature> component);
|
||||
void addComponentAccess(std::shared_ptr<TokenComponentAccess> component);
|
||||
|
||||
// Logging.
|
||||
virtual std::string getTypeString() const;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "data/graph/token_component/TokenComponentAccess.h"
|
||||
|
||||
std::string TokenComponentAccess::getAccessString(AccessType access)
|
||||
std::string TokenComponentAccess::getAccessString(AccessKind access)
|
||||
{
|
||||
switch (access)
|
||||
{
|
||||
@@ -10,38 +10,18 @@ std::string TokenComponentAccess::getAccessString(AccessType access)
|
||||
return "protected";
|
||||
case ACCESS_PRIVATE:
|
||||
return "private";
|
||||
case ACCESS_TEMPLATE:
|
||||
case ACCESS_DEFAULT:
|
||||
return "default";
|
||||
case ACCESS_TEMPLATE_PARAMETER:
|
||||
return "template parameter";
|
||||
case ACCESS_NONE:
|
||||
return "";
|
||||
case ACCESS_TYPE_PARAMETER:
|
||||
return "type parameter";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
int TokenComponentAccess::typeToInt(AccessType type)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
TokenComponentAccess::AccessType TokenComponentAccess::intToType(int value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 0x1:
|
||||
return ACCESS_PUBLIC;
|
||||
case 0x2:
|
||||
return ACCESS_PROTECTED;
|
||||
case 0x4:
|
||||
return ACCESS_PRIVATE;
|
||||
case 0x8:
|
||||
return ACCESS_TEMPLATE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ACCESS_NONE;
|
||||
}
|
||||
|
||||
TokenComponentAccess::TokenComponentAccess(AccessType access)
|
||||
TokenComponentAccess::TokenComponentAccess(AccessKind access)
|
||||
: m_access(access)
|
||||
{
|
||||
}
|
||||
@@ -55,7 +35,7 @@ std::shared_ptr<TokenComponent> TokenComponentAccess::copy() const
|
||||
return std::make_shared<TokenComponentAccess>(*this);
|
||||
}
|
||||
|
||||
TokenComponentAccess::AccessType TokenComponentAccess::getAccess() const
|
||||
AccessKind TokenComponentAccess::getAccess() const
|
||||
{
|
||||
return m_access;
|
||||
}
|
||||
|
||||
@@ -4,35 +4,24 @@
|
||||
#include <string>
|
||||
|
||||
#include "data/graph/token_component/TokenComponent.h"
|
||||
#include "data/parser/AccessKind.h"
|
||||
|
||||
class TokenComponentAccess
|
||||
: public TokenComponent
|
||||
{
|
||||
public:
|
||||
enum AccessType : int // todo: use normal numbers here. not 2^x
|
||||
{
|
||||
ACCESS_PUBLIC = 0x1,
|
||||
ACCESS_PROTECTED = 0x2,
|
||||
ACCESS_PRIVATE = 0x4,
|
||||
ACCESS_TEMPLATE = 0x8,
|
||||
ACCESS_NONE = 0x0
|
||||
};
|
||||
static std::string getAccessString(AccessKind access);
|
||||
|
||||
static std::string getAccessString(AccessType access);
|
||||
|
||||
static int typeToInt(AccessType type);
|
||||
static AccessType intToType(int value);
|
||||
|
||||
TokenComponentAccess(AccessType access);
|
||||
TokenComponentAccess(AccessKind access);
|
||||
virtual ~TokenComponentAccess();
|
||||
|
||||
virtual std::shared_ptr<TokenComponent> copy() const;
|
||||
|
||||
AccessType getAccess() const;
|
||||
AccessKind getAccess() const;
|
||||
std::string getAccessString() const;
|
||||
|
||||
private:
|
||||
const AccessType m_access;
|
||||
const AccessKind m_access;
|
||||
};
|
||||
|
||||
#endif // TOKEN_COMPONENT_ACCESS_H
|
||||
|
||||
@@ -38,7 +38,11 @@ std::string NameElement::Signature::qualifyName(const std::string& name) const
|
||||
std::string qualifiedName = m_prefix;
|
||||
if (name.size() > 0)
|
||||
{
|
||||
qualifiedName += " " + name;
|
||||
if (!m_prefix.empty())
|
||||
{
|
||||
qualifiedName += " ";
|
||||
}
|
||||
qualifiedName += name;
|
||||
}
|
||||
qualifiedName += m_postfix;
|
||||
|
||||
|
||||
@@ -87,26 +87,26 @@ size_t NameHierarchy::size() const
|
||||
return m_elements.size();
|
||||
}
|
||||
|
||||
std::string NameHierarchy::getQualifiedName() const
|
||||
std::string NameHierarchy::getQualifiedName(const std::string& delimiter) const
|
||||
{
|
||||
std::string name;
|
||||
for (size_t i = 0; i < m_elements.size(); i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
name += "::";
|
||||
name += delimiter;
|
||||
}
|
||||
name += m_elements[i]->getName();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string NameHierarchy::getQualifiedNameWithSignature() const
|
||||
std::string NameHierarchy::getQualifiedNameWithSignature(const std::string& delimiter) const
|
||||
{
|
||||
std::string name = getQualifiedName();
|
||||
std::string name = getQualifiedName(delimiter);
|
||||
if (m_elements.size())
|
||||
{
|
||||
name = m_elements.back()->getSignature().qualifyName(name);
|
||||
name = m_elements.back()->getSignature().qualifyName(name); // todo: use separator for signature!
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public:
|
||||
std::shared_ptr<NameElement> operator[](size_t pos) const;
|
||||
size_t size() const;
|
||||
|
||||
std::string getQualifiedName() const;
|
||||
std::string getQualifiedNameWithSignature() const;
|
||||
std::string getQualifiedName(const std::string& delimiter = "::") const;
|
||||
std::string getQualifiedNameWithSignature(const std::string& delimiter = "::") const;
|
||||
std::string getRawName() const;
|
||||
std::string getRawNameWithSignature() const;
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "data/parser/AccessKind.h"
|
||||
|
||||
AccessKind intToAccessKind(int v)
|
||||
{
|
||||
switch (v)
|
||||
{
|
||||
case ACCESS_PUBLIC:
|
||||
return ACCESS_PUBLIC;
|
||||
case ACCESS_PROTECTED:
|
||||
return ACCESS_PROTECTED;
|
||||
case ACCESS_PRIVATE:
|
||||
return ACCESS_PRIVATE;
|
||||
case ACCESS_DEFAULT:
|
||||
return ACCESS_DEFAULT;
|
||||
case ACCESS_TEMPLATE_PARAMETER:
|
||||
return ACCESS_TEMPLATE_PARAMETER;
|
||||
case ACCESS_TYPE_PARAMETER:
|
||||
return ACCESS_TYPE_PARAMETER;
|
||||
}
|
||||
return ACCESS_NONE;
|
||||
}
|
||||
|
||||
int accessKindToInt(AccessKind t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef ACCESS_KIND_H
|
||||
#define ACCESS_KIND_H
|
||||
|
||||
enum AccessKind
|
||||
{ // these values need to be the same as AccessType in Java code
|
||||
ACCESS_NONE = 0,
|
||||
ACCESS_PUBLIC = 1,
|
||||
ACCESS_PROTECTED = 2,
|
||||
ACCESS_PRIVATE = 3,
|
||||
ACCESS_DEFAULT = 4,
|
||||
ACCESS_TEMPLATE_PARAMETER = 5,
|
||||
ACCESS_TYPE_PARAMETER = 6
|
||||
};
|
||||
|
||||
AccessKind intToAccessKind(int v);
|
||||
int accessKindToInt(AccessKind t);
|
||||
|
||||
#endif // ACCESS_KIND_H
|
||||
@@ -17,6 +17,8 @@ public:
|
||||
{
|
||||
Arguments();
|
||||
|
||||
std::vector<FilePath> javaClassPaths;
|
||||
|
||||
std::vector<FilePath> headerSearchPaths;
|
||||
std::vector<FilePath> systemHeaderSearchPaths;
|
||||
std::vector<FilePath> frameworkSearchPaths;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "data/type/DataType.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
std::string ParserClient::addAccessPrefix(const std::string& str, AccessType access)
|
||||
std::string ParserClient::addAccessPrefix(const std::string& str, AccessKind access)
|
||||
{
|
||||
switch (access)
|
||||
{
|
||||
@@ -16,9 +16,10 @@ std::string ParserClient::addAccessPrefix(const std::string& str, AccessType acc
|
||||
return "protected " + str;
|
||||
case ACCESS_PRIVATE:
|
||||
return "private " + str;
|
||||
case ACCESS_NONE:
|
||||
return str;
|
||||
case ACCESS_DEFAULT:
|
||||
return "default " + str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string ParserClient::addAbstractionPrefix(const std::string& str, AbstractionType abstraction)
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "data/name/NameHierarchy.h"
|
||||
#include "data/parser/SymbolType.h"
|
||||
#include "data/parser/AccessKind.h"
|
||||
#include "data/parser/ReferenceKind.h"
|
||||
#include "data/parser/SymbolKind.h"
|
||||
#include "utility/file/FileInfo.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
@@ -15,20 +17,13 @@ class DataType;
|
||||
class ParserClient
|
||||
{
|
||||
public:
|
||||
enum AccessType {
|
||||
ACCESS_PUBLIC,
|
||||
ACCESS_PROTECTED,
|
||||
ACCESS_PRIVATE,
|
||||
ACCESS_NONE
|
||||
};
|
||||
|
||||
enum AbstractionType {
|
||||
ABSTRACTION_VIRTUAL,
|
||||
ABSTRACTION_PURE_VIRTUAL,
|
||||
ABSTRACTION_NONE
|
||||
};
|
||||
|
||||
static std::string addAccessPrefix(const std::string& str, AccessType access);
|
||||
static std::string addAccessPrefix(const std::string& str, AccessKind access);
|
||||
static std::string addAbstractionPrefix(const std::string& str, AbstractionType abstraction);
|
||||
static std::string addStaticPrefix(const std::string& str, bool isStatic);
|
||||
static std::string addConstPrefix(const std::string& str, bool isConst, bool atFront);
|
||||
@@ -42,28 +37,46 @@ public:
|
||||
virtual void startParsingFile() = 0;
|
||||
virtual void finishParsingFile() = 0;
|
||||
|
||||
virtual Id recordSymbol(
|
||||
const NameHierarchy& symbolName, SymbolKind symbolType,
|
||||
AccessKind access = ACCESS_NONE, bool isImplicit = false) = 0;
|
||||
|
||||
virtual Id recordSymbol(
|
||||
const NameHierarchy& symbolName, SymbolKind symbolType,
|
||||
const ParseLocation& location,
|
||||
AccessKind access = ACCESS_NONE, bool isImplicit = false) = 0;
|
||||
|
||||
virtual Id recordSymbol(
|
||||
const NameHierarchy& symbolName, SymbolKind symbolType,
|
||||
const ParseLocation& location, const ParseLocation& scopeLocation,
|
||||
AccessKind access = ACCESS_NONE, bool isImplicit = false) = 0;
|
||||
|
||||
virtual void recordReference(
|
||||
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
|
||||
const ParseLocation& location) = 0;
|
||||
|
||||
virtual void onError(const ParseLocation& location, const std::string& message, bool fatal, bool indexed) = 0;
|
||||
|
||||
virtual void onTypedefParsed(
|
||||
const ParseLocation& location, const NameHierarchy& typedefName, AccessType access, bool isImplicit) = 0;
|
||||
const ParseLocation& location, const NameHierarchy& typedefName, AccessKind access, bool isImplicit) = 0;
|
||||
virtual void onClassParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessType access,
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessKind access,
|
||||
const ParseLocation& scopeLocation, bool isImplicit) = 0;
|
||||
virtual void onStructParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessType access,
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessKind access,
|
||||
const ParseLocation& scopeLocation, bool isImplicit) = 0;
|
||||
virtual void onGlobalVariableParsed(const ParseLocation& location, const NameHierarchy& variable, bool isImplicit) = 0;
|
||||
virtual void onFieldParsed(const ParseLocation& location, const NameHierarchy& field, AccessType access, bool isImplicit) = 0;
|
||||
virtual void onFieldParsed(const ParseLocation& location, const NameHierarchy& field, AccessKind access, bool isImplicit) = 0;
|
||||
virtual void onFunctionParsed(
|
||||
const ParseLocation& location, const NameHierarchy& function, const ParseLocation& scopeLocation, bool isImplicit) = 0;
|
||||
virtual void onMethodParsed(
|
||||
const ParseLocation& location, const NameHierarchy& method, AccessType access, AbstractionType abstraction,
|
||||
const ParseLocation& location, const NameHierarchy& method, AccessKind access, AbstractionType abstraction,
|
||||
const ParseLocation& scopeLocation, bool isImplicit) = 0;
|
||||
virtual void onNamespaceParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy,
|
||||
const ParseLocation& scopeLocation, bool isImplicit) = 0;
|
||||
virtual void onEnumParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessType access,
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessKind access,
|
||||
const ParseLocation& scopeLocation, bool isImplicit) = 0;
|
||||
virtual void onEnumConstantParsed(const ParseLocation& location, const NameHierarchy& nameHierarchy, bool isImplicit) = 0;
|
||||
virtual void onTemplateParameterTypeParsed(
|
||||
@@ -76,13 +89,13 @@ public:
|
||||
|
||||
virtual void onInheritanceParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy,
|
||||
const NameHierarchy& baseNameHierarchy, AccessType access) = 0;
|
||||
const NameHierarchy& baseNameHierarchy) = 0;
|
||||
virtual void onMethodOverrideParsed(
|
||||
const ParseLocation& location, const NameHierarchy& overridden, const NameHierarchy& overrider) = 0;
|
||||
virtual void onCallParsed(
|
||||
const ParseLocation& location, const NameHierarchy& caller, const NameHierarchy& callee) = 0;
|
||||
virtual void onUsageParsed(
|
||||
const ParseLocation& location, const NameHierarchy& userName, SymbolType usedType, const NameHierarchy& usedName) = 0;
|
||||
const ParseLocation& location, const NameHierarchy& userName, SymbolKind usedType, const NameHierarchy& usedName) = 0;
|
||||
virtual void onTypeUsageParsed(const ParseLocation& location, const NameHierarchy& user, const NameHierarchy& used) = 0;
|
||||
|
||||
virtual void onTemplateArgumentTypeParsed(
|
||||
|
||||
@@ -27,13 +27,57 @@ void ParserClientImpl::resetStorage()
|
||||
|
||||
void ParserClientImpl::startParsingFile()
|
||||
{
|
||||
m_nodeIdsToMemberEdgeIds.clear(); // remove this when one parserclient is created per file
|
||||
}
|
||||
|
||||
void ParserClientImpl::finishParsingFile()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Id ParserClientImpl::recordSymbol(
|
||||
const NameHierarchy& symbolName, SymbolKind symbolType,
|
||||
AccessKind access, bool isImplicit
|
||||
)
|
||||
{
|
||||
Id nodeId = addNodeHierarchy(symbolKindToNodeType(symbolType), symbolName, (isImplicit ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT));
|
||||
addAccess(nodeId, access);
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
Id ParserClientImpl::recordSymbol(
|
||||
const NameHierarchy& symbolName, SymbolKind symbolType,
|
||||
const ParseLocation& location,
|
||||
AccessKind access, bool isImplicit
|
||||
)
|
||||
{
|
||||
Id nodeId = recordSymbol(symbolName, symbolType, access, isImplicit);
|
||||
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
Id ParserClientImpl::recordSymbol(
|
||||
const NameHierarchy& symbolName, SymbolKind symbolType,
|
||||
const ParseLocation& location, const ParseLocation& scopeLocation,
|
||||
AccessKind access, bool isImplicit
|
||||
)
|
||||
{
|
||||
Id nodeId = recordSymbol(symbolName, symbolType, location, access, isImplicit);
|
||||
addSourceLocation(nodeId, scopeLocation, locationTypeToInt(LOCATION_SCOPE));
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
void ParserClientImpl::recordReference(
|
||||
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
|
||||
const ParseLocation& location)
|
||||
{
|
||||
Id contextNodeId = addNodeHierarchy(Node::NODE_UNDEFINED, contextName, DEFINITION_NONE);
|
||||
Id referencedNodeId = addNodeHierarchy(Node::NODE_UNDEFINED, referencedName, DEFINITION_NONE);
|
||||
Id edgeId = addEdge(referenceKindToEdgeType(referenceKind), contextNodeId, referencedNodeId);
|
||||
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ParserClientImpl::onError(const ParseLocation& location, const std::string& message, bool fatal, bool indexed)
|
||||
{
|
||||
log(std::string(fatal ? "FATAL: " : "ERROR: "), message, location);
|
||||
@@ -47,7 +91,7 @@ void ParserClientImpl::onError(const ParseLocation& location, const std::string&
|
||||
}
|
||||
|
||||
void ParserClientImpl::onTypedefParsed(
|
||||
const ParseLocation& location, const NameHierarchy& typedefName, AccessType access, bool isImplicit)
|
||||
const ParseLocation& location, const NameHierarchy& typedefName, AccessKind access, bool isImplicit)
|
||||
{
|
||||
log("typedef", typedefName.getQualifiedName(), location);
|
||||
|
||||
@@ -57,7 +101,7 @@ void ParserClientImpl::onTypedefParsed(
|
||||
}
|
||||
|
||||
void ParserClientImpl::onClassParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessType access,
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessKind access,
|
||||
const ParseLocation& scopeLocation, bool isImplicit)
|
||||
{
|
||||
log("class", nameHierarchy.getQualifiedName(), location);
|
||||
@@ -73,7 +117,7 @@ void ParserClientImpl::onClassParsed(
|
||||
}
|
||||
|
||||
void ParserClientImpl::onStructParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessType access,
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessKind access,
|
||||
const ParseLocation& scopeLocation, bool isImplicit)
|
||||
{
|
||||
log("struct", nameHierarchy.getQualifiedName(), location);
|
||||
@@ -96,7 +140,7 @@ void ParserClientImpl::onGlobalVariableParsed(const ParseLocation& location, con
|
||||
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
|
||||
}
|
||||
|
||||
void ParserClientImpl::onFieldParsed(const ParseLocation& location, const NameHierarchy& field, AccessType access, bool isImplicit)
|
||||
void ParserClientImpl::onFieldParsed(const ParseLocation& location, const NameHierarchy& field, AccessKind access, bool isImplicit)
|
||||
{
|
||||
log("field", field.getQualifiedName(), location);
|
||||
|
||||
@@ -116,7 +160,7 @@ void ParserClientImpl::onFunctionParsed(
|
||||
}
|
||||
|
||||
void ParserClientImpl::onMethodParsed(
|
||||
const ParseLocation& location, const NameHierarchy& method, AccessType access, AbstractionType abstraction,
|
||||
const ParseLocation& location, const NameHierarchy& method, AccessKind access, AbstractionType abstraction, // todo: remove abstractio... better: remove this method!
|
||||
const ParseLocation& scopeLocation, bool isImplicit)
|
||||
{
|
||||
log("method", method.getQualifiedNameWithSignature(), location);
|
||||
@@ -142,7 +186,7 @@ void ParserClientImpl::onNamespaceParsed(
|
||||
}
|
||||
|
||||
void ParserClientImpl::onEnumParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessType access,
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessKind access,
|
||||
const ParseLocation& scopeLocation, bool isImplicit)
|
||||
{
|
||||
log("enum", nameHierarchy.getQualifiedName(), location);
|
||||
@@ -168,7 +212,7 @@ void ParserClientImpl::onTemplateParameterTypeParsed(
|
||||
|
||||
Id nodeId = addNodeHierarchy(Node::NODE_TEMPLATE_PARAMETER_TYPE, templateParameterTypeNameHierarchy, (isImplicit ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT));
|
||||
addSourceLocation(nodeId, location, locationTypeToInt(LOCATION_TOKEN));
|
||||
addAccess(nodeId, TokenComponentAccess::ACCESS_TEMPLATE);
|
||||
addAccess(nodeId, ACCESS_TEMPLATE_PARAMETER);
|
||||
}
|
||||
|
||||
void ParserClientImpl::onLocalSymbolParsed(const std::string& name, const ParseLocation& location)
|
||||
@@ -214,7 +258,7 @@ void ParserClientImpl::onCommentParsed(const ParseLocation& location)
|
||||
|
||||
void ParserClientImpl::onInheritanceParsed(
|
||||
const ParseLocation& location, const NameHierarchy& childNameHierarchy,
|
||||
const NameHierarchy& parentNameHierarchy, AccessType access)
|
||||
const NameHierarchy& parentNameHierarchy)
|
||||
{
|
||||
log("inheritance", childNameHierarchy.getQualifiedName() + " : " + parentNameHierarchy.getQualifiedName(), location);
|
||||
|
||||
@@ -246,12 +290,12 @@ void ParserClientImpl::onCallParsed(const ParseLocation& location, const NameHie
|
||||
}
|
||||
|
||||
void ParserClientImpl::onUsageParsed(
|
||||
const ParseLocation& location, const NameHierarchy& userName, SymbolType usedType, const NameHierarchy& usedName)
|
||||
const ParseLocation& location, const NameHierarchy& userName, SymbolKind usedType, const NameHierarchy& usedName)
|
||||
{
|
||||
log("usage", userName.getQualifiedNameWithSignature() + " -> " + usedName.getQualifiedName(), location);
|
||||
|
||||
Id userNodeId = addNodeHierarchy(Node::NODE_UNDEFINED, userName, DEFINITION_NONE);
|
||||
Id usedNodeId = addNodeHierarchy(symbolTypeToNodeType(usedType), usedName, DEFINITION_NONE);
|
||||
Id usedNodeId = addNodeHierarchy(symbolKindToNodeType(usedType), usedName, DEFINITION_NONE);
|
||||
Id edgeId = addEdge(Edge::EDGE_USAGE, userNodeId, usedNodeId);
|
||||
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
|
||||
}
|
||||
@@ -354,10 +398,12 @@ void ParserClientImpl::onMacroExpandParsed(const ParseLocation &location, const
|
||||
addSourceLocation(edgeId, location, locationTypeToInt(LOCATION_TOKEN));
|
||||
}
|
||||
|
||||
Node::NodeType ParserClientImpl::symbolTypeToNodeType(SymbolType symbolType) const
|
||||
Node::NodeType ParserClientImpl::symbolKindToNodeType(SymbolKind symbolType) const
|
||||
{
|
||||
switch (symbolType)
|
||||
{
|
||||
case SYMBOL_BUILTIN_TYPE:
|
||||
return Node::NODE_BUILTIN_TYPE;
|
||||
case SYMBOL_CLASS:
|
||||
return Node::NODE_CLASS;
|
||||
case SYMBOL_ENUM:
|
||||
@@ -370,18 +416,24 @@ Node::NodeType ParserClientImpl::symbolTypeToNodeType(SymbolType symbolType) con
|
||||
return Node::NODE_FUNCTION;
|
||||
case SYMBOL_GLOBAL_VARIABLE:
|
||||
return Node::NODE_GLOBAL_VARIABLE;
|
||||
case SYMBOL_INTERFACE:
|
||||
return Node::NODE_INTERFACE;
|
||||
case SYMBOL_MACRO:
|
||||
return Node::NODE_MACRO;
|
||||
case SYMBOL_METHOD:
|
||||
return Node::NODE_METHOD;
|
||||
case SYMBOL_NAMESPACE:
|
||||
return Node::NODE_NAMESPACE;
|
||||
case SYMBOL_PACKAGE:
|
||||
return Node::NODE_PACKAGE;
|
||||
case SYMBOL_STRUCT:
|
||||
return Node::NODE_STRUCT;
|
||||
case SYMBOL_TYPEDEF:
|
||||
return Node::NODE_TYPEDEF;
|
||||
case SYMBOL_TEMPLATE_PARAMETER:
|
||||
return Node::NODE_TEMPLATE_PARAMETER_TYPE;
|
||||
case SYMBOL_TYPEDEF:
|
||||
return Node::NODE_TYPEDEF;
|
||||
case SYMBOL_TYPE_PARAMETER:
|
||||
return Node::NODE_TYPE_PARAMETER;
|
||||
case SYMBOL_UNION:
|
||||
return Node::NODE_TYPE;
|
||||
default:
|
||||
@@ -390,34 +442,48 @@ Node::NodeType ParserClientImpl::symbolTypeToNodeType(SymbolType symbolType) con
|
||||
return Node::NODE_UNDEFINED;
|
||||
}
|
||||
|
||||
TokenComponentAccess::AccessType ParserClientImpl::convertAccessType(ParserClient::AccessType access) const
|
||||
Edge::EdgeType ParserClientImpl::referenceKindToEdgeType(ReferenceKind referenceKind) const
|
||||
{
|
||||
switch (access)
|
||||
switch (referenceKind)
|
||||
{
|
||||
case ACCESS_PUBLIC:
|
||||
return TokenComponentAccess::ACCESS_PUBLIC;
|
||||
case ACCESS_PROTECTED:
|
||||
return TokenComponentAccess::ACCESS_PROTECTED;
|
||||
case ACCESS_PRIVATE:
|
||||
return TokenComponentAccess::ACCESS_PRIVATE;
|
||||
case ACCESS_NONE:
|
||||
return TokenComponentAccess::ACCESS_NONE;
|
||||
case REFERENCE_TYPE_USAGE:
|
||||
return Edge::EDGE_TYPE_USAGE;
|
||||
case REFERENCE_USAGE:
|
||||
return Edge::EDGE_USAGE;
|
||||
case REFERENCE_CALL:
|
||||
return Edge::EDGE_CALL;
|
||||
case REFERENCE_INHERITANCE:
|
||||
return Edge::EDGE_INHERITANCE;
|
||||
case REFERENCE_OVERRIDE:
|
||||
return Edge::EDGE_OVERRIDE;
|
||||
case REFERENCE_TEMPLATE_ARGUMENT:
|
||||
return Edge::EDGE_TEMPLATE_ARGUMENT;
|
||||
case REFERENCE_TYPE_ARGUMENT:
|
||||
return Edge::EDGE_TYPE_ARGUMENT;
|
||||
case REFERENCE_TEMPLATE_DEFAULT_ARGUMENT:
|
||||
return Edge::EDGE_TEMPLATE_DEFAULT_ARGUMENT;
|
||||
case REFERENCE_TEMPLATE_SPECIALIZATION_OF:
|
||||
return Edge::EDGE_TEMPLATE_SPECIALIZATION_OF;
|
||||
case REFERENCE_TEMPLATE_MEMBER_SPECIALIZATION_OF:
|
||||
return Edge::EDGE_TEMPLATE_MEMBER_SPECIALIZATION_OF;
|
||||
case REFERENCE_INCLUDE:
|
||||
return Edge::EDGE_INCLUDE;
|
||||
case REFERENCE_IMPORT:
|
||||
return Edge::EDGE_IMPORT;
|
||||
case REFERENCE_MACRO_USAGE:
|
||||
return Edge::EDGE_MACRO_USAGE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return Edge::EDGE_UNDEFINED;
|
||||
}
|
||||
|
||||
void ParserClientImpl::addAccess(Id nodeId, ParserClient::AccessType access)
|
||||
void ParserClientImpl::addAccess(Id nodeId, AccessKind access)
|
||||
{
|
||||
addAccess(nodeId, convertAccessType(access));
|
||||
}
|
||||
|
||||
void ParserClientImpl::addAccess(Id nodeId, TokenComponentAccess::AccessType access)
|
||||
{
|
||||
if (access == TokenComponentAccess::ACCESS_NONE)
|
||||
if (access != ACCESS_NONE)
|
||||
{
|
||||
return;
|
||||
addComponentAccess(nodeId, accessKindToInt(access));
|
||||
}
|
||||
|
||||
addComponentAccess(nodeId, access);
|
||||
}
|
||||
|
||||
Id ParserClientImpl::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType)
|
||||
@@ -493,14 +559,7 @@ Id ParserClientImpl::addEdge(int type, Id sourceId, Id targetId)
|
||||
return 0;
|
||||
}
|
||||
|
||||
Id edgeId = m_storage->addEdge(type, sourceId, targetId);
|
||||
|
||||
if (type == Edge::EDGE_MEMBER)
|
||||
{
|
||||
m_nodeIdsToMemberEdgeIds[targetId] = edgeId;
|
||||
}
|
||||
|
||||
return edgeId;
|
||||
return m_storage->addEdge(type, sourceId, targetId);
|
||||
}
|
||||
|
||||
Id ParserClientImpl::addLocalSymbol(const std::string& name)
|
||||
@@ -549,15 +608,7 @@ void ParserClientImpl::addComponentAccess(Id nodeId , int type)
|
||||
return;
|
||||
}
|
||||
|
||||
std::unordered_map<Id, Id>::const_iterator it = m_nodeIdsToMemberEdgeIds.find(nodeId);
|
||||
if (it != m_nodeIdsToMemberEdgeIds.end())
|
||||
{
|
||||
m_storage->addComponentAccess(it->second, type);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "Cannot assign access" << type << " to node id " << nodeId << " because it's not a child node.");
|
||||
}
|
||||
m_storage->addComponentAccess(nodeId, type);
|
||||
}
|
||||
|
||||
void ParserClientImpl::addCommentLocation(const ParseLocation& location)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef PARSER_CLIENT_IMPL_H
|
||||
#define PARSER_CLIENT_IMPL_H
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "data/graph/Node.h"
|
||||
#include "data/parser/ParserClient.h"
|
||||
#include "data/IntermediateStorage.h"
|
||||
@@ -21,28 +23,47 @@ public:
|
||||
virtual void startParsingFile();
|
||||
virtual void finishParsingFile();
|
||||
|
||||
|
||||
virtual Id recordSymbol(
|
||||
const NameHierarchy& symbolName, SymbolKind symbolType,
|
||||
AccessKind access = ACCESS_NONE, bool isImplicit = false);
|
||||
|
||||
virtual Id recordSymbol(
|
||||
const NameHierarchy& symbolName, SymbolKind symbolType,
|
||||
const ParseLocation& location,
|
||||
AccessKind access = ACCESS_NONE, bool isImplicit = false);
|
||||
|
||||
virtual Id recordSymbol(
|
||||
const NameHierarchy& symbolName, SymbolKind symbolType,
|
||||
const ParseLocation& location, const ParseLocation& scopeLocation,
|
||||
AccessKind access = ACCESS_NONE, bool isImplicit = false);
|
||||
|
||||
virtual void recordReference(
|
||||
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
|
||||
const ParseLocation& location);
|
||||
|
||||
virtual void onError(const ParseLocation& location, const std::string& message, bool fatal, bool indexed);
|
||||
|
||||
virtual void onTypedefParsed(
|
||||
const ParseLocation& location, const NameHierarchy& typedefName, AccessType access, bool isImplicit);
|
||||
const ParseLocation& location, const NameHierarchy& typedefName, AccessKind access, bool isImplicit);
|
||||
virtual void onClassParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessType access,
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessKind access,
|
||||
const ParseLocation& scopeLocation, bool isImplicit);
|
||||
virtual void onStructParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessType access,
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessKind access,
|
||||
const ParseLocation& scopeLocation, bool isImplicit);
|
||||
virtual void onGlobalVariableParsed(const ParseLocation& location, const NameHierarchy& variable, bool isImplicit);
|
||||
virtual void onFieldParsed(const ParseLocation& location, const NameHierarchy& field, AccessType access, bool isImplicit);
|
||||
virtual void onFieldParsed(const ParseLocation& location, const NameHierarchy& field, AccessKind access, bool isImplicit);
|
||||
virtual void onFunctionParsed(
|
||||
const ParseLocation& location, const NameHierarchy& function, const ParseLocation& scopeLocation, bool isImplicit);
|
||||
virtual void onMethodParsed(
|
||||
const ParseLocation& location, const NameHierarchy& method, AccessType access, AbstractionType abstraction,
|
||||
const ParseLocation& location, const NameHierarchy& method, AccessKind access, AbstractionType abstraction,
|
||||
const ParseLocation& scopeLocation, bool isImplicit);
|
||||
virtual void onNamespaceParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy,
|
||||
const ParseLocation& scopeLocation, bool isImplicit);
|
||||
virtual void onEnumParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessType access,
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy, AccessKind access,
|
||||
const ParseLocation& scopeLocation, bool isImplicit);
|
||||
virtual void onEnumConstantParsed(const ParseLocation& location, const NameHierarchy& nameHierarchy, bool isImplicit);
|
||||
virtual void onTemplateParameterTypeParsed(
|
||||
@@ -55,13 +76,13 @@ public:
|
||||
|
||||
virtual void onInheritanceParsed(
|
||||
const ParseLocation& location, const NameHierarchy& nameHierarchy,
|
||||
const NameHierarchy& baseNameHierarchy, AccessType access);
|
||||
const NameHierarchy& baseNameHierarchy);
|
||||
virtual void onMethodOverrideParsed(
|
||||
const ParseLocation& location, const NameHierarchy& overridden, const NameHierarchy& overrider);
|
||||
virtual void onCallParsed(
|
||||
const ParseLocation& location, const NameHierarchy& caller, const NameHierarchy& callee);
|
||||
virtual void onUsageParsed(
|
||||
const ParseLocation& location, const NameHierarchy& userName, SymbolType usedType, const NameHierarchy& usedName);
|
||||
const ParseLocation& location, const NameHierarchy& userName, SymbolKind usedType, const NameHierarchy& usedName);
|
||||
virtual void onTypeUsageParsed(const ParseLocation& location, const NameHierarchy& user, const NameHierarchy& used);
|
||||
|
||||
virtual void onTemplateArgumentTypeParsed(
|
||||
@@ -83,10 +104,9 @@ public:
|
||||
const ParseLocation& location, const NameHierarchy& macroNameHierarchy);
|
||||
|
||||
private:
|
||||
Node::NodeType symbolTypeToNodeType(SymbolType symbolType) const;
|
||||
TokenComponentAccess::AccessType convertAccessType(ParserClient::AccessType access) const;
|
||||
void addAccess(Id nodeId, ParserClient::AccessType access);
|
||||
void addAccess(Id nodeId, TokenComponentAccess::AccessType access);
|
||||
Node::NodeType symbolKindToNodeType(SymbolKind symbolType) const;
|
||||
Edge::EdgeType referenceKindToEdgeType(ReferenceKind referenceKind) const;
|
||||
void addAccess(Id nodeId, AccessKind access);
|
||||
Id addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, DefinitionType definitionType);
|
||||
|
||||
Id addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime);
|
||||
@@ -102,7 +122,6 @@ private:
|
||||
void log(std::string type, std::string str, const ParseLocation& location) const;
|
||||
|
||||
std::shared_ptr<IntermediateStorage> m_storage;
|
||||
std::unordered_map<Id, Id> m_nodeIdsToMemberEdgeIds;
|
||||
};
|
||||
|
||||
#endif // PARSER_CLIENT_IMPL_H
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "data/parser/ReferenceKind.h"
|
||||
|
||||
ReferenceKind intToReferenceKind(int v)
|
||||
{
|
||||
switch (v)
|
||||
{
|
||||
case REFERENCE_TYPE_USAGE:
|
||||
return REFERENCE_TYPE_USAGE;
|
||||
case REFERENCE_USAGE:
|
||||
return REFERENCE_USAGE;
|
||||
case REFERENCE_CALL:
|
||||
return REFERENCE_CALL;
|
||||
case REFERENCE_INHERITANCE:
|
||||
return REFERENCE_INHERITANCE;
|
||||
case REFERENCE_OVERRIDE:
|
||||
return REFERENCE_OVERRIDE;
|
||||
case REFERENCE_TEMPLATE_ARGUMENT:
|
||||
return REFERENCE_TEMPLATE_ARGUMENT;
|
||||
case REFERENCE_TYPE_ARGUMENT:
|
||||
return REFERENCE_TYPE_ARGUMENT;
|
||||
case REFERENCE_TEMPLATE_DEFAULT_ARGUMENT:
|
||||
return REFERENCE_TEMPLATE_DEFAULT_ARGUMENT;
|
||||
case REFERENCE_TEMPLATE_SPECIALIZATION_OF:
|
||||
return REFERENCE_TEMPLATE_SPECIALIZATION_OF;
|
||||
case REFERENCE_TEMPLATE_MEMBER_SPECIALIZATION_OF:
|
||||
return REFERENCE_TEMPLATE_MEMBER_SPECIALIZATION_OF;
|
||||
case REFERENCE_INCLUDE:
|
||||
return REFERENCE_INCLUDE;
|
||||
case REFERENCE_IMPORT:
|
||||
return REFERENCE_IMPORT;
|
||||
case REFERENCE_MACRO_USAGE:
|
||||
return REFERENCE_MACRO_USAGE;
|
||||
}
|
||||
return REFERENCE_UNDEFINED;
|
||||
}
|
||||
|
||||
int referenceKindToInt(ReferenceKind t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef REFERENCE_KIND_H
|
||||
#define REFERENCE_KIND_H
|
||||
|
||||
enum ReferenceKind
|
||||
{ // these values need to be the same as ReferenceKind in Java code
|
||||
REFERENCE_UNDEFINED = 0,
|
||||
REFERENCE_TYPE_USAGE = 1,
|
||||
REFERENCE_USAGE = 2,
|
||||
REFERENCE_CALL = 3,
|
||||
REFERENCE_INHERITANCE = 4,
|
||||
REFERENCE_OVERRIDE = 5,
|
||||
REFERENCE_TEMPLATE_ARGUMENT = 6,
|
||||
REFERENCE_TYPE_ARGUMENT = 7,
|
||||
REFERENCE_TEMPLATE_DEFAULT_ARGUMENT = 8,
|
||||
REFERENCE_TEMPLATE_SPECIALIZATION_OF = 9,
|
||||
REFERENCE_TEMPLATE_MEMBER_SPECIALIZATION_OF = 10,
|
||||
REFERENCE_INCLUDE = 11,
|
||||
REFERENCE_IMPORT = 12,
|
||||
REFERENCE_MACRO_USAGE = 13
|
||||
};
|
||||
|
||||
ReferenceKind intToReferenceKind(int v);
|
||||
int referenceKindToInt(ReferenceKind t);
|
||||
|
||||
#endif // REFERENCE_KIND_H
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "data/parser/SymbolKind.h"
|
||||
|
||||
SymbolKind intToSymbolKind(int v)
|
||||
{
|
||||
switch (v)
|
||||
{
|
||||
case SYMBOL_BUILTIN_TYPE:
|
||||
return SYMBOL_BUILTIN_TYPE;
|
||||
case SYMBOL_CLASS:
|
||||
return SYMBOL_CLASS;
|
||||
case SYMBOL_ENUM:
|
||||
return SYMBOL_ENUM;
|
||||
case SYMBOL_ENUM_CONSTANT:
|
||||
return SYMBOL_ENUM_CONSTANT;
|
||||
case SYMBOL_FIELD:
|
||||
return SYMBOL_FIELD;
|
||||
case SYMBOL_FUNCTION:
|
||||
return SYMBOL_FUNCTION;
|
||||
case SYMBOL_GLOBAL_VARIABLE:
|
||||
return SYMBOL_GLOBAL_VARIABLE;
|
||||
case SYMBOL_INTERFACE:
|
||||
return SYMBOL_INTERFACE;
|
||||
case SYMBOL_LOCAL_VARIABLE:
|
||||
return SYMBOL_LOCAL_VARIABLE;
|
||||
case SYMBOL_MACRO:
|
||||
return SYMBOL_MACRO;
|
||||
case SYMBOL_METHOD:
|
||||
return SYMBOL_METHOD;
|
||||
case SYMBOL_NAMESPACE:
|
||||
return SYMBOL_NAMESPACE;
|
||||
case SYMBOL_PACKAGE:
|
||||
return SYMBOL_PACKAGE;
|
||||
case SYMBOL_PARAMETER:
|
||||
return SYMBOL_PARAMETER;
|
||||
case SYMBOL_STRUCT:
|
||||
return SYMBOL_STRUCT;
|
||||
case SYMBOL_TEMPLATE_PARAMETER:
|
||||
return SYMBOL_TEMPLATE_PARAMETER;
|
||||
case SYMBOL_TYPEDEF:
|
||||
return SYMBOL_TYPEDEF;
|
||||
case SYMBOL_TYPE_PARAMETER:
|
||||
return SYMBOL_TYPE_PARAMETER;
|
||||
case SYMBOL_UNION:
|
||||
return SYMBOL_UNION;
|
||||
}
|
||||
return SYMBOL_KIND_MAX;
|
||||
}
|
||||
|
||||
int symbolKindToInt(SymbolKind t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef SYMBOL_KIND_H
|
||||
#define SYMBOL_KIND_H
|
||||
|
||||
enum SymbolKind
|
||||
{ // these values need to be the same as SymbolType in Java code
|
||||
SYMBOL_BUILTIN_TYPE = 1,
|
||||
SYMBOL_CLASS = 2,
|
||||
SYMBOL_ENUM = 3,
|
||||
SYMBOL_ENUM_CONSTANT = 4,
|
||||
SYMBOL_FIELD = 5,
|
||||
SYMBOL_FUNCTION = 6,
|
||||
SYMBOL_GLOBAL_VARIABLE = 7,
|
||||
SYMBOL_INTERFACE = 8,
|
||||
SYMBOL_LOCAL_VARIABLE = 9,
|
||||
SYMBOL_MACRO = 10,
|
||||
SYMBOL_METHOD = 11,
|
||||
SYMBOL_NAMESPACE = 12,
|
||||
SYMBOL_PACKAGE = 13,
|
||||
SYMBOL_PARAMETER = 14,
|
||||
SYMBOL_STRUCT = 15,
|
||||
SYMBOL_TEMPLATE_PARAMETER = 16,
|
||||
SYMBOL_TYPEDEF = 17,
|
||||
SYMBOL_TYPE_PARAMETER = 18,
|
||||
SYMBOL_UNION = 19,
|
||||
SYMBOL_KIND_MAX = 20
|
||||
};
|
||||
|
||||
SymbolKind intToSymbolKind(int v);
|
||||
int symbolKindToInt(SymbolKind t);
|
||||
|
||||
#endif // SYMBOL_KIND_H
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef SYMBOL_TYPE_H
|
||||
#define SYMBOL_TYPE_H
|
||||
|
||||
enum SymbolType
|
||||
{
|
||||
SYMBOL_CLASS,
|
||||
SYMBOL_ENUM,
|
||||
SYMBOL_ENUM_CONSTANT,
|
||||
SYMBOL_FIELD,
|
||||
SYMBOL_FUNCTION,
|
||||
SYMBOL_GLOBAL_VARIABLE,
|
||||
SYMBOL_LOCAL_VARIABLE,
|
||||
SYMBOL_MACRO,
|
||||
SYMBOL_METHOD,
|
||||
SYMBOL_NAMESPACE,
|
||||
SYMBOL_PARAMETER,
|
||||
SYMBOL_STRUCT,
|
||||
SYMBOL_TYPEDEF,
|
||||
SYMBOL_TEMPLATE_PARAMETER,
|
||||
SYMBOL_UNION,
|
||||
SYMBOL_TYPE_MAX
|
||||
};
|
||||
|
||||
#endif // SYMBOL_TYPE_H
|
||||
@@ -5,22 +5,21 @@
|
||||
|
||||
#include "data/parser/Parser.h"
|
||||
#include "data/parser/ParserClientImpl.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
#include "utility/scheduling/TaskDecorator.h"
|
||||
#include "utility/TimePoint.h"
|
||||
|
||||
class PersistentStorage;
|
||||
class FileRegister;
|
||||
class CxxParser;
|
||||
|
||||
class TaskParseWrapper
|
||||
: public Task
|
||||
: public TaskDecorator
|
||||
{
|
||||
public:
|
||||
TaskParseWrapper(
|
||||
std::shared_ptr<Task> child,
|
||||
PersistentStorage* storage,
|
||||
std::shared_ptr<FileRegister> fileRegister
|
||||
);
|
||||
virtual ~TaskParseWrapper();
|
||||
|
||||
virtual void enter();
|
||||
virtual TaskState update();
|
||||
@@ -30,10 +29,8 @@ public:
|
||||
virtual void revert();
|
||||
|
||||
private:
|
||||
std::shared_ptr<Task> m_child;
|
||||
PersistentStorage* m_storage;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
|
||||
TimePoint m_start;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
#include "data/parser/java/JavaEnvironment.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "data/parser/java/JavaEnvironmentFactory.h"
|
||||
|
||||
JavaEnvironment::~JavaEnvironment()
|
||||
{
|
||||
JavaEnvironmentFactory::getInstance()->unregisterEnvironment();
|
||||
}
|
||||
|
||||
bool JavaEnvironment::callStaticVoidMethod(std::string className, std::string methodName, int arg1, std::string arg2, std::string arg3, std::string arg4)
|
||||
{
|
||||
jclass javaClass = m_env->FindClass(className.c_str());
|
||||
if(javaClass == nullptr)
|
||||
{
|
||||
LOG_ERROR("class " + className + " not found in JVM environment");
|
||||
jthrowable exc = m_env->ExceptionOccurred();
|
||||
if(exc)
|
||||
{
|
||||
m_env->ExceptionDescribe();
|
||||
m_env->ExceptionClear();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
jmethodID javaMethodId = m_env->GetStaticMethodID(javaClass, methodName.c_str(), "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
if(javaMethodId == nullptr)
|
||||
{
|
||||
LOG_ERROR("method void " + methodName + "(int, String, String, String) not found in JVM environment");
|
||||
}
|
||||
else
|
||||
{
|
||||
jint jarg1 = arg1;
|
||||
jstring jarg2 = m_env->NewStringUTF(arg2.c_str());
|
||||
jstring jarg3 = m_env->NewStringUTF(arg3.c_str());
|
||||
jstring jarg4 = m_env->NewStringUTF(arg4.c_str());
|
||||
m_env->CallStaticVoidMethod(javaClass, javaMethodId, jarg1, jarg2, jarg3, jarg4);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string JavaEnvironment::toStdString(jstring s)
|
||||
{
|
||||
const char *nativeString = m_env->GetStringUTFChars(s, 0);
|
||||
std::string ret = nativeString;
|
||||
m_env->ReleaseStringUTFChars(s, nativeString);
|
||||
return ret;
|
||||
}
|
||||
|
||||
jstring JavaEnvironment::toJString(std::string s)
|
||||
{
|
||||
return m_env->NewStringUTF(s.c_str());
|
||||
}
|
||||
|
||||
JavaEnvironment::JavaEnvironment(JavaVM* jvm, JNIEnv* env)
|
||||
: m_jvm(jvm)
|
||||
, m_env(env)
|
||||
{
|
||||
JavaEnvironmentFactory::getInstance()->registerEnvironment();
|
||||
}
|
||||
|
||||
void JavaEnvironment::registerNativeMethods(std::string className, std::vector<NativeMethod> methods)
|
||||
{
|
||||
JNINativeMethod* jniMethods = new JNINativeMethod[methods.size()];
|
||||
|
||||
for (int i = 0; i < methods.size(); i++)
|
||||
{
|
||||
jniMethods[i].name = const_cast<char*>(methods[i].name.c_str());
|
||||
jniMethods[i].signature = const_cast<char*>(methods[i].signature.c_str());
|
||||
jniMethods[i].fnPtr = methods[i].function;
|
||||
}
|
||||
|
||||
jclass javaClass = m_env->FindClass(className.c_str());
|
||||
if (javaClass)
|
||||
{
|
||||
if (m_env->RegisterNatives(javaClass, jniMethods, methods.size()) < 0)
|
||||
{
|
||||
LOG_ERROR("RegisterNatives failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("class \"" + className + "\" not found while registering native methods");
|
||||
}
|
||||
|
||||
delete [] jniMethods;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef JAVA_ENVIRONMENT_H
|
||||
#define JAVA_ENVIRONMENT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct JavaVM_;
|
||||
typedef JavaVM_ JavaVM;
|
||||
|
||||
struct JNIEnv_;
|
||||
typedef JNIEnv_ JNIEnv;
|
||||
|
||||
class _jstring;
|
||||
typedef _jstring *jstring;
|
||||
|
||||
class JavaEnvironmentFactory;
|
||||
|
||||
class JavaEnvironment
|
||||
{
|
||||
public:
|
||||
struct NativeMethod
|
||||
{
|
||||
std::string name;
|
||||
std::string signature;
|
||||
void *function;
|
||||
};
|
||||
|
||||
~JavaEnvironment();
|
||||
bool callStaticVoidMethod(std::string className, std::string methodName, int arg1, std::string arg2, std::string arg3, std::string arg4);
|
||||
|
||||
std::string toStdString(jstring s);
|
||||
jstring toJString(std::string s);
|
||||
|
||||
void registerNativeMethods(std::string className, std::vector<NativeMethod> methods);
|
||||
private:
|
||||
friend class JavaEnvironmentFactory;
|
||||
|
||||
JavaEnvironment(JavaVM* jvm, JNIEnv* env);
|
||||
|
||||
JavaVM* m_jvm;
|
||||
JNIEnv* m_env;
|
||||
};
|
||||
|
||||
#endif // JAVA_ENVIRONMENT_H
|
||||
@@ -0,0 +1,170 @@
|
||||
#include "data/parser/java/JavaEnvironmentFactory.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "data/parser/java/JavaEnvironment.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
void JavaEnvironmentFactory::createInstance(std::string classPath)
|
||||
{
|
||||
if (s_instance)
|
||||
{
|
||||
if (classPath == s_classPath)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("java classpath cannot be changed!");
|
||||
// todo: implement destroying the old factory instance and create a new one.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
s_classPath = classPath;
|
||||
|
||||
#ifdef _WIN32
|
||||
{ // todo: make this windows only
|
||||
std::string env1 = getenv("path");
|
||||
|
||||
std::string javapath = ApplicationSettings::getInstance()->getJavaPath() + "/client/";
|
||||
putenv(("path=" + env1 + ";" + javapath).c_str()); // path env is only modified in the scope of this process.
|
||||
}
|
||||
#endif
|
||||
using namespace std;
|
||||
|
||||
JavaVM* jvm; // Pointer to the JVM (Java Virtual Machine)
|
||||
JNIEnv* env; // Pointer to native interface
|
||||
|
||||
JavaVMInitArgs vm_args; // Initialization arguments
|
||||
JavaVMOption* options = new JavaVMOption[3]; // JVM invocation options
|
||||
std::string classPathOption = "-Djava.class.path=" + classPath;
|
||||
options[0].optionString = const_cast<char*>(classPathOption.c_str());
|
||||
options[1].optionString = "-Xms1m";
|
||||
std::string maximumMemoryOprionString = "-Xmx" + std::to_string(ApplicationSettings::getInstance()->getJavaMaximumMemory()) + "m";
|
||||
options[2].optionString = const_cast<char*>(maximumMemoryOprionString.c_str());
|
||||
// options[3].optionString = "-verbose:jni";
|
||||
vm_args.version = JNI_VERSION_1_6; // minimum Java version
|
||||
vm_args.nOptions = 3; // number of options
|
||||
vm_args.options = options;
|
||||
vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail
|
||||
|
||||
jint rc = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); // YES !!
|
||||
|
||||
delete options;
|
||||
|
||||
if(rc != JNI_OK)
|
||||
{
|
||||
if(rc == JNI_EVERSION)
|
||||
{
|
||||
LOG_ERROR("JVM is oudated and doesn't meet requirements");
|
||||
}
|
||||
else if(rc == JNI_ENOMEM)
|
||||
{
|
||||
LOG_ERROR("not enough memory for JVM");
|
||||
}
|
||||
else if(rc == JNI_EINVAL)
|
||||
{
|
||||
LOG_ERROR("invalid ragument for launching JVM");
|
||||
}
|
||||
else if(rc == JNI_EEXIST)
|
||||
{
|
||||
LOG_ERROR("the process can only launch one JVM an not more");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "could not create the JVM instance (error code " << rc << ")");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
jvm->DetachCurrentThread();
|
||||
s_instance = std::shared_ptr<JavaEnvironmentFactory>(new JavaEnvironmentFactory(jvm));
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<JavaEnvironmentFactory> JavaEnvironmentFactory::getInstance()
|
||||
{
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
JavaEnvironmentFactory::~JavaEnvironmentFactory()
|
||||
{
|
||||
// todo: what if there are threads running using the jvm?? log something!
|
||||
m_jvm->DestroyJavaVM();
|
||||
}
|
||||
|
||||
std::shared_ptr<JavaEnvironment> JavaEnvironmentFactory::createEnvironment()
|
||||
{
|
||||
std::thread::id currentThreadId = std::this_thread::get_id();
|
||||
|
||||
JNIEnv* env;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadIdToEnvAndUserCountMutex);
|
||||
|
||||
std::map<std::thread::id, std::pair<JNIEnv*, int>>::const_iterator it = m_threadIdToEnvAndUserCount.find(currentThreadId);
|
||||
if (it != m_threadIdToEnvAndUserCount.end())
|
||||
{
|
||||
env = it->second.first;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_jvm->AttachCurrentThread((void**)&env, NULL);
|
||||
m_threadIdToEnvAndUserCount.insert(std::make_pair(currentThreadId, std::make_pair(env, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
return std::shared_ptr<JavaEnvironment>(new JavaEnvironment(m_jvm, env));
|
||||
}
|
||||
|
||||
std::shared_ptr<JavaEnvironmentFactory> JavaEnvironmentFactory::s_instance;
|
||||
|
||||
std::string JavaEnvironmentFactory::s_classPath;
|
||||
|
||||
JavaEnvironmentFactory::JavaEnvironmentFactory(JavaVM* jvm)
|
||||
: m_jvm(jvm)
|
||||
{
|
||||
}
|
||||
|
||||
void JavaEnvironmentFactory::registerEnvironment()
|
||||
{
|
||||
std::thread::id currentThreadId = std::this_thread::get_id();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadIdToEnvAndUserCountMutex);
|
||||
std::map<std::thread::id, std::pair<JNIEnv*, int>>::iterator it = m_threadIdToEnvAndUserCount.find(currentThreadId);
|
||||
if (it != m_threadIdToEnvAndUserCount.end())
|
||||
{
|
||||
it->second.second++;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("something went horribly wrong while registering a java environment");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JavaEnvironmentFactory::unregisterEnvironment()
|
||||
{
|
||||
std::thread::id currentThreadId = std::this_thread::get_id();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadIdToEnvAndUserCountMutex);
|
||||
std::map<std::thread::id, std::pair<JNIEnv*, int>>::iterator it = m_threadIdToEnvAndUserCount.find(currentThreadId);
|
||||
if (it != m_threadIdToEnvAndUserCount.end())
|
||||
{
|
||||
it->second.second--;
|
||||
if (it->second.second == 0)
|
||||
{ // TODO: currently this happens quite often. do something about that.
|
||||
m_jvm->DetachCurrentThread();
|
||||
m_threadIdToEnvAndUserCount.erase(it);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("something went horribly wrong while unregistering a java environment");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef JAVA_ENVIRONMENT_FACTORY_H
|
||||
#define JAVA_ENVIRONMENT_FACTORY_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
struct JavaVM_;
|
||||
typedef JavaVM_ JavaVM;
|
||||
|
||||
struct JNIEnv_;
|
||||
typedef JNIEnv_ JNIEnv;
|
||||
|
||||
class JavaEnvironment;
|
||||
|
||||
class JavaEnvironmentFactory
|
||||
{
|
||||
public:
|
||||
static void createInstance(std::string classPath);
|
||||
static std::shared_ptr<JavaEnvironmentFactory> getInstance();
|
||||
|
||||
~JavaEnvironmentFactory();
|
||||
|
||||
std::shared_ptr<JavaEnvironment> createEnvironment();
|
||||
|
||||
private:
|
||||
friend class JavaEnvironment;
|
||||
|
||||
static std::shared_ptr<JavaEnvironmentFactory> s_instance;
|
||||
static std::string s_classPath;
|
||||
|
||||
JavaEnvironmentFactory(JavaVM* jvm);
|
||||
|
||||
void registerEnvironment();
|
||||
void unregisterEnvironment();
|
||||
|
||||
JavaVM* m_jvm;
|
||||
std::map<std::thread::id, std::pair<JNIEnv*, int>> m_threadIdToEnvAndUserCount;
|
||||
std::mutex m_threadIdToEnvAndUserCountMutex;
|
||||
};
|
||||
|
||||
#endif // JAVA_ENVIRONMENT_FACTORY_H
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef TASK_PARSE_JAVA_H
|
||||
#define TASK_PARSE_JAVA_H
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "data/parser/Parser.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
|
||||
class FileRegister;
|
||||
class PersistentStorage;
|
||||
|
||||
class TaskParseJava
|
||||
: public Task
|
||||
{
|
||||
public:
|
||||
TaskParseJava(
|
||||
PersistentStorage* storage,
|
||||
std::shared_ptr<std::mutex> storageMutex,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
const Parser::Arguments& arguments
|
||||
);
|
||||
|
||||
virtual void enter();
|
||||
virtual TaskState update();
|
||||
virtual void exit();
|
||||
|
||||
virtual void interrupt();
|
||||
virtual void revert();
|
||||
|
||||
private:
|
||||
PersistentStorage* m_storage;
|
||||
std::shared_ptr<std::mutex> m_storageMutex;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
Parser::Arguments m_arguments;
|
||||
};
|
||||
|
||||
#endif // TASK_PARSE_JAVA_H
|
||||
@@ -35,46 +35,6 @@ int ApplicationSettings::getMaxRecentProjectsCount() const
|
||||
return 7;
|
||||
}
|
||||
|
||||
std::vector<FilePath> ApplicationSettings::getHeaderSearchPaths() const
|
||||
{
|
||||
return getPathValues("source/header_search_paths/header_search_path");
|
||||
}
|
||||
|
||||
std::vector<FilePath> ApplicationSettings::getHeaderSearchPathsExpanded() const
|
||||
{
|
||||
std::vector<FilePath> paths = getPathValues("source/header_search_paths/header_search_path");
|
||||
expandPaths(paths);
|
||||
return paths;
|
||||
}
|
||||
|
||||
bool ApplicationSettings::setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths)
|
||||
{
|
||||
return setPathValues("source/header_search_paths/header_search_path", headerSearchPaths);
|
||||
}
|
||||
|
||||
std::vector<FilePath> ApplicationSettings::getFrameworkSearchPaths() const
|
||||
{
|
||||
return getPathValues("source/framework_search_paths/framework_search_path");
|
||||
}
|
||||
|
||||
std::vector<FilePath> ApplicationSettings::getFrameworkSearchPathsExpanded() const
|
||||
{
|
||||
std::vector<FilePath> paths = getPathValues("source/framework_search_paths/framework_search_path");
|
||||
expandPaths(paths);
|
||||
return paths;
|
||||
}
|
||||
|
||||
bool ApplicationSettings::setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths)
|
||||
{
|
||||
return setPathValues("source/framework_search_paths/framework_search_path", frameworkSearchPaths);
|
||||
}
|
||||
|
||||
std::vector<std::string> ApplicationSettings::getCompilerFlags() const
|
||||
{
|
||||
std::vector<std::string> defaultValues;
|
||||
return getValues("source/compiler_flags/compiler_flag", defaultValues);
|
||||
}
|
||||
|
||||
std::string ApplicationSettings::getFontName() const
|
||||
{
|
||||
return getValue<std::string>("application/font_name", "Source Code Pro");
|
||||
@@ -143,14 +103,24 @@ void ApplicationSettings::setFontSizeStd(const int fontSizeStd)
|
||||
setValue<int>("application/font_size_std", fontSizeStd);
|
||||
}
|
||||
|
||||
int ApplicationSettings::getWindowBaseWidth() const
|
||||
{
|
||||
return getValue<int>("application/window_base_width", 500);
|
||||
}
|
||||
|
||||
int ApplicationSettings::getWindowBaseHeight() const
|
||||
{
|
||||
return getValue<int>("application/window_base_height", 500);
|
||||
}
|
||||
|
||||
int ApplicationSettings::getIndexerThreadCount() const
|
||||
{
|
||||
return getValue<int>("application/indexer_thread_count", 4);
|
||||
return getValue<int>("indexing/indexer_thread_count", 4);
|
||||
}
|
||||
|
||||
void ApplicationSettings::setIndexerThreadCount(const int count)
|
||||
{
|
||||
setValue<int>("application/indexer_thread_count", count);
|
||||
setValue<int>("indexing/indexer_thread_count", count);
|
||||
}
|
||||
|
||||
bool ApplicationSettings::getShowExternalNonFatalErrors() const
|
||||
@@ -163,14 +133,58 @@ void ApplicationSettings::setShowExternalNonFatalErrors(const bool show)
|
||||
setValue<bool>("application/show_external_non_fatal_errors", show);
|
||||
}
|
||||
|
||||
int ApplicationSettings::getWindowBaseWidth() const
|
||||
std::string ApplicationSettings::getJavaPath() const
|
||||
{
|
||||
return getValue<int>("application/window_base_width", 500);
|
||||
return getValue<std::string>("indexing/java/java_path", "");
|
||||
}
|
||||
|
||||
int ApplicationSettings::getWindowBaseHeight() const
|
||||
void ApplicationSettings::setJavaPath(const std::string path)
|
||||
{
|
||||
return getValue<int>("application/window_base_height", 500);
|
||||
setValue<std::string>("indexing/java/java_path", path);
|
||||
}
|
||||
|
||||
int ApplicationSettings::getJavaMaximumMemory() const
|
||||
{
|
||||
return getValue<int>("indexing/java/java_maximum_memory", 512);
|
||||
}
|
||||
|
||||
void ApplicationSettings::setJavaMaximumMemory(int size)
|
||||
{
|
||||
setValue<int>("indexing/java/java_maximum_memory", size);
|
||||
}
|
||||
|
||||
std::vector<FilePath> ApplicationSettings::getHeaderSearchPaths() const
|
||||
{
|
||||
return getPathValues("indexing/cxx/header_search_paths/header_search_path");
|
||||
}
|
||||
|
||||
std::vector<FilePath> ApplicationSettings::getHeaderSearchPathsExpanded() const
|
||||
{
|
||||
std::vector<FilePath> paths = getHeaderSearchPaths();
|
||||
expandPaths(paths);
|
||||
return paths;
|
||||
}
|
||||
|
||||
bool ApplicationSettings::setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths)
|
||||
{
|
||||
return setPathValues("indexing/cxx/header_search_paths/header_search_path", headerSearchPaths);
|
||||
}
|
||||
|
||||
std::vector<FilePath> ApplicationSettings::getFrameworkSearchPaths() const
|
||||
{
|
||||
return getPathValues("indexing/cxx/framework_search_paths/framework_search_path");
|
||||
}
|
||||
|
||||
std::vector<FilePath> ApplicationSettings::getFrameworkSearchPathsExpanded() const
|
||||
{
|
||||
std::vector<FilePath> paths = getFrameworkSearchPaths();
|
||||
expandPaths(paths);
|
||||
return paths;
|
||||
}
|
||||
|
||||
bool ApplicationSettings::setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths)
|
||||
{
|
||||
return setPathValues("indexing/cxx/framework_search_paths/framework_search_path", frameworkSearchPaths);
|
||||
}
|
||||
|
||||
int ApplicationSettings::getCodeTabWidth() const
|
||||
|
||||
@@ -17,17 +17,6 @@ public:
|
||||
|
||||
int getMaxRecentProjectsCount() const;
|
||||
|
||||
// source
|
||||
std::vector<FilePath> getHeaderSearchPaths() const;
|
||||
std::vector<FilePath> getHeaderSearchPathsExpanded() const;
|
||||
bool setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths);
|
||||
|
||||
std::vector<FilePath> getFrameworkSearchPaths() const;
|
||||
std::vector<FilePath> getFrameworkSearchPathsExpanded() const;
|
||||
bool setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths);
|
||||
|
||||
std::vector<std::string> getCompilerFlags() const;
|
||||
|
||||
// application
|
||||
std::string getFontName() const;
|
||||
void setFontName(const std::string& fontName);
|
||||
@@ -47,14 +36,28 @@ public:
|
||||
int getFontSizeStd() const;
|
||||
void setFontSizeStd(const int fontSizeStd);
|
||||
|
||||
int getWindowBaseWidth() const;
|
||||
int getWindowBaseHeight() const;
|
||||
|
||||
int getIndexerThreadCount() const;
|
||||
void setIndexerThreadCount(const int count);
|
||||
|
||||
bool getShowExternalNonFatalErrors() const;
|
||||
void setShowExternalNonFatalErrors(const bool show);
|
||||
|
||||
int getWindowBaseWidth() const;
|
||||
int getWindowBaseHeight() const;
|
||||
std::string getJavaPath() const;
|
||||
void setJavaPath(const std::string path);
|
||||
|
||||
int getJavaMaximumMemory() const;
|
||||
void setJavaMaximumMemory(int size);
|
||||
|
||||
std::vector<FilePath> getHeaderSearchPaths() const;
|
||||
std::vector<FilePath> getHeaderSearchPathsExpanded() const;
|
||||
bool setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths);
|
||||
|
||||
std::vector<FilePath> getFrameworkSearchPaths() const;
|
||||
std::vector<FilePath> getFrameworkSearchPathsExpanded() const;
|
||||
bool setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths);
|
||||
|
||||
// code
|
||||
int getCodeTabWidth() const;
|
||||
|
||||
@@ -82,6 +82,19 @@ bool ProjectSettings::setStandard(const std::string& standard)
|
||||
return setValue<std::string>("language_settings/standard", standard);
|
||||
}
|
||||
|
||||
std::vector<FilePath> ProjectSettings::getJavaClasspaths() const
|
||||
{
|
||||
return getPathValues("source/class_paths/class_path");
|
||||
}
|
||||
|
||||
std::vector<FilePath> ProjectSettings::getAbsoluteJavaClasspaths() const
|
||||
{
|
||||
std::vector<FilePath> paths = getJavaClasspaths();
|
||||
expandPaths(paths);
|
||||
makePathsAbsolute(paths);
|
||||
return paths;
|
||||
}
|
||||
|
||||
std::vector<FilePath> ProjectSettings::getSourcePaths() const
|
||||
{
|
||||
return getPathValues("source/source_paths/source_path");
|
||||
|
||||
@@ -28,6 +28,10 @@ public:
|
||||
std::string getStandard() const;
|
||||
bool setStandard(const std::string& standard);
|
||||
|
||||
// java... todo: move this
|
||||
std::vector<FilePath> getJavaClasspaths() const;
|
||||
std::vector<FilePath> getAbsoluteJavaClasspaths() const;
|
||||
|
||||
// source
|
||||
std::vector<FilePath> getSourcePaths() const;
|
||||
std::vector<FilePath> getAbsoluteSourcePaths() const;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "utility/scheduling/TaskDecorator.h"
|
||||
|
||||
TaskDecorator::TaskDecorator()
|
||||
{
|
||||
}
|
||||
|
||||
TaskDecorator::~TaskDecorator()
|
||||
{
|
||||
}
|
||||
|
||||
void TaskDecorator::setTask(std::shared_ptr<Task> task)
|
||||
{
|
||||
m_task = task;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef TASK_DECORATOR_H
|
||||
#define TASK_DECORATOR_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "utility/scheduling/Task.h"
|
||||
|
||||
class TaskDecorator
|
||||
: public Task
|
||||
{
|
||||
public:
|
||||
TaskDecorator();
|
||||
virtual ~TaskDecorator();
|
||||
|
||||
void setTask(std::shared_ptr<Task> task);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Task> m_task;
|
||||
};
|
||||
|
||||
#endif // TASK_DECORATOR_H
|
||||
Reference in New Issue
Block a user