-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close #8 #33
Close #8 #33
Conversation
…read_graphviz_new>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As get there a lot of files from @AlexanderMishutkin commits, but you can both take it into account.
According to the design of a builder, as we were talking before, we better separate functionalities of storing paths to virtual machines, calling them and parsing dot file to our structure. You better do it within a single class.
@@ -1,10 +1,12 @@ | |||
project(uast_core) | |||
|
|||
set(SOURCE_LIB uast.h uast_stub.cpp) | |||
set(CMAKE_CXX_FLAGS -lboost_graph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You already link boost_graph with target_link_library
. Do you need to add this flag?
|
||
add_library(uast_core STATIC ${SOURCE_LIB}) | ||
|
||
target_link_libraries(uast_core LINK_PUBLIC cpp_parser) | ||
target_link_libraries(uast_core cpp_parser) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have you removed LINK_PUBLIC
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow there was double including of this file...
|
||
add_library(uast_core STATIC ${SOURCE_LIB}) | ||
|
||
target_link_libraries(uast_core LINK_PUBLIC cpp_parser) | ||
target_link_libraries(uast_core cpp_parser) | ||
target_link_libraries(uast_core boost_graph boost_regex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can link all needed libraries in one target_link_libraries
call.
#include <vector> | ||
|
||
namespace uast { | ||
class Node { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We better dont indent code inside namespace block, because usually all files declare some namespace, but extra indentation increase code readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can change the style, but it would be har, cause all the IDLE's use such indentation by default, but they can be customized, of course. Should we do it anyway?
|
||
namespace uast { | ||
class Node { | ||
std::unordered_multimap<std::string, std::shared_ptr<Node>> nodes_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you use shared pointer? Who else sharing ownership of a node. except its parent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One main link is stored in parent's Node. But pointers are also used in iterators and can be customly done by user to reduct tree. This logic could be realized via weak_pointers, but they are too complicated.
|
||
return *rootP->first; | ||
} | ||
|
||
std::string Stub() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can delete stub for now.
const std::string& pythonVmPath) { | ||
|
||
const std::string runCppParser = "cpp_parser/cpp_parser.exe", | ||
runJavaParser = javaVmPath + "java -jar java_parser/java_parser.jar", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I see here, you expect user to provide a path to directory. Here I see few problems. First, user may not provide a separator /
, making usual concatenation error prone. Second, the name of the virtual machine may not be java
, but java11
or something like this. I think we have to make user specify full path to virtual machine, to avoid such errors.
|
||
system(runParserCommand.c_str()); | ||
|
||
const std::string gvFilePath = "graph.dot"; // Where is parser result? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You better specify output file name on your own. You might create a string template and substitute into it output file name, making it each time different. Check for some functions, how to generate unique file name.
boost::graph_traits<graph_t>::out_edge_iterator eIt, edge_end; | ||
|
||
// Parse boost::graph to uast | ||
for (boost::tie(vIt, end) = boost::vertices(graph); vIt != end; vIt++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is first statement in for
cycle?
boost::tie(vIt, end) = boost::vertices(graph)
does it declare any cycle index?
vertex_t v = *vIt; | ||
if (nodes.find(v) == nodes.end()) { | ||
nodes[v] = std::make_shared<Node>(typeMap[v]); | ||
degrees[nodes[v]] = 0; | ||
} | ||
|
||
for (boost::tie(eIt, edge_end) = boost::out_edges(*vIt, graph); eIt != edge_end; eIt++) { | ||
vertex_t to = boost::target(*eIt, graph); | ||
if (nodes.find(to) == nodes.end()) { | ||
nodes[to] = std::make_shared<Node>(typeMap[to]); | ||
} | ||
nodes[v]->AddChild(nameMap[*eIt], nodes[to]); | ||
degrees[nodes[to]]++; | ||
} | ||
} | ||
|
||
auto rootP = | ||
std::find_if(degrees.begin(), degrees.end(), [](const auto& p) { return p.second == 0; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is really hard for me to understand this code, it might need some explanation, like comments, ecomposition to several functions with proper names, etc.
@elevankoff, please, can you move the biggest part of your code from uast.h, wich is used just for including other headers and defining namespaces, to some specific files 🙏 |
Да просто увидел открытый ПР неактуальный -- решил закопать |
Ну так)) Все по Джордану Питерсану, если ты понимаешь о чем я ахахах С наступающим!) |
Added UAST builder and related functions.