Giter Club home page Giter Club logo

Comments (8)

KyleMayes avatar KyleMayes commented on August 21, 2024 2

Yeah, it kinda sucks. It's still 100x easier to use than the raw bindings.

The libclang API is just really awkward, even as C APIs go.

from clang-rs.

KyleMayes avatar KyleMayes commented on August 21, 2024 1

d7507ed

from clang-rs.

KyleMayes avatar KyleMayes commented on August 21, 2024

Interesting, I hadn't thought about that.

Another idea would be to leave Entity as a struct but add fields that are specific to only a few EntityKinds to the EntityKind variant.

E.g., Entity::get_file would be removed (because it is only used for inclusion directives) and the EntityKind::InclusionDirective variant would become EntityKind::InclusionDirective(File<'tu>).

I'll have to think about it.

from clang-rs.

KyleMayes avatar KyleMayes commented on August 21, 2024

I've thought about it, and I'm not sure it's worth the implementation difficulty. There would still be many fields common to most entity kinds.

if let Entity::InclusionDirective(file) = entity {
    let name = entity.get_name().unwrap();
}

doesn't seem much better than

if entity.get_kind() == EntityKind::InclusionDirective {
    let name = entity.get_name().unwrap();
    let file = entity.get_file().unwrap();
}

to me.

There's less unwrap with the pattern matching, but it wouldn't eliminate it completely. Some entities would still have an optional name and some would still have an optional source range.

from clang-rs.

KyleMayes avatar KyleMayes commented on August 21, 2024

However, something like

if let EntityKind::InclusionDirective(file) = entity.get_kind() {
    let name = entity.get_name().unwrap();
}

might work. I'll start looking into it.

from clang-rs.

KyleMayes avatar KyleMayes commented on August 21, 2024

Well I tried, but it doesn't seem practical to map libclang's API into anything other than what it is now.

from clang-rs.

Yamakaky avatar Yamakaky commented on August 21, 2024

The you crate is not really rust idiomatic ;)

from clang-rs.

Yamakaky avatar Yamakaky commented on August 21, 2024

This crate will not be used a lot (only crates which manipulates c code), so it's not a big issue.

from clang-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.