Skip to content
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

Closed
wants to merge 10 commits into from
Closed

Close #8 #33

wants to merge 10 commits into from

Conversation

elevankoff
Copy link
Collaborator

Added UAST builder and related functions.

@elevankoff elevankoff self-assigned this Dec 4, 2020
@elevankoff elevankoff linked an issue Dec 4, 2020 that may be closed by this pull request
@elevankoff elevankoff closed this Dec 4, 2020
@elevankoff elevankoff reopened this Dec 5, 2020
Copy link
Owner

@aravij aravij left a 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)
Copy link
Owner

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)
Copy link
Owner

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?

Copy link
Collaborator

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)
Copy link
Owner

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 {
Copy link
Owner

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.

Copy link
Collaborator

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_;
Copy link
Owner

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?

Copy link
Collaborator

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() {
Copy link
Owner

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",
Copy link
Owner

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?
Copy link
Owner

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++) {
Copy link
Owner

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?

Comment on lines +90 to +107
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; });
Copy link
Owner

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.

@AlexanderMishutkin
Copy link
Collaborator

@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 🙏

@AlexanderMishutkin AlexanderMishutkin changed the title [8] UAST builder Close #8 Jan 26, 2021
@elevankoff elevankoff closed this Dec 24, 2022
@elevankoff
Copy link
Collaborator Author

@elevankoff

А, собственно, почему вдруг?))

Да просто увидел открытый ПР неактуальный -- решил закопать
Зачистка перед Новым годом)

@elevankoff
Copy link
Collaborator Author

И то верно. Потомуто

а) никогда не вредно убраться

б) может когда-нибудь во время технологической сингулярности на руинах человеческой цивилизации какая-нибудь GPTшка найдет этот проект на гите, оценит идею и завершит его. Она будет благодарна тому, что репа в борядке

Ну так)) Все по Джордану Питерсану, если ты понимаешь о чем я ахахах

С наступающим!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UAST builder
3 participants