0

I want to parse

if (email.find ("@")! = String :: npos) {cout << "Correct"; } 

hild nodes get so

node.getchildren ()

BUT CLang not find if statement node, because in the condition there

email.find ("@")! = String :: npos

Now this statement

if (a == b) {// do something } 

it finds no problems.

HOW IT WORKS? help me please.

My code

Recursive method of tree traversal

    def search_in_ast(self, node, look):
    """
    Поиск однотипных узлов в синтаксическом дереве
    Args:
        node: узел дерева, в котором будет осуществляться рекурсивный поиск
        look: массив искомых представлений узлов (VAR_DECL, FUNCTION_DECL и др) node.kind

    Returns: массив найденных узлов

    """
    nodes_decl = []
    # n = list(node.get_tokens())
    if node.kind in look:
        nodes_decl.append(node)

    # рекурсивный обход дочерних узлов
    for c in node.get_children():

        # обход дочерних узлов выполняется только в файле - main, чтобы не тратить время на стандартные инклюды
        file_name = c.location.file.name.decode("utf-8")
        if file_name == self.path_to_source_code:
            new_vars = self.search_in_ast(c, look)
            if new_vars:
                nodes_decl = nodes_decl + new_vars
    return nodes_decl

So getting the right type of nodes

match_nodes = [clang.cindex.CursorKind.IF_STMT]
nodes = self.search_in_ast(node, match_nodes)

0 Answers0