sighingnow / libclang

(Unofficial) Release libclang (clang.cindex) on pypi.
https://pypi.org/project/libclang
Other
85 stars 23 forks source link

Inline method call, unrecognized #48

Open skarl-api opened 1 year ago

skarl-api commented 1 year ago

give an example

bool file_exists(const std::string &file) {
    std::ifstream infile(file);
    if (!infile.is_open()) {
        return false;
    }
    infile.close();
    return true;
}
bool read_file_to_string(const std::string file_path, std::string &str) {
    if (!file_exists(file_path)) {
        return false;
    }
    std::ifstream file{file_path};
    str = std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
    file.close();
    return true;
}

config

Config.set_library_file('/usr/local/Cellar/llvm@14/14.0.6/lib/libclang.dylib')

use code

print(f"{'  ' * level} {str(node.kind)}: {node.spelling}")
for child in node.get_children():
    self.print_ast(child, code_source, file_path, level + 1)

Unable to output read file to String called file exists

skarl-api commented 1 year ago

@torfinnberset @storypku @sighingnow @nabhoneel

sighingnow commented 1 year ago

Which version are you working with? If you install the clang bindings using pip3 install libclang (note that the package name is libclang) you don't need the Config.set_library_file anymore.

skarl-api commented 1 year ago

Which version are you working with? If you install the clang bindings using pip3 install libclang (note that the package name is libclang) you don't need the Config.set_library_file anymore.

system:mac pythonversion 3.9.9 libclang version 14.0

Even if set is not set library File is not allowed either

Is there any code that I can refer to for the above example?

sighingnow commented 1 year ago

I cannot see which was going wrong as I cannot know how your dump_ast are implemented. But I can provides you a reference implementation in another project:

https://github.com/v6d-io/v6d/blob/main/python/vineyard/core/codegen/parsing.py#L302

As well as the settings the parse the file:

https://github.com/v6d-io/v6d/blob/main/python/vineyard/core/codegen/parsing.py#L613

Hope that could be helpful.

skarl-api commented 1 year ago

I cannot see which was going wrong as I cannot know how your dump_ast are implemented. But I can provides you a reference implementation in another project:

https://github.com/v6d-io/v6d/blob/main/python/vineyard/core/codegen/parsing.py#L302

As well as the settings the parse the file:

https://github.com/v6d-io/v6d/blob/main/python/vineyard/core/codegen/parsing.py#L613

Hope that could be helpful.

Following your prompts, I'll try it

skarl-api commented 1 year ago

https://github.com/v6d-io/v6d/blob/main/python/vineyard/core/codegen/parsing.py#L613

CALL_EXPR, t:

How do I continue parsing?
skarl-api commented 1 year ago

@sighingnow

sighingnow commented 1 year ago

CALL_EXPR, t: How do I continue parsing?

Could you please describe your problem in a more detail? e.g., Parsing which file, and encounter which unexpected behaviour? as well as the behavior/output that you desired?

skarl-api commented 1 year ago

give an example

bool file_exists(const std::string &file) {
    std::ifstream infile(file);
    if (!infile.is_open()) {
        return false;
    }
    infile.close();
    return true;
}
bool read_file_to_string(const std::string file_path, std::string &str) {
    if (!file_exists(file_path)) {
        return false;
    }
    std::ifstream file{file_path};
    str = std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
    file.close();
    return true;
}

config

Config.set_library_file('/usr/local/Cellar/llvm@14/14.0.6/lib/libclang.dylib')

use code

print(f"{'  ' * level} {str(node.kind)}: {node.spelling}")
for child in node.get_children():
    self.print_ast(child, code_source, file_path, level + 1)

Unable to output read file to String called file exists

@sighingnow

Using dump Ast parsing, when parsing to CursorKind. CAL During EXPR, the output value of t is. How to obtain the specific function; Actually, it should be a file_ exists

image

skarl-api commented 1 year ago

@torfinnberset @storypku @nabhoneel