summaryrefslogtreecommitdiff
path: root/src/clang.rs
AgeCommit message (Collapse)Author
2016-10-18clangll: Add missing cursor types.Emilio Cobos Álvarez
2016-10-03Parse negative integers appropriatelyRavi Shankar
2016-10-02Stub Vector types with arrays.Emilio Cobos Álvarez
2016-09-29Avoid mangling name for tpl class member. Fix #68Xidorn Quan
2016-09-21Some fixes for function pointers, typedefs, and OSX's stdlib.h.Emilio Cobos Álvarez
2016-09-16Rewrite the core of the binding generator.Emilio Cobos Álvarez
TL;DR: The binding generator is a mess as of right now. At first it was funny (in a "this is challenging" sense) to improve on it, but this is not sustainable. The truth is that the current architecture of the binding generator is a huge pile of hacks, so these few days I've been working on rewriting it with a few goals. 1) Have the hacks as contained and identified as possible. They're sometimes needed because how clang exposes the AST, but ideally those hacks are well identified and don't interact randomly with each others. As an example, in the current bindgen when scanning the parameters of a function that references a struct clones all the struct information, then if the struct name changes (because we mangle it), everything breaks. 2) Support extending the bindgen output without having to deal with clang. The way I'm aiming to do this is separating completely the parsing stage from the code generation one, and providing a single id for each item the binding generator provides. 3) No more random mutation of the internal representation from anywhere. That means no more Rc<RefCell<T>>, no more random circular references, no more borrow_state... nothing. 4) No more deduplication of declarations before code generation. Current bindgen has a stage, called `tag_dup_decl`[1], that takes care of deduplicating declarations. That's completely buggy, and for C++ it's a complete mess, since we YOLO modify the world. I've managed to take rid of this using the clang canonical declaration, and the definition, to avoid scanning any type/item twice. 5) Code generation should not modify any internal data structure. It can lookup things, traverse whatever it needs, but not modifying randomly. 6) Each item should have a canonical name, and a single source of mangling logic, and that should be computed from the inmutable state, at code generation. I've put a few canonical_name stuff in the code generation phase, but it's still not complete, and should change if I implement namespaces. Improvements pending until this can land: 1) Add support for missing core stuff, mainly generating functions (note that we parse the signatures for types correctly though), bitfields, generating C++ methods. 2) Add support for the necessary features that were added to work around some C++ pitfalls, like opaque types, etc... 3) Add support for the sugar that Manish added recently. 4) Optionally (and I guess this can land without it, because basically nobody uses it since it's so buggy), bring back namespace support. These are not completely trivial, but I think I can do them quite easily with the current architecture. I'm putting the current state of affairs here as a request for comments... Any thoughts? Note that there are still a few smells I want to eventually re-redesign, like the ParseError::Recurse thing, but until that happens I'm way happier with this kind of architecture. I'm keeping the old `parser.rs` and `gen.rs` in tree just for reference while I code, but they will go away. [1]: https://github.com/Yamakaky/rust-bindgen/blob/master/src/gen.rs#L448
2016-08-13Properly detect template<typename T> union ...Emilio Cobos Álvarez
2016-07-18Add explicit option for selecting MSVC manglingVladimir Vukicevic
There's no easy way to get the current target triple from the clang-c bindings. Make this simple and require an option to be passed when generating bindings for msvc, using the x86_64-pc-win32 target (or i686)
2016-07-18Restrict the undo mangling hack to gnu targetXidorn Quan
This is not needed at least for Clang 3.9 (which is required to parse stdlib headers of MSVC 2015). This hack leads to incorrect mangling result there.
2016-07-01Add support for elaborated types.Jack Moffitt
Fixes #1.
2016-06-26Fix travis CI allowing to build on llvm stableEmilio Cobos Álvarez
2016-06-22Merge pull request #4 from nox/inlineEmilio Cobos Álvarez
Ignore inlined functions
2016-05-07Warning cleanupEmilio Cobos Álvarez
2016-05-04c++: Detect an inner class declaration with the same name in a compositeEmilio Cobos Álvarez
2016-05-04Wrap C++ `mutable` types in rust *CellsEmilio Cobos Álvarez
2016-05-04clang: Add a fallible version of sizeof, and display_name()Emilio Cobos Álvarez
2016-04-22Ignore inlined functionsAnthony Ramine
2016-04-04parser: Add in-class typedef resolving to method argumentsEmilio Cobos Álvarez
2016-03-24parser: Nits from trying to implement partial template specialisationEmilio Cobos Álvarez
2016-03-21clang: Add bindings for function template parametersEmilio Cobos Álvarez
2016-03-16SM hacks squashMichael Wu
Generate better enums Squash of... Disable prefixing Default to failing on unknown types Add support for Char16 Emit errors for unknown cursor kinds Hack in support for classes Recurse into unexposed decls This fixes functions that use extern "C". Add support for generating unmangled functions Prefix unnamed data structures with the file name Recurse into namespaced things Avoid rust reserved keywords in unmangle func args Don't create variadic unmangled funcs Don't translate typedefs to the same name Ignore operator overloads Avoid templates Handle class declarations Number duplicate demangle functions Implement copy on enums Translate stdint types into standard rust int types Switch enums to i32 for better compatibility Correctly deal with mangled functions with unnamed args Mark unmangling functions as unsafe Attempt to produce structs for C++ classes Convert references Generate better func decls for void returns Make every function callback unsafe Add support for generics in typedefs Add support for class templates Aggressively trim duplicates Don't generate default impl for templates Improve handling of templates Fix function numbering Fix deduplication Make unmangling functions extern "C" Convert all int/float typedefs to standard rust ints/floats This also gives better information to the bitfield parsing and allows uint32_t and other stdint bitfields to be processed properly Add support for wchar Add support for bitfield setter generation Fix floats Squash of... Shorten generated bitfield names Add support for generating whole bitfields Add support for enums nested inside structs/classes Rustup Fixes #184. Rustup to b301e02f3 2015-05-19 Inline demangling functions Add support for base classes/types Generate bindings for methods Make duplicate detection less aggressive Avoid converting long/unsigned longs to rust types. This fixes 64/32bit issues in structs. Generate bitfields correctly for typedefs Convert stdint types to rust types Derive Debug on BindgenOptions, Bindings, and LinkType. Remove +'static when writing bindings Generate virtual function tables Resolve some warnings Add NotConst where Constness params are required Generate real bools when applicable Squash of... Add support for comments Improve bitfield support using const fn Add limited support for references Add comments to fields Don't generate empty comments Convert char16_t to u16 rather than i16 Convert signed chars to libc::c_char Fix Cargo.toml rebasing breakage Fix compiler errors This gets bindgen to compile and run again, but all but one `cargo test` tests fail. Not sure if that’s because of mistakes on my part or if the sm-hacks branch never passed those tests. Fix build warnings Use link_name attr for mangled function names Handle mangled global vars Only generate bindings for visible symbols Don't generate arrays for blobs when the length is 1 Name enums inside classes better Handle template args inside typedefs better Filter out duplicate decls better Generate correctly sized enums Squash of... Fix bitfield accessor method generation for bools Insert phantom fields in empty structs Don't mark unmangling methods as extern "C" Add back comment support for functions Add basic annotation support Don't generate univariant enums Add support for hide annotation and adjust syntax Don't generate unsupported structs Don't parse hidden fields Don't derive Copy for structs with destructors Don't implement Clone or Default Derive Clone when deriving Copy Bypass single member unions Disable references in function args for now Remove extra underscore in mangled names on OSX Don't translate private methods Support generating consts from macros that are defined as integer literals. Handle mangling better Squash of... Update README.md for fork Generate docs for enum items Generate docs for typedefs Generate docs for enums Update syntex_syntax to 0.24.* Update clang info in README.md Spit errors and warnings to stdout. The correct thing to do here is to use env_logger, but that was causing cargo troubles for me, and this is preferable to swallowing them. Add the -ignore-functions argument. Handle 1 << 63 as enum value. Don't try to convert standard int types in rust_type_id. It looks like mwu added this, but I'm pretty sure it's a category error. This function appears to be designed to reproducibly permute C identifiers so that they don't conflict with builtin rust types. It's specifically _not_ a type translator (which would happen at the type level, rather than the string level), and using it as such with callers like ctypedef_to_rs causes us to generate things like: type u64 = u64; While processing stdint.h, which is clearly wrong. Stop patching in placeholder names for CompInfo and EnumInfo instances during code generator. As best as I can tell, it's done this way (rather than my way) because bindgen tries to recognize struct and enums typedefs of the form: /* This is a common idiom in C, not so much in C++ */ typdef struct { ... } Foo; The intention, I think, is to avoid generating rust code for a struct with a placeholder name followed by a typedef, and just give the struct the right name initially. This seems like a reasonable goal, though not a particularly important one. However, in my testing this never actually happens, because we end up calling unnamed_name anyway during the GComp(ci) case of gen_mod before we get to evaluting the typedef. So let's just remove that stuff and simplify the code. This lets us remove all the borrow_mut calls during code generation, which seems necessary for soundness. gen: Allow empty union members Use full paths in generation. Fix test compilation parser: Add support for parsing namespaces Partial C++ namespaces support We currently generate the modules as expected, but we don't resolve the names from external namespaces well. Remove unnecesary return statements Put namespaces behind a flag Overall now that they aren't complete still. Moar refactoring Finally take rid of all the warnings Even moar gen: Avoid so much cloning parser: Refactor the way submodules are stored This way we can share the global map, while having each module custom globals. gen: Checkpoint before the refactoring This actually keeps working as before. gen: Make modules (almost) work for typedef'd types We generate almost valid code, we just have to add some use statements. Or maybe is a better idea to add an unintelligible name to the root mod, and actually output a root mod plus a use root::* before. gen: Document the current submodule approach and some desirable alternative gen: Make it actually compilable \o/ gen: Make the code generation usable for every type. There's just an edge case I've detected, and it's when we remove the instantiation of C<int>, and another module uses it, because that means we only know of its existance in that other module. Probably we might want to use cursor_getSemanticParent to get the real class instead of the instantiated, but I'm not too confident about that. Fix a corner case when a template was instantiated in another module. Added an example of the namespace resolution. Don't panic when not finding the specialised template This can be annoying if filtering files out. Straight rebase completed, let's fix that build errors wip Pair up with master nits Update AST Add -no-rename-fields option This is for compatibility between C bindings and C++ bindings (in C `struct Foo` and `enum Foo`, are different, while in C++ they aren't). wip Add enum tests pass, and add C++ tests Make a few more struct-related tests pass
2016-03-12Disallow if_not_elseAnthony Ramine
2016-03-10Use std instead of libc whenever possibleWangshan Lu
2016-01-23Cleanup some warnings from Clippymcarton
2015-07-29Add support for 'packed' attribute.Ilkka Rauta
2015-07-07Add support for generating consts for integer constants. Fixes #145.Ted Mielczarek
This patch adds a few things to enable this: * Cursor::extent * struct Token * TranslationUnit::tokens - clang's C API doesn't have a straightforward way to get the integer literal from a variable declaration, so I used clang_tokenize to get the literal token and parse it. * VarInfo::val - to store the value. Non-const variable declarations and non-integer constants are handled as they were previously.
2015-03-22Clean up `allow`sTamir Duberstein
2015-03-22Purge `old_io`Tamir Duberstein
2015-03-22Silence warningsTamir Duberstein
2015-03-22RustupTamir Duberstein
Fixes #184.
2015-03-01fix: update to rust nightlyJorge Aparicio
2015-02-20update Hash impl for upstreamJason Fager
2015-01-30Update unboxed closure syntax.Nik Voss
2015-01-28Fixes for std::io -> std::old_io Rust changes.Robert Clipsham
2015-01-24Fix buildJyun-Yan You
2015-01-10Update for integer renamingDan Burkert
2015-01-10Fix build for rustc 1.0.0-nightly (44a287e6e 2015-01-08 17:03:40 -0800)Dan Burkert
2015-01-07Gets tests running, simplifies use of Cursor.visit.Christopher Chambers
clang.rs - Remove Box<_> from the signature of Cursor.visit. This makes the implementation a little noisier, but makes calling easier. tests - Updated for recent changes to rustc and std.
2015-01-08Fix unboxed closuresAidan Hobson Sayers
2015-01-05Fixes after entry api modificationsFrancois Bernier
2015-01-03Fix buildEdward Barnard
2015-01-03fix build on master rustСухарик
2015-01-01Structs containing bitfields are now the correct size and bitfield accessors ↵Edward Barnard
can be written by hand if required.
2014-12-28Switch to using canonical cursors. Closes #139.Edward Barnard
2014-12-23Fix buildEdward Barnard
2014-12-13Fix build for rustc 2014-12-13Andrew Cann
2014-11-03Generate calling-convention-aware bindingklutzy
With this patch, rust-bindgen generates extern functions with calling conventions specified in header. This patch also removes `-abi` flag.
2014-10-06Remove some warningsJyun-Yan You
2014-09-18Fix deprecated itemsEdward Barnard
2014-09-12Reduce some warningsJyun-Yan You