diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 6adbb5dae2..2cf01f85cf 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -9,87 +9,6 @@ on: - master jobs: - rustfmt: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - # TODO: Should ideally be stable, but we use some nightly-only - # features. - toolchain: nightly - override: true - components: rustfmt, clippy - - - name: Run rustfmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check - - - name: Run clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --tests - - msrv: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install msrv - uses: actions-rs/toolchain@v1 - with: - profile: minimal - # MSRV below is documented in Cargo.toml and README.md, please update those if you - # change this. - toolchain: 1.57.0 - override: true - - - name: Build with msrv - run: rm Cargo.lock && cargo +1.57.0 build --lib - - quickchecking: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - # TODO: Actually run quickchecks once `bindgen` is reliable enough. - - name: Build quickcheck tests - run: cd tests/quickchecking && cargo test - - test-expectations: - runs-on: ${{matrix.os}} - strategy: - matrix: - # TODO(#1954): These should be run on mac too, but turns out they're - # broken. - os: [ubuntu-latest, macos-latest] - steps: - - uses: actions/checkout@v3 - - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Test expectations - run: cd tests/expectations && cargo test - test: runs-on: ${{matrix.os}} strategy: @@ -99,48 +18,16 @@ jobs: - debian: null cross: null rust: null - llvm_version: ["5.0", "9.0"] + llvm_version: ["9.0"] main_tests: [1] - release_build: [0, 1] - no_default_features: [0, 1] + release_build: [0] + no_default_features: [0] # FIXME: There are no pre-built static libclang libraries, so the # `static` feature is not testable atm. - feature_runtime: [0, 1] + feature_runtime: [0] feature_extra_asserts: [0] feature_testing_only_docs: [0] - include: - # Test with extra asserts + docs just with latest llvm versions to - # prevent explosion - - os: ubuntu-latest - llvm_version: "9.0" - release_build: 0 - no_default_features: 0 - feature_extra_asserts: 1 - feature_testing_only_docs: 1 - - # FIXME: Seems installing multiarch packages fails: - # - # https://github.com/rust-lang/rust-bindgen/pull/2037/checks?check_run_id=2441799333 - # - # - os: ubuntu-latest - # target: - # debian: arm64 - # cross: aarch64-linux-gnu - # rust: aarch64-unknown-linux-gnu - # llvm_version: "9.0" - # main_tests: 0 - # release_build: 0 - # feature_extra_asserts: 0 - # feature_testing_only_docs: 0 - - # Ensure stuff works on macos too - - os: macos-latest - llvm_version: "9.0" - release_build: 0 - no_default_features: 0 - feature_extra_asserts: 0 - feature_testing_only_docs: 0 steps: - uses: actions/checkout@v3 @@ -169,6 +56,7 @@ jobs: - name: Run all the tests env: + CARGO_TERM_VERBOSE: "true" GITHUB_ACTIONS_OS: ${{matrix.os}} RUST_CROSS_COMPILER: ${{matrix.target.cross}} RUST_TARGET: ${{matrix.target.rust}} @@ -180,22 +68,3 @@ jobs: BINDGEN_FEATURE_TESTING_ONLY_DOCS: ${{matrix.feature_testing_only_docs}} BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} run: ./ci/test.sh - - test-book: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - # NOTE(emilio): Change deploy-book as well if you change this. - - name: Test book - run: | - curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.5/mdbook-v0.4.5-x86_64-unknown-linux-gnu.tar.gz | tar xz - ./mdbook build book - ./mdbook test book diff --git a/Cargo.lock b/Cargo.lock index 0c7c2f7851..bfa3c1ed42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,6 +36,7 @@ dependencies = [ "cexpr", "clang-sys", "clap", + "cmake", "diff", "env_logger", "lazy_static", @@ -57,6 +58,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + [[package]] name = "cexpr" version = "0.6.0" @@ -107,6 +114,15 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "cmake" +version = "0.1.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8ad8cef104ac57b68b89df3208164d228503abbdce70f6880ffa3d970e7443a" +dependencies = [ + "cc", +] + [[package]] name = "diff" version = "0.1.12" diff --git a/Cargo.toml b/Cargo.toml index ed7571ae99..e44a981a68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,9 @@ clap = "3" shlex = "1" tempfile = "3" +[build-dependencies] +cmake = "0.1" + [dependencies] bitflags = "1.0.3" cexpr = "0.6" diff --git a/build.rs b/build.rs index 8c05d59b4c..6f1113965d 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,5 @@ +extern crate cmake; + mod target { use std::env; use std::fs::File; @@ -68,9 +70,406 @@ mod testgen { } } +mod clang_ast { + use std::env; + use std::ffi::OsStr; + use std::fs; + use std::path::{Path, PathBuf}; + use std::process::{Command, Stdio}; + + pub fn main() { + let llvm_info = LLVMInfo::new(); + build_native(&llvm_info); + } + + fn build_var(name: &str) -> Option { + println!("cargo:rerun-if-env-changed={}", name); + env::var(name).ok() + } + + /// Strip full path from library if provided. rustc expects us to + /// pass just the library name in `-l` arguments. + fn clean_lib_path(lib: &str) -> String { + if lib.starts_with("-l") { + lib[2..].to_string() + } else { + // Sometimes llvm-config gives us an absolute path + // to the library, and I can't figure out a way to + // give an absolute path of a library to rustc. + Path::new(lib) + .file_stem() + .unwrap() + .to_str() + .unwrap() + .trim_start_matches("lib") + .into() + } + } + + /// Call out to CMake, build the clang ast library, and tell cargo where to look + /// for it. Note that `CMAKE_BUILD_TYPE` gets implicitly determined by the + /// cmake crate according to the following: + /// + /// - if `opt-level=0` then `CMAKE_BUILD_TYPE=Debug` + /// - if `opt-level={1,2,3}` and not `debug=false`, then `CMAKE_BUILD_TYPE=RelWithDebInfo` + fn build_native(llvm_info: &LLVMInfo) { + // Find where the (already built) LLVM lib dir is + let llvm_lib_dir = &llvm_info.lib_dir; + let mut llvm_cmake_dir: PathBuf = llvm_lib_dir.into(); + llvm_cmake_dir.push("cmake"); + llvm_cmake_dir.push("llvm"); + let mut clang_cmake_dir: PathBuf = llvm_lib_dir.into(); + clang_cmake_dir.push("cmake"); + clang_cmake_dir.push("clang"); + + if let Some((major_version, minor_version)) = llvm_info.version { + if (major_version == 3 && minor_version <= 8) || major_version < 3 { + llvm_cmake_dir = PathBuf::from(llvm_lib_dir); + llvm_cmake_dir.pop(); + llvm_cmake_dir.push("share"); + llvm_cmake_dir.push("llvm"); + llvm_cmake_dir.push("cmake"); + clang_cmake_dir = PathBuf::from(llvm_lib_dir); + clang_cmake_dir.pop(); + clang_cmake_dir.push("share"); + clang_cmake_dir.push("clang"); + clang_cmake_dir.push("cmake"); + } + } + + println!("cargo:rerun-if-changed=src/clang/clang_interface.hpp"); + println!("cargo:rerun-if-changed=src/clang/clang_interface_impl.hpp"); + println!("cargo:rerun-if-changed=src/clang/clang_interface.cpp"); + println!("cargo:rerun-if-changed=src/clang/libclang_compat.cpp"); + // Build libBindgenClangInterface.a with cmake + let out_dir = cmake::Config::new("src/clang") + .define("LLVM_DIR", llvm_cmake_dir.as_os_str()) + .define("Clang_DIR", clang_cmake_dir.as_os_str()) + .build(); + + // Set up search path for newly built libBindgenClangInterface.a + let lib_dir = out_dir.join("lib"); + println!("cargo:rustc-link-search=native={}", lib_dir.display()); + + // Statically link against our library, 'BindgenClangInterface' + println!("cargo:rustc-link-lib=static=BindgenClangInterface"); + + let deps_filepath = out_dir.join("BindgenClangInterface.deps"); + println!("cargo:rustc-link-search=native={}", llvm_lib_dir); + if false && deps_filepath.is_file() { + // Our CMake script was able to generate a list of dependencies for + // us. This should be more accurate than what we build here. + let deps_file = fs::read_to_string(deps_filepath) + .expect("Could not read deps file"); + let deps = deps_file + .split(";") + .filter(|dep| { + // We're skipping any dependencies with delayLoad, because + // rustc doesn't know how to handle these. We don't seem to + // need them anyway. + !dep.starts_with("-delayload") + }) + .map(clean_lib_path); + for lib in deps { + println!("cargo:rustc-link-lib={}", lib); + } + // XXX KULP + println!("cargo:rustc-link-lib={}", "ncurses"); + } else { + // Link against these Clang libs. The ordering here is important! Libraries + // must be listed before their dependencies when statically linking. + for lib in &[ + "clangIndex", + "clangFrontend", + "clangParse", + "clangSerialization", + "clangSema", + "clangEdit", + "clangAnalysis", + "clangDriver", + "clangFormat", + "clangToolingCore", + "clangAST", + "clangLex", + "clangBasic", + ] { + println!("cargo:rustc-link-lib={}", lib); + } + + for lib in &llvm_info.libs { + // IMPORTANT: We cannot specify static= or dylib= here because rustc + // will reorder those libs before the clang libs above which don't have + // static or dylib. + println!("cargo:rustc-link-lib={}", lib); + } + + // Link against the C++ std library. + if cfg!(target_os = "macos") { + println!("cargo:rustc-link-lib=c++"); + } else if cfg!(not(target_os = "windows")) { + println!("cargo:rustc-link-lib=stdc++"); + } + + // clangDriver links against system version.lib on windows + if cfg!(target_os = "windows") { + println!("cargo:rustc-link-lib=version") + } + } + } + + /// Holds information about LLVM paths we have found + struct LLVMInfo { + /// LLVM lib dir containing libclang* and libLLVM* libraries + pub lib_dir: String, + + /// List of libs we need to link against + pub libs: Vec, + + /// LLVM version in (major, minor) form, if available + pub version: Option<(i32, i32)>, + } + + impl LLVMInfo { + fn new() -> Self { + fn find_llvm_config() -> Option { + // Explicitly provided path in LLVM_CONFIG_PATH + build_var("LLVM_CONFIG_PATH") + // Relative to LLVM_LIB_DIR + .or_else(|| { + build_var("LLVM_LIB_DIR").map(|d| { + String::from( + Path::new(&d) + .join("../bin/llvm-config") + .canonicalize() + .unwrap() + .to_string_lossy(), + ) + }) + }) + // In PATH + .or_else(|| { + [ + "llvm-config-7.0", + "llvm-config-6.1", + "llvm-config-6.0", + "llvm-config", + // Homebrew install location on MacOS + "/usr/local/opt/llvm/bin/llvm-config", + ] + .iter() + .find_map(|c| { + if Command::new(c) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn() + .is_ok() + { + Some(String::from(*c)) + } else { + None + } + }) + }) + } + + /// Invoke given `command`, if any, with the specified arguments. + fn invoke_command( + command: Option, + args: I, + ) -> Option + where + I: IntoIterator, + S: AsRef, + C: AsRef, + { + command.and_then(|c| { + Command::new(c).args(args).output().ok().and_then( + |output| { + if output.status.success() { + Some( + String::from_utf8_lossy(&output.stdout) + .trim() + .to_string(), + ) + } else { + None + } + }, + ) + }) + } + + let llvm_config = find_llvm_config(); + let lib_dir = { + let path_str = build_var("LLVM_LIB_DIR") + .or(invoke_command(llvm_config.as_ref(), &["--libdir"])) + .expect( + " +Couldn't find LLVM lib dir. Try setting the `LLVM_LIB_DIR` environment +variable or make sure `llvm-config` is on $PATH then re-build. For example: + + $ export LLVM_LIB_DIR=/usr/local/opt/llvm/lib +", + ); + String::from( + Path::new(&path_str) + .canonicalize() + .unwrap() + .to_string_lossy(), + ) + }; + + let llvm_shared_libs = invoke_command( + llvm_config.as_ref(), + &["--libs", "--link-shared"], + ); + + // /lib/rustlib//lib/ contains a libLLVM DSO for the + // rust compiler. On MacOS, this lib is named libLLVM.dylib, which will + // always conflict with the dylib we are trying to link against. On + // Linux we generally will not hit this issue because the prebuilt lib + // includes the `svn` suffix. This would conflict with a source build + // from master, however. + // + // We check here if the lib we want to link against will conflict with + // the rustlib version. If so we can't dynamically link against libLLVM. + let conflicts_with_rustlib_llvm = { + if let Some(llvm_shared_libs) = llvm_shared_libs.as_ref() { + let dylib_suffix = { + if cfg!(target_os = "macos") { + ".dylib" + } else { + ".so" + } // Windows is not supported + }; + let mut dylib_file = String::from("lib"); + dylib_file + .push_str(llvm_shared_libs.trim_start_matches("-l")); + dylib_file.push_str(dylib_suffix); + let sysroot = invoke_command( + env::var("RUSTC").ok().as_ref(), + &["--print=sysroot"], + ) + .unwrap(); + + // Does /lib/rustlib//lib/ exist? + let mut libllvm_path = PathBuf::new(); + libllvm_path.push(sysroot); + libllvm_path.push("lib/rustlib"); + libllvm_path.push(env::var("TARGET").unwrap()); + libllvm_path.push("lib"); + libllvm_path.push(dylib_file); + + libllvm_path.as_path().exists() + } else { + false + } + }; + + let link_statically = cfg!(feature = "llvm-static") || { + let args = if conflicts_with_rustlib_llvm { + vec!["--shared-mode", "--ignore-libllvm"] + } else { + vec!["--shared-mode"] + }; + invoke_command(llvm_config.as_ref(), &args) + .map_or(false, |c| c == "static") + }; + + let link_mode = if link_statically { + "--link-static" + } else { + "--link-shared" + }; + + let version_string = invoke_command( + llvm_config.as_ref(), + &["--version"], + ) + .or_else(|| { + invoke_command( + Some(&format!("{}/../bin/clang", lib_dir)), + &["--version"], + ) + .and_then(|output| Some(output.split(" ").nth(2)?.to_string())) + }); + let version = version_string.and_then(|version| { + let mut split = version.split("."); + let major: i32 = split.next()?.parse().ok()?; + let minor: i32 = split.next()?.parse().ok()?; + Some((major, minor)) + }); + + let mut supports_link_mode = true; + if let Some((major_version, minor_version)) = version { + if major_version < 3 || + (major_version == 3 && minor_version <= 8) + { + supports_link_mode = false; + } + } + + // LLVM components that we need to link against for the clang libs + let mut llvm_components = vec![ + "MC", + "MCParser", + "Support", + "Option", + "BitReader", + "ProfileData", + "Core", + ]; + + // llvmAST requires FrontendOpenMP from version 10 and newer + if let Some((version, _minor_version)) = version { + if version > 4 { + llvm_components.push("BinaryFormat"); + } + if version > 9 { + llvm_components.push("FrontendOpenMP"); + } + } + + // Construct the list of libs we need to link against + let mut args = llvm_components; + args.insert(0, "--libs"); + if supports_link_mode { + args.insert(1, link_mode); + } + let mut libs: Vec = + invoke_command(llvm_config.as_ref(), &args) + .unwrap_or("-lLLVM".to_string()) + .split_whitespace() + .map(clean_lib_path) + .collect(); + + libs.extend( + build_var("LLVM_SYSTEM_LIBS") + .or_else(|| { + let mut args = vec!["--system-libs"]; + if supports_link_mode { + args.push(link_mode); + } + invoke_command(llvm_config.as_ref(), args) + }) + .unwrap_or(String::new()) + .split_whitespace() + .map(clean_lib_path), + ); + + Self { + lib_dir, + libs, + version, + } + } + } +} + fn main() { target::main(); testgen::main(); + clang_ast::main(); // On behalf of clang_sys, rebuild ourselves if important configuration // variables change, to ensure that bindings get rebuilt if the diff --git a/src/clang.rs b/src/clang.rs index 587cc0ba7d..be3c0d2f34 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -4,20 +4,156 @@ #![allow(non_upper_case_globals, dead_code)] use crate::ir::context::BindgenContext; -use clang_sys::*; +use cexpr; +use regex; use std::ffi::{CStr, CString}; use std::fmt; use std::hash::Hash; -use std::hash::Hasher; use std::os::raw::{c_char, c_int, c_longlong, c_uint, c_ulong, c_ulonglong}; use std::{mem, ptr, slice}; +#[allow(non_camel_case_types, non_snake_case, missing_docs)] +mod clang_interface; +pub use self::clang_interface::CXCallingConv::Type as CXCallingConv; +pub use self::clang_interface::CXCallingConv::*; +pub use self::clang_interface::CXChildVisitResult::Type as CXChildVisitResult; +pub use self::clang_interface::CXChildVisitResult::*; +pub use self::clang_interface::CXCommentKind::*; +pub use self::clang_interface::CXCursorKind::Type as CXCursorKind; +pub use self::clang_interface::CXCursorKind::*; +pub use self::clang_interface::CXDiagnosticSeverity::Type as CXDiagnosticSeverity; +pub use self::clang_interface::CXDiagnosticSeverity::*; +pub use self::clang_interface::CXEvalResultKind::Type as CXEvalResultKind; +pub use self::clang_interface::CXEvalResultKind::*; +pub use self::clang_interface::CXLinkageKind::Type as CXLinkageKind; +pub use self::clang_interface::CXLinkageKind::*; +pub use self::clang_interface::CXTokenKind::Type as CXTokenKind; +pub use self::clang_interface::CXTokenKind::*; +pub use self::clang_interface::CXTranslationUnit_Flags::Type as CXTranslationUnit_Flags; +pub use self::clang_interface::CXTranslationUnit_Flags::*; +pub use self::clang_interface::CXTypeKind::Type as CXTypeKind; +pub use self::clang_interface::CXTypeKind::*; +pub use self::clang_interface::CXVisibilityKind::Type as CXVisibilityKind; +pub use self::clang_interface::CXVisibilityKind::*; +pub use self::clang_interface::CXVisitorResult::*; +pub use self::clang_interface::CX_CXXAccessSpecifier::Type as CX_CXXAccessSpecifier; +pub use self::clang_interface::CX_CXXAccessSpecifier::*; + +impl clang_interface::BindgenSourceRange { + fn null() -> Self { + Self { + B: ptr::null_mut(), + E: ptr::null_mut(), + } + } +} + +impl Drop for clang_interface::BindgenSourceRange { + fn drop(&mut self) { + unsafe { + clang_interface::deleteSourceRange(self); + } + } +} + +trait ToCString { + fn to_cstring(&self) -> CString; +} + +impl ToCString for clang_interface::BindgenStringRef { + fn to_cstring(&self) -> CString { + if !self.s.is_null() { + unsafe { CStr::from_ptr(self.s).into() } + } else { + return CString::new("").unwrap(); + } + } +} + +impl fmt::Display for clang_interface::BindgenStringRef { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let str = self.to_cstring(); + write!(f, "{}", str.to_str().unwrap()) + } +} + +impl Drop for clang_interface::BindgenStringRef { + fn drop(&mut self) { + unsafe { + clang_interface::deleteString(self); + } + } +} + +impl Drop for clang_interface::BindgenStringRefSet { + fn drop(&mut self) { + unsafe { + clang_interface::deleteStringSet(self); + } + } +} + /// A cursor into the Clang AST, pointing to an AST node. /// /// We call the AST node pointed to by the cursor the cursor's "referent". -#[derive(Copy, Clone)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] pub struct Cursor { - x: CXCursor, + node: ASTNode, + + /// Kind of this cursor, may differ from the kind of the node, e.g. TypeRef + /// kind referring to a ClassDecl. + kind: CXCursorKind, + + /// AST unit that this cursor is part of. + /// + /// Some clang interfaces require access to an ASTUnit, so we keep this + /// available. + unit: *mut clang_interface::clang_ASTUnit, +} + +/// Clang AST nodes. +/// +/// Each variant wraps a raw pointer to a type of Clang AST node that we handle. +#[derive(Copy, Clone, PartialEq, Eq, Hash)] +pub enum ASTNode { + /// Placeholder for an invalid AST node + Invalid, + + /// Declaration AST node (const Decl*) + Decl(*const clang_interface::clang_Decl), + + /// Expression AST node (const Expr*) + Expr(*const clang_interface::clang_Expr), + + /// C++ base specifier AST node (const CXXBaseSpecifier*) + CXXBaseSpecifier(*const clang_interface::clang_CXXBaseSpecifier), + + /// Attribute AST node (const Attr*) + Attr(*const clang_interface::clang_Attr), + + /// Preprocessor entity node (const PreprocessedEntity*) + PreprocessedEntity(*const clang_interface::clang_PreprocessedEntity), +} + +impl ASTNode { + /// Is this node valid? + fn is_valid(&self) -> bool { + unsafe { !clang_interface::CursorKind_isInvalid(self.kind()) } + } + + /// Kind of the AST node. This is NOT the kind of the cursor itself, and may + /// differ from a cursor holding the node. + fn kind(&self) -> CXCursorKind { + unsafe { + match *self { + ASTNode::Decl(d) => clang_interface::Decl_getCXCursorKind(d), + ASTNode::Expr(e) => clang_interface::Expr_getCXCursorKind(e), + ASTNode::CXXBaseSpecifier(_) => CXCursor_CXXBaseSpecifier, + ASTNode::Attr(a) => clang_interface::Attr_getCXCursorKind(a), + _ => CXCursor_InvalidFile, + } + } + } } impl fmt::Debug for Cursor { @@ -34,13 +170,39 @@ impl fmt::Debug for Cursor { } impl Cursor { + /// Create a new Cursor from an ASTNode and a clang ASTUnit + fn new(node: ASTNode, unit: *mut clang_interface::clang_ASTUnit) -> Self { + Self { + node, + kind: node.kind(), + unit, + } + } + + /// Create a new Cursor with the given ASTNode in the same clang ASTUnit as + /// self. + fn with_node(&self, node: ASTNode) -> Self { + Self::new(node, self.unit) + } + + /// Get the clang ASTContext for this cursor + fn context(&self) -> *mut clang_interface::clang_ASTContext { + unsafe { clang_interface::ASTUnit_getContext(self.unit) } + } + /// Get the Unified Symbol Resolution for this cursor's referent, if /// available. /// /// The USR can be used to compare entities across translation units. pub fn usr(&self) -> Option { - let s = unsafe { cxstring_into_string(clang_getCursorUSR(self.x)) }; - if s.is_empty() { + let s = unsafe { + match self.node { + ASTNode::Decl(d) => clang_interface::Decl_getUSR(d), + _ => return None, + } + }; + let s = s.to_string(); + if s.len() == 0 { None } else { Some(s) @@ -49,44 +211,64 @@ impl Cursor { /// Is this cursor's referent a declaration? pub fn is_declaration(&self) -> bool { - unsafe { clang_isDeclaration(self.kind()) != 0 } + match self.node { + ASTNode::Decl(_) => true, + _ => false, + } } /// Get this cursor's referent's spelling. pub fn spelling(&self) -> String { - unsafe { cxstring_into_string(clang_getCursorSpelling(self.x)) } - } - - /// Get this cursor's referent's display name. - /// - /// This is not necessarily a valid identifier. It includes extra - /// information, such as parameters for a function, etc. - pub fn display_name(&self) -> String { - unsafe { cxstring_into_string(clang_getCursorDisplayName(self.x)) } + unsafe { + match self.node { + ASTNode::Decl(d) => { + clang_interface::Decl_getSpelling(d).to_string() + } + ASTNode::Expr(e) => { + clang_interface::Expr_getSpelling(e).to_string() + } + ASTNode::CXXBaseSpecifier(b) => { + clang_interface::CXXBaseSpecifier_getSpelling(b).to_string() + } + ASTNode::PreprocessedEntity(e) => { + clang_interface::PreprocessedEntity_getSpelling(e) + .to_string() + } + _ => String::new(), + } + } } /// Get the mangled name of this cursor's referent. pub fn mangling(&self) -> String { - unsafe { cxstring_into_string(clang_Cursor_getMangling(self.x)) } + unsafe { + match self.node { + ASTNode::Decl(d) => { + clang_interface::Decl_getMangling(d, self.context()) + .to_string() + } + _ => String::new(), + } + } } /// Gets the C++ manglings for this cursor, or an error if the manglings /// are not available. pub fn cxx_manglings(&self) -> Result, ()> { - use clang_sys::*; unsafe { - let manglings = clang_Cursor_getCXXManglings(self.x); - if manglings.is_null() { - return Err(()); - } - let count = (*manglings).Count as usize; + let manglings = match self.node { + ASTNode::Decl(d) => { + clang_interface::Decl_getCXXManglings(d, self.context()) + } + _ => return Err(()), + }; + let count = manglings.len as usize; let mut result = Vec::with_capacity(count); for i in 0..count { - let string_ptr = (*manglings).Strings.add(i); - result.push(cxstring_to_string_leaky(*string_ptr)); + let string_ptr = manglings.strings.offset(i as isize); + result.push((*string_ptr).to_string()); } - clang_disposeStringSet(manglings); Ok(result) } } @@ -115,11 +297,13 @@ impl Cursor { /// void Foo::method() { /* ... */ } /// ``` pub fn lexical_parent(&self) -> Cursor { - unsafe { - Cursor { - x: clang_getCursorLexicalParent(self.x), - } - } + let node = match self.node { + ASTNode::Decl(d) => unsafe { + ASTNode::Decl(clang_interface::Decl_getLexicalParent(d)) + }, + _ => ASTNode::Invalid, + }; + self.with_node(node) } /// Get the referent's semantic parent, if one is available. @@ -127,15 +311,17 @@ impl Cursor { /// See documentation for `lexical_parent` for details on semantic vs /// lexical parents. pub fn fallible_semantic_parent(&self) -> Option { - let sp = unsafe { - Cursor { - x: clang_getCursorSemanticParent(self.x), - } + let node = match self.node { + ASTNode::Decl(d) => unsafe { + ASTNode::Decl(clang_interface::Decl_getSemanticParent(d)) + }, + ASTNode::Expr(_) => panic!("Unimplemented for Expr"), + _ => return None, }; - if sp == *self || !sp.is_valid() { + if node == self.node || !node.is_valid() { return None; } - Some(sp) + Some(self.with_node(node)) } /// Get the referent's semantic parent. @@ -157,11 +343,17 @@ impl Cursor { // `clang_Cursor_getNumTemplateArguments` is totally unreliable. // Therefore, try former first, and only fallback to the latter if we // have to. + let decl = if let ASTNode::Decl(decl) = self.node { + decl + } else { + return None; + }; self.cur_type() .num_template_args() .or_else(|| { - let n: c_int = - unsafe { clang_Cursor_getNumTemplateArguments(self.x) }; + let n: c_int = unsafe { + clang_interface::Decl_getNumTemplateArguments(decl) + }; if n >= 0 { Some(n as u32) @@ -186,16 +378,8 @@ impl Cursor { /// bindgen assumes there will only be one of them alive at a time, and /// disposes it on drop. That can change if this would be required, but I /// think we can survive fine without it. - pub fn translation_unit(&self) -> Cursor { - assert!(self.is_valid()); - unsafe { - let tu = clang_Cursor_getTranslationUnit(self.x); - let cursor = Cursor { - x: clang_getTranslationUnitCursor(tu), - }; - assert!(cursor.is_valid()); - cursor - } + pub fn translation_unit(&self) -> *mut clang_interface::clang_ASTUnit { + self.unit } /// Is the referent a top level construct? @@ -212,7 +396,9 @@ impl Cursor { semantic_parent.unwrap().fallible_semantic_parent(); } - let tu = self.translation_unit(); + let tu = self.with_node(ASTNode::Decl(unsafe { + clang_interface::getTranslationUnitDecl(self.unit) + })); // Yes, this can happen with, e.g., macro definitions. semantic_parent == tu.fallible_semantic_parent() } @@ -231,17 +417,29 @@ impl Cursor { /// Is this Cursor pointing to a function-like macro definition? pub fn is_macro_function_like(&self) -> bool { - unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 } + match self.node { + ASTNode::PreprocessedEntity(p) => unsafe { + clang_interface::PreprocessedEntity_isFunctionMacroLike( + self.unit, p, + ) + }, + _ => false, + } } /// Get the kind of referent this cursor is pointing to. pub fn kind(&self) -> CXCursorKind { - self.x.kind + self.kind } /// Returns true if the cursor is a definition pub fn is_definition(&self) -> bool { - unsafe { clang_isCursorDefinition(self.x) != 0 } + match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::Decl_isDefinition(d) + }, + _ => false, + } } /// Is the referent a template specialization? @@ -278,27 +476,59 @@ impl Cursor { /// Is this cursor pointing a valid referent? pub fn is_valid(&self) -> bool { - unsafe { clang_isInvalid(self.kind()) == 0 } + unsafe { !clang_interface::CursorKind_isInvalid(self.kind) } } /// Get the source location for the referent. pub fn location(&self) -> SourceLocation { unsafe { - SourceLocation { - x: clang_getCursorLocation(self.x), - } + let x = match self.node { + ASTNode::Decl(d) => clang_interface::Decl_getLocation(d), + ASTNode::Expr(e) => clang_interface::Expr_getLocation(e), + ASTNode::CXXBaseSpecifier(b) => { + clang_interface::CXXBaseSpecifier_getLocation(b) + } + ASTNode::Attr(b) => clang_interface::Attr_getLocation(b), + ASTNode::PreprocessedEntity(p) => { + clang_interface::PreprocessedEntity_getLocation(p) + } + ASTNode::Invalid => ptr::null_mut(), + }; + SourceLocation { x, unit: self.unit } } } /// Get the source location range for the referent. - pub fn extent(&self) -> CXSourceRange { - unsafe { clang_getCursorExtent(self.x) } + /// + /// Warning: This range goes from the start of the first token to the start + /// of the last token, unlike the ranges provided by libclang, which are + /// half-open ranges of characters (end is past the last character in the + /// last token). + pub fn extent(&self) -> clang_interface::BindgenSourceRange { + unsafe { + match self.node { + ASTNode::Decl(d) => clang_interface::Decl_getSourceRange(d), + ASTNode::Expr(e) => clang_interface::Expr_getSourceRange(e), + ASTNode::CXXBaseSpecifier(b) => { + clang_interface::CXXBaseSpecifier_getSourceRange(b) + } + ASTNode::Attr(b) => clang_interface::Attr_getSourceRange(b), + ASTNode::PreprocessedEntity(b) => { + clang_interface::PreprocessedEntity_getSourceRange(b) + } + _ => clang_interface::BindgenSourceRange::null(), + } + } } /// Get the raw declaration comment for this referent, if one exists. pub fn raw_comment(&self) -> Option { - let s = unsafe { - cxstring_into_string(clang_Cursor_getRawCommentText(self.x)) + let s = match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::Decl_getRawCommentText(d, self.context()) + .to_string() + }, + _ => return None, }; if s.is_empty() { None @@ -309,19 +539,29 @@ impl Cursor { /// Get the referent's parsed comment. pub fn comment(&self) -> Comment { - unsafe { - Comment { - x: clang_Cursor_getParsedComment(self.x), - } - } + let x = match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::Decl_getParsedComment(d, self.context()) + }, + _ => ptr::null(), + }; + Comment { x } } /// Get the referent's type. pub fn cur_type(&self) -> Type { unsafe { - Type { - x: clang_getCursorType(self.x), - } + let x = match self.node { + ASTNode::Decl(d) => { + clang_interface::Decl_getType(d, self.context()) + } + ASTNode::Expr(e) => clang_interface::Expr_getType(e), + ASTNode::CXXBaseSpecifier(base) => { + clang_interface::CXXBaseSpecifier_getType(base) + } + _ => mem::zeroed(), + }; + Type { x, unit: self.unit } } } @@ -329,32 +569,34 @@ impl Cursor { /// a declaration, get the cursor pointing to the referenced type or type of /// the declared thing. pub fn definition(&self) -> Option { - unsafe { - let ret = Cursor { - x: clang_getCursorDefinition(self.x), - }; - - if ret.is_valid() && ret.kind() != CXCursor_NoDeclFound { - Some(ret) - } else { - None - } + let is_reference = + self.kind >= CXCursor_FirstRef && self.kind <= CXCursor_LastRef; + let def = match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::Decl_getDefinition(d, is_reference) + }, + _ => return None, + }; + if def.is_null() { + None + } else { + Some(self.with_node(ASTNode::Decl(def))) } } /// Given that this cursor's referent is reference type, get the cursor /// pointing to the referenced type. pub fn referenced(&self) -> Option { - unsafe { - let ret = Cursor { - x: clang_getCursorReferenced(self.x), - }; - - if ret.is_valid() { - Some(ret) - } else { - None - } + match self.node { + ASTNode::Decl(d) => unsafe { + let ptr = clang_interface::Decl_getReferenced(d); + if ptr.is_null() { + None + } else { + Some(self.with_node(ASTNode::Decl(ptr))) + } + }, + _ => return None, } } @@ -364,33 +606,41 @@ impl Cursor { /// defined. This method allows us to get the canonical cursor for the /// referent type. pub fn canonical(&self) -> Cursor { - unsafe { - Cursor { - x: clang_getCanonicalCursor(self.x), - } - } + let node = match self.node { + ASTNode::Decl(d) => unsafe { + ASTNode::Decl(clang_interface::Decl_getCanonical(d)) + }, + _ => ASTNode::Invalid, + }; + self.with_node(node) } /// Given that this cursor points to either a template specialization or a /// template instantiation, get a cursor pointing to the template definition /// that is being specialized. pub fn specialized(&self) -> Option { - unsafe { - let ret = Cursor { - x: clang_getSpecializedCursorTemplate(self.x), - }; - if ret.is_valid() { - Some(ret) - } else { - None - } + match self.node { + ASTNode::Decl(d) => unsafe { + let ptr = clang_interface::Decl_getSpecializedTemplate(d); + if ptr.is_null() { + None + } else { + Some(self.with_node(ASTNode::Decl(ptr))) + } + }, + _ => None, } } /// Assuming that this cursor's referent is a template declaration, get the /// kind of cursor that would be generated for its specializations. pub fn template_kind(&self) -> CXCursorKind { - unsafe { clang_getTemplateCursorKind(self.x) } + match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::Decl_getTemplateCursorKind(d) + }, + _ => CXCursor_NoDeclFound, + } } /// Traverse this cursor's referent and its children. @@ -400,9 +650,35 @@ impl Cursor { where Visitor: FnMut(Cursor) -> CXChildVisitResult, { - let data = &mut visitor as *mut Visitor; - unsafe { - clang_visitChildren(self.x, visit_children::, data.cast()); + match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::Decl_visitChildren( + d, + self.kind, + Some(visit_children::), + self.unit, + mem::transmute(&mut visitor), + ); + }, + ASTNode::Expr(e) => unsafe { + clang_interface::Expr_visitChildren( + e, + self.kind, + Some(visit_children::), + self.unit, + mem::transmute(&mut visitor), + ); + }, + ASTNode::CXXBaseSpecifier(b) => unsafe { + clang_interface::CXXBaseSpecifier_visitChildren( + b, + self.kind, + Some(visit_children::), + self.unit, + mem::transmute(&mut visitor), + ); + }, + _ => panic!("Tried to visit: {:?}", self), } } @@ -461,55 +737,53 @@ impl Cursor { /// Is the referent an inlined function? pub fn is_inlined_function(&self) -> bool { - unsafe { clang_Cursor_isFunctionInlined(self.x) != 0 } - } - - /// Is the referent a defaulted function? - pub fn is_defaulted_function(&self) -> bool { - unsafe { clang_CXXMethod_isDefaulted(self.x) != 0 } + match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::Decl_isFunctionInlined(d) + }, + _ => false, + } } /// Is the referent a deleted function? pub fn is_deleted_function(&self) -> bool { - // Unfortunately, libclang doesn't yet have an API for checking if a - // member function is deleted, but the following should be a good - // enough approximation. - // Deleted functions are implicitly inline according to paragraph 4 of - // [dcl.fct.def.delete] in the C++ standard. Normal inline functions - // have a definition in the same translation unit, so if this is an - // inline function without a definition, and it's not a defaulted - // function, we can reasonably safely conclude that it's a deleted - // function. - self.is_inlined_function() && - self.definition().is_none() && - !self.is_defaulted_function() + match self.node { + ASTNode::Decl(d) => unsafe { clang_interface::Decl_isDeleted(d) }, + _ => false, + } } /// Get the width of this cursor's referent bit field, or `None` if the /// referent is not a bit field. pub fn bit_width(&self) -> Option { - unsafe { - let w = clang_getFieldDeclBitWidth(self.x); - if w == -1 { - None - } else { - Some(w as u32) - } + let w = match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::Decl_getFieldDeclBitWidth(d, self.context()) + }, + _ => -1, + }; + if w == -1 { + None + } else { + Some(w as u32) } } /// Get the integer representation type used to hold this cursor's referent /// enum type. pub fn enum_type(&self) -> Option { - unsafe { - let t = Type { - x: clang_getEnumDeclIntegerType(self.x), - }; - if t.is_valid() { - Some(t) - } else { - None + let x = unsafe { + match self.node { + ASTNode::Decl(d) => { + clang_interface::Decl_getEnumDeclIntegerType(d) + } + _ => mem::zeroed(), } + }; + if x.is_null() { + None + } else { + Some(Type { x, unit: self.unit }) } } @@ -517,25 +791,18 @@ impl Cursor { /// /// Returns None if the cursor's referent is not an enum variant. pub fn enum_val_boolean(&self) -> Option { - unsafe { - if self.kind() == CXCursor_EnumConstantDecl { - Some(clang_getEnumConstantDeclValue(self.x) != 0) - } else { - None - } - } + self.enum_val_unsigned().map(|x| x != 0) } /// Get the signed constant value for this cursor's enum variant referent. /// /// Returns None if the cursor's referent is not an enum variant. pub fn enum_val_signed(&self) -> Option { - unsafe { - if self.kind() == CXCursor_EnumConstantDecl { - Some(clang_getEnumConstantDeclValue(self.x) as i64) - } else { - None - } + match self.node { + ASTNode::Decl(d) => unsafe { + Some(clang_interface::Decl_getEnumConstantValue(d)) + }, + _ => None, } } @@ -543,12 +810,11 @@ impl Cursor { /// /// Returns None if the cursor's referent is not an enum variant. pub fn enum_val_unsigned(&self) -> Option { - unsafe { - if self.kind() == CXCursor_EnumConstantDecl { - Some(clang_getEnumConstantDeclUnsignedValue(self.x) as u64) - } else { - None - } + match self.node { + ASTNode::Decl(d) => unsafe { + Some(clang_interface::Decl_getEnumConstantUnsignedValue(d)) + }, + _ => None, } } @@ -586,14 +852,14 @@ impl Cursor { /// Given that this cursor's referent is a `typedef`, get the `Type` that is /// being aliased. pub fn typedef_type(&self) -> Option { - let inner = Type { - x: unsafe { clang_getTypedefDeclUnderlyingType(self.x) }, - }; - - if inner.is_valid() { - Some(inner) - } else { - None + match self.node { + ASTNode::Decl(d) => Some(Type { + x: unsafe { + clang_interface::Decl_getTypedefDeclUnderlyingType(d) + }, + unit: self.unit, + }), + _ => None, } } @@ -601,12 +867,20 @@ impl Cursor { /// /// This only applies to functions and variables. pub fn linkage(&self) -> CXLinkageKind { - unsafe { clang_getCursorLinkage(self.x) } + match self.node { + ASTNode::Decl(d) => unsafe { clang_interface::Decl_getLinkage(d) }, + _ => CXLinkage_Invalid, + } } /// Get the visibility of this cursor's referent. pub fn visibility(&self) -> CXVisibilityKind { - unsafe { clang_getCursorVisibility(self.x) } + match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::Decl_getVisibility(d) + }, + _ => CXVisibility_Invalid, + } } /// Given that this cursor's referent is a function, return cursors to its @@ -620,8 +894,23 @@ impl Cursor { // CXCursor_CXXMethod => { self.num_args().ok().map(|num| { (0..num) - .map(|i| Cursor { - x: unsafe { clang_Cursor_getArgument(self.x, i as c_uint) }, + .map(|i| { + let node = match self.node { + ASTNode::Decl(d) => unsafe { + ASTNode::Decl(clang_interface::Decl_getArgument( + d, + i as c_uint, + )) + }, + ASTNode::Expr(e) => unsafe { + ASTNode::Expr(clang_interface::Expr_getArgument( + e, + i as c_uint, + )) + }, + _ => ASTNode::Invalid, + }; + self.with_node(node) }) .collect() }) @@ -633,19 +922,31 @@ impl Cursor { /// Returns Err if the cursor's referent is not a function/method call or /// declaration. pub fn num_args(&self) -> Result { - unsafe { - let w = clang_Cursor_getNumArguments(self.x); - if w == -1 { - Err(()) - } else { - Ok(w as u32) - } + let w = match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::Decl_getNumArguments(d) + }, + ASTNode::Expr(e) => unsafe { + clang_interface::Expr_getNumArguments(e) + }, + _ => -1, + }; + if w == -1 { + Err(()) + } else { + Ok(w as u32) } } /// Get the access specifier for this cursor's referent. pub fn access_specifier(&self) -> CX_CXXAccessSpecifier { - unsafe { clang_getCXXAccessSpecifier(self.x) } + match self.node { + ASTNode::Decl(d) => unsafe { clang_interface::Decl_getAccess(d) }, + ASTNode::CXXBaseSpecifier(b) => unsafe { + clang_interface::CXXBaseSpecifier_getAccess(b) + }, + _ => CX_CXXInvalidAccessSpecifier, + } } /// Is the cursor's referrent publically accessible in C++? @@ -660,13 +961,22 @@ impl Cursor { /// Is this cursor's referent a field declaration that is marked as /// `mutable`? pub fn is_mutable_field(&self) -> bool { - unsafe { clang_CXXField_isMutable(self.x) != 0 } + match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::CXXField_isMutable(d) + }, + _ => false, + } } /// Get the offset of the field represented by the Cursor. pub fn offset_of_field(&self) -> Result { - let offset = unsafe { clang_Cursor_getOffsetOfField(self.x) }; - + let offset = match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::Decl_getOffsetOfField(d, self.context()) + }, + _ => -1, + }; if offset < 0 { Err(LayoutError::from(offset as i32)) } else { @@ -676,43 +986,100 @@ impl Cursor { /// Is this cursor's referent a member function that is declared `static`? pub fn method_is_static(&self) -> bool { - unsafe { clang_CXXMethod_isStatic(self.x) != 0 } + match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::CXXMethod_isStatic(d) + }, + _ => false, + } } /// Is this cursor's referent a member function that is declared `const`? pub fn method_is_const(&self) -> bool { - unsafe { clang_CXXMethod_isConst(self.x) != 0 } + match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::CXXMethod_isConst(d) + }, + _ => false, + } } /// Is this cursor's referent a member function that is virtual? pub fn method_is_virtual(&self) -> bool { - unsafe { clang_CXXMethod_isVirtual(self.x) != 0 } + match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::CXXMethod_isVirtual(d) + }, + _ => false, + } } /// Is this cursor's referent a member function that is pure virtual? pub fn method_is_pure_virtual(&self) -> bool { - unsafe { clang_CXXMethod_isPureVirtual(self.x) != 0 } + match self.node { + ASTNode::Decl(d) => unsafe { + clang_interface::CXXMethod_isPureVirtual(d) + }, + _ => false, + } } /// Is this cursor's referent a struct or class with virtual members? pub fn is_virtual_base(&self) -> bool { - unsafe { clang_isVirtualBase(self.x) != 0 } + match self.node { + ASTNode::CXXBaseSpecifier(b) => unsafe { + clang_interface::CXXBaseSpecifier_isVirtualBase(b) + }, + _ => false, + } } /// Try to evaluate this cursor. pub fn evaluate(&self) -> Option { - EvalResult::new(*self) + // Work around https://bugs.llvm.org/show_bug.cgi?id=42532, see: + // * https://github.com/rust-lang/rust-bindgen/issues/283 + // * https://github.com/rust-lang/rust-bindgen/issues/1590 + { + let mut found_cant_eval = false; + self.visit(|c| { + if c.kind() == CXCursor_TypeRef && + c.cur_type().canonical_type().kind() == CXType_Unexposed + { + found_cant_eval = true; + return CXChildVisit_Break; + } + + CXChildVisit_Recurse + }); + + if found_cant_eval { + return None; + } + } + unsafe { + let x = match self.node { + ASTNode::Decl(d) => { + clang_interface::Decl_Evaluate(d, self.context()) + } + ASTNode::Expr(e) => { + clang_interface::Expr_Evaluate(e, self.context()) + } + _ => return None, + }; + Some(EvalResult { x }) + } } /// Return the result type for this cursor pub fn ret_type(&self) -> Option { - let rt = Type { - x: unsafe { clang_getCursorResultType(self.x) }, - }; - if rt.is_valid() { - Some(rt) - } else { - None + match self.node { + ASTNode::Decl(d) => Some(Type { + x: unsafe { + clang_interface::Decl_getResultType(d, self.context()) + }, + unit: self.unit, + }), + _ => None, } } @@ -733,12 +1100,17 @@ impl Cursor { /// /// Returns None if the cursor does not include a file, otherwise the file's full name pub fn get_included_file_name(&self) -> Option { - let file = unsafe { clang_sys::clang_getIncludedFile(self.x) }; + let file = match self.node { + ASTNode::PreprocessedEntity(e) => unsafe { + clang_interface::PreprocessedEntity_getIncludedFile(e) + }, + _ => ptr::null(), + }; if file.is_null() { None } else { Some(unsafe { - cxstring_into_string(clang_sys::clang_getFileName(file)) + clang_interface::FileEntry_getName(file).to_string() }) } } @@ -747,8 +1119,8 @@ impl Cursor { /// A struct that owns the tokenizer result from a given cursor. pub struct RawTokens<'a> { cursor: &'a Cursor, - tu: CXTranslationUnit, - tokens: *mut CXToken, + tu: *mut clang_interface::clang_ASTUnit, + tokens: *mut clang_interface::CXToken, token_count: c_uint, } @@ -756,9 +1128,11 @@ impl<'a> RawTokens<'a> { fn new(cursor: &'a Cursor) -> Self { let mut tokens = ptr::null_mut(); let mut token_count = 0; + let tu = cursor.translation_unit(); let range = cursor.extent(); - let tu = unsafe { clang_Cursor_getTranslationUnit(cursor.x) }; - unsafe { clang_tokenize(tu, range, &mut tokens, &mut token_count) }; + unsafe { + clang_interface::tokenize(tu, range, &mut tokens, &mut token_count); + } Self { cursor, tu, @@ -767,7 +1141,7 @@ impl<'a> RawTokens<'a> { } } - fn as_slice(&self) -> &[CXToken] { + fn as_slice(&self) -> &[clang_interface::CXToken] { if self.tokens.is_null() { return &[]; } @@ -787,7 +1161,7 @@ impl<'a> Drop for RawTokens<'a> { fn drop(&mut self) { if !self.tokens.is_null() { unsafe { - clang_disposeTokens( + clang_interface::disposeTokens( self.tu, self.tokens, self.token_count as c_uint, @@ -797,16 +1171,13 @@ impl<'a> Drop for RawTokens<'a> { } } -/// A raw clang token, that exposes only kind, spelling, and extent. This is a +/// A raw clang token, that exposes only the kind and spelling. This is a /// slightly more convenient version of `CXToken` which owns the spelling -/// string and extent. +/// string. #[derive(Debug)] pub struct ClangToken { - spelling: CXString, - /// The extent of the token. This is the same as the relevant member from - /// `CXToken`. - pub extent: CXSourceRange, - /// The kind of the token. This is the same as the relevant member from + spelling: CString, + /// The kind of token, this is the same as the relevant member from /// `CXToken`. pub kind: CXTokenKind, } @@ -814,10 +1185,7 @@ pub struct ClangToken { impl ClangToken { /// Get the token spelling, without being converted to utf-8. pub fn spelling(&self) -> &[u8] { - let c_str = unsafe { - CStr::from_ptr(clang_getCString(self.spelling) as *const _) - }; - c_str.to_bytes() + self.spelling.to_bytes() } /// Converts a ClangToken to a `cexpr` token if possible. @@ -845,16 +1213,10 @@ impl ClangToken { } } -impl Drop for ClangToken { - fn drop(&mut self) { - unsafe { clang_disposeString(self.spelling) } - } -} - /// An iterator over a set of Tokens. pub struct ClangTokenIterator<'a> { - tu: CXTranslationUnit, - raw: slice::Iter<'a, CXToken>, + tu: *mut clang_interface::clang_ASTUnit, + raw: slice::Iter<'a, clang_interface::CXToken>, } impl<'a> Iterator for ClangTokenIterator<'a> { @@ -863,14 +1225,10 @@ impl<'a> Iterator for ClangTokenIterator<'a> { fn next(&mut self) -> Option { let raw = self.raw.next()?; unsafe { - let kind = clang_getTokenKind(*raw); - let spelling = clang_getTokenSpelling(self.tu, *raw); - let extent = clang_getTokenExtent(self.tu, *raw); - Some(ClangToken { - kind, - extent, - spelling, - }) + let kind = clang_interface::getTokenKind(*raw); + let spelling = + clang_interface::getTokenSpelling(self.tu, *raw).to_cstring(); + Some(ClangToken { kind, spelling }) } } } @@ -887,48 +1245,61 @@ pub fn is_valid_identifier(name: &str) -> bool { first_valid && chars.all(|c| c.is_alphanumeric() || c == '_') } -extern "C" fn visit_children( - cur: CXCursor, - _parent: CXCursor, - data: CXClientData, +unsafe extern "C" fn visit_children( + raw_node: clang_interface::Node, + _parent: clang_interface::Node, + unit: *mut clang_interface::clang_ASTUnit, + data: clang_interface::CXClientData, ) -> CXChildVisitResult where Visitor: FnMut(Cursor) -> CXChildVisitResult, { - let func: &mut Visitor = unsafe { &mut *(data as *mut Visitor) }; - let child = Cursor { x: cur }; + let func: &mut Visitor = mem::transmute(data); + let node = { + // CXCursor_CXXBaseSpecifier must come before decls, because it is in + // the range [FirstRef, LastRef] + if raw_node.kind == CXCursor_CXXBaseSpecifier { + ASTNode::CXXBaseSpecifier(raw_node.ptr.base) + } else if (raw_node.kind >= CXCursor_FirstDecl && + raw_node.kind <= CXCursor_LastDecl) || + (raw_node.kind >= CXCursor_FirstExtraDecl && + raw_node.kind <= CXCursor_LastExtraDecl) || + (raw_node.kind >= CXCursor_FirstRef && + raw_node.kind <= CXCursor_LastRef) + { + ASTNode::Decl(raw_node.ptr.decl) + } else if raw_node.kind >= CXCursor_FirstExpr && + raw_node.kind <= CXCursor_LastExpr + { + ASTNode::Expr(raw_node.ptr.expr) + } else if raw_node.kind >= CXCursor_FirstAttr && + raw_node.kind <= CXCursor_LastAttr + { + ASTNode::Attr(raw_node.ptr.attr) + } else if raw_node.kind >= CXCursor_FirstPreprocessing && + raw_node.kind <= CXCursor_LastPreprocessing + { + ASTNode::PreprocessedEntity(raw_node.ptr.ppe) + } else { + return CXChildVisit_Recurse; + } + }; + let child = Cursor { + node, + kind: raw_node.kind, + unit, + }; (*func)(child) } -impl PartialEq for Cursor { - fn eq(&self, other: &Cursor) -> bool { - unsafe { clang_equalCursors(self.x, other.x) == 1 } - } -} - -impl Eq for Cursor {} - -impl Hash for Cursor { - fn hash(&self, state: &mut H) { - unsafe { clang_hashCursor(self.x) }.hash(state) - } -} - /// The type of a node in clang's AST. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Type { - x: CXType, -} - -impl PartialEq for Type { - fn eq(&self, other: &Self) -> bool { - unsafe { clang_equalTypes(self.x, other.x) != 0 } - } + x: clang_interface::BindgenQualType, + unit: *mut clang_interface::clang_ASTUnit, } -impl Eq for Type {} - impl fmt::Debug for Type { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { write!( @@ -963,6 +1334,7 @@ pub enum LayoutError { impl ::std::convert::From for LayoutError { fn from(val: i32) -> Self { + use self::clang_interface::CXTypeLayoutError::*; use self::LayoutError::*; match val { @@ -977,17 +1349,22 @@ impl ::std::convert::From for LayoutError { } impl Type { + fn context(&self) -> *mut clang_interface::clang_ASTContext { + unsafe { clang_interface::ASTUnit_getContext(self.unit) } + } + /// Get this type's kind. pub fn kind(&self) -> CXTypeKind { - self.x.kind + unsafe { clang_interface::Type_kind(self.x, self.context()) } } /// Get a cursor pointing to this type's declaration. pub fn declaration(&self) -> Cursor { unsafe { - Cursor { - x: clang_getTypeDeclaration(self.x), - } + Cursor::new( + ASTNode::Decl(clang_interface::Type_getDeclaration(self.x)), + self.unit, + ) } } @@ -1019,7 +1396,10 @@ impl Type { /// Get a raw display name for this type. pub fn spelling(&self) -> String { - let s = unsafe { cxstring_into_string(clang_getTypeSpelling(self.x)) }; + let s = unsafe { + clang_interface::Type_getTypeSpelling(self.x, self.context()) + .to_string() + }; // Clang 5.0 introduced changes in the spelling API so it returned the // full qualified name. Let's undo that here. if s.split("::").all(is_valid_identifier) { @@ -1033,7 +1413,7 @@ impl Type { /// Is this type const qualified? pub fn is_const(&self) -> bool { - unsafe { clang_isConstQualifiedType(self.x) != 0 } + unsafe { clang_interface::Type_isConstQualifiedType(self.x) } } #[inline] @@ -1050,8 +1430,10 @@ impl Type { ctx.target_pointer_size() as c_longlong } // Work-around https://bugs.llvm.org/show_bug.cgi?id=40813 - CXType_Auto if self.is_non_deductible_auto_type() => -6, - _ => unsafe { clang_Type_getSizeOf(self.x) }, + CXType_Auto if self.is_non_deductible_auto_type() => return -6, + _ => unsafe { + clang_interface::Type_getSizeOf(self.x, self.context()) + }, } } @@ -1063,8 +1445,10 @@ impl Type { ctx.target_pointer_size() as c_longlong } // Work-around https://bugs.llvm.org/show_bug.cgi?id=40813 - CXType_Auto if self.is_non_deductible_auto_type() => -6, - _ => unsafe { clang_Type_getAlignOf(self.x) }, + CXType_Auto if self.is_non_deductible_auto_type() => return -6, + _ => unsafe { + clang_interface::Type_getAlignOf(self.x, self.context()) + }, } } @@ -1131,7 +1515,8 @@ impl Type { /// Get the number of template arguments this type has, or `None` if it is /// not some kind of template. pub fn num_template_args(&self) -> Option { - let n = unsafe { clang_Type_getNumTemplateArguments(self.x) }; + let n = + unsafe { clang_interface::Type_getNumTemplateArguments(self.x) }; if n >= 0 { Some(n as u32) } else { @@ -1145,6 +1530,7 @@ impl Type { pub fn template_args(&self) -> Option { self.num_template_args().map(|n| TypeTemplateArgIterator { x: self.x, + unit: self.unit, length: n, index: 0, }) @@ -1157,7 +1543,10 @@ impl Type { self.num_args().ok().map(|num| { (0..num) .map(|i| Type { - x: unsafe { clang_getArgType(self.x, i as c_uint) }, + x: unsafe { + clang_interface::Type_getArgType(self.x, i as c_uint) + }, + unit: self.unit, }) .collect() }) @@ -1168,7 +1557,7 @@ impl Type { /// Returns Err if the type is not a function prototype. pub fn num_args(&self) -> Result { unsafe { - let w = clang_getNumArgTypes(self.x); + let w = clang_interface::Type_getNumArgTypes(self.x); if w == -1 { Err(()) } else { @@ -1188,7 +1577,8 @@ impl Type { CXType_BlockPointer | CXType_ObjCObjectPointer => { let ret = Type { - x: unsafe { clang_getPointeeType(self.x) }, + x: unsafe { clang_interface::Type_getPointeeType(self.x) }, + unit: self.unit, }; debug_assert!(ret.is_valid()); Some(ret) @@ -1201,7 +1591,8 @@ impl Type { /// type of its elements. pub fn elem_type(&self) -> Option { let current_type = Type { - x: unsafe { clang_getElementType(self.x) }, + x: unsafe { clang_interface::Type_getElementType(self.x) }, + unit: self.unit, }; if current_type.is_valid() { Some(current_type) @@ -1213,7 +1604,8 @@ impl Type { /// Given that this type is an array or vector type, return its number of /// elements. pub fn num_elements(&self) -> Option { - let num_elements_returned = unsafe { clang_getNumElements(self.x) }; + let num_elements_returned = + unsafe { clang_interface::Type_getNumElements(self.x) }; if num_elements_returned != -1 { Some(num_elements_returned as usize) } else { @@ -1226,21 +1618,26 @@ impl Type { pub fn canonical_type(&self) -> Type { unsafe { Type { - x: clang_getCanonicalType(self.x), + x: clang_interface::Type_getCanonicalType( + self.x, + self.context(), + ), + unit: self.unit, } } } /// Is this type a variadic function type? pub fn is_variadic(&self) -> bool { - unsafe { clang_isFunctionTypeVariadic(self.x) != 0 } + unsafe { clang_interface::Type_isFunctionTypeVariadic(self.x) } } /// Given that this type is a function type, get the type of its return /// value. pub fn ret_type(&self) -> Option { let rt = Type { - x: unsafe { clang_getResultType(self.x) }, + x: unsafe { clang_interface::Type_getResultType(self.x) }, + unit: self.unit, }; if rt.is_valid() { Some(rt) @@ -1251,8 +1648,8 @@ impl Type { /// Given that this type is a function type, get its calling convention. If /// this is not a function type, `CXCallingConv_Invalid` is returned. - pub fn call_conv(&self) -> CXCallingConv { - unsafe { clang_getFunctionTypeCallingConv(self.x) } + pub fn call_conv(&self) -> clang_interface::CXCallingConv::Type { + unsafe { clang_interface::Type_getFunctionTypeCallingConv(self.x) } } /// For elaborated types (types which use `class`, `struct`, or `union` to @@ -1260,7 +1657,8 @@ impl Type { pub fn named(&self) -> Type { unsafe { Type { - x: clang_Type_getNamedType(self.x), + x: clang_interface::Type_getNamedType(self.x), + unit: self.unit, } } } @@ -1340,7 +1738,8 @@ impl CanonicalTypeDeclaration { /// An iterator for a type's template arguments. pub struct TypeTemplateArgIterator { - x: CXType, + x: clang_interface::BindgenQualType, + unit: *mut clang_interface::clang_ASTUnit, length: u32, index: u32, } @@ -1352,7 +1751,10 @@ impl Iterator for TypeTemplateArgIterator { let idx = self.index as c_uint; self.index += 1; Some(Type { - x: unsafe { clang_Type_getTemplateArgumentAsType(self.x, idx) }, + x: unsafe { + clang_interface::Type_getTemplateArgumentAsType(self.x, idx) + }, + unit: self.unit, }) } else { None @@ -1370,7 +1772,8 @@ impl ExactSizeIterator for TypeTemplateArgIterator { /// A `SourceLocation` is a file, line, column, and byte offset location for /// some source text. pub struct SourceLocation { - x: CXSourceLocation, + x: *mut clang_interface::clang_SourceLocation, + unit: *mut clang_interface::clang_ASTUnit, } impl SourceLocation { @@ -1382,8 +1785,8 @@ impl SourceLocation { let mut line = 0; let mut col = 0; let mut off = 0; - clang_getSpellingLocation( - self.x, &mut file, &mut line, &mut col, &mut off, + clang_interface::getSpellingLocation( + self.unit, self.x, &mut file, &mut line, &mut col, &mut off, ); (File { x: file }, line as usize, col as usize, off as usize) } @@ -1407,24 +1810,32 @@ impl fmt::Debug for SourceLocation { } } +impl Drop for SourceLocation { + fn drop(&mut self) { + unsafe { + clang_interface::deleteSourceLocation(self.x); + } + } +} + /// A comment in the source text. /// /// Comments are sort of parsed by Clang, and have a tree structure. pub struct Comment { - x: CXComment, + x: *const clang_interface::clang_comments_Comment, } impl Comment { /// What kind of comment is this? - pub fn kind(&self) -> CXCommentKind { - unsafe { clang_Comment_getKind(self.x) } + pub fn kind(&self) -> clang_interface::CXCommentKind::Type { + unsafe { clang_interface::Comment_getKind(self.x) } } /// Get this comment's children comment pub fn get_children(&self) -> CommentChildrenIterator { CommentChildrenIterator { parent: self.x, - length: unsafe { clang_Comment_getNumChildren(self.x) }, + length: unsafe { clang_interface::Comment_getNumChildren(self.x) }, index: 0, } } @@ -1432,14 +1843,18 @@ impl Comment { /// Given that this comment is the start or end of an HTML tag, get its tag /// name. pub fn get_tag_name(&self) -> String { - unsafe { cxstring_into_string(clang_HTMLTagComment_getTagName(self.x)) } + unsafe { + clang_interface::HTMLTagComment_getTagName(self.x).to_string() + } } /// Given that this comment is an HTML start tag, get its attributes. pub fn get_tag_attrs(&self) -> CommentAttributesIterator { CommentAttributesIterator { x: self.x, - length: unsafe { clang_HTMLStartTag_getNumAttrs(self.x) }, + length: unsafe { + clang_interface::HTMLStartTag_getNumAttrs(self.x) + }, index: 0, } } @@ -1447,7 +1862,7 @@ impl Comment { /// An iterator for a comment's children pub struct CommentChildrenIterator { - parent: CXComment, + parent: *const clang_interface::clang_comments_Comment, length: c_uint, index: c_uint, } @@ -1459,7 +1874,9 @@ impl Iterator for CommentChildrenIterator { let idx = self.index; self.index += 1; Some(Comment { - x: unsafe { clang_Comment_getChild(self.parent, idx) }, + x: unsafe { + clang_interface::Comment_getChild(self.parent, idx) + }, }) } else { None @@ -1477,7 +1894,7 @@ pub struct CommentAttribute { /// An iterator for a comment's attributes pub struct CommentAttributesIterator { - x: CXComment, + x: *const clang_interface::clang_comments_Comment, length: c_uint, index: c_uint, } @@ -1490,14 +1907,12 @@ impl Iterator for CommentAttributesIterator { self.index += 1; Some(CommentAttribute { name: unsafe { - cxstring_into_string(clang_HTMLStartTag_getAttrName( - self.x, idx, - )) + clang_interface::HTMLStartTag_getAttrName(self.x, idx) + .to_string() }, value: unsafe { - cxstring_into_string(clang_HTMLStartTag_getAttrValue( - self.x, idx, - )) + clang_interface::HTMLStartTag_getAttrValue(self.x, idx) + .to_string() }, }) } else { @@ -1508,7 +1923,7 @@ impl Iterator for CommentAttributesIterator { /// A source file. pub struct File { - x: CXFile, + x: *mut clang_interface::clang_FileEntry, } impl File { @@ -1517,63 +1932,63 @@ impl File { if self.x.is_null() { return None; } - Some(unsafe { cxstring_into_string(clang_getFileName(self.x)) }) - } -} - -fn cxstring_to_string_leaky(s: CXString) -> String { - if s.data.is_null() { - return "".to_owned(); - } - let c_str = unsafe { CStr::from_ptr(clang_getCString(s) as *const _) }; - c_str.to_string_lossy().into_owned() -} - -fn cxstring_into_string(s: CXString) -> String { - let ret = cxstring_to_string_leaky(s); - unsafe { clang_disposeString(s) }; - ret -} - -/// An `Index` is an environment for a set of translation units that will -/// typically end up linked together in one final binary. -pub struct Index { - x: CXIndex, -} - -impl Index { - /// Construct a new `Index`. - /// - /// The `pch` parameter controls whether declarations in pre-compiled - /// headers are included when enumerating a translation unit's "locals". - /// - /// The `diag` parameter controls whether debugging diagnostics are enabled. - pub fn new(pch: bool, diag: bool) -> Index { - unsafe { - Index { - x: clang_createIndex(pch as c_int, diag as c_int), - } - } + Some(unsafe { clang_interface::FileEntry_getName(self.x).to_string() }) } } -impl fmt::Debug for Index { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - write!(fmt, "Index {{ }}") - } -} - -impl Drop for Index { - fn drop(&mut self) { - unsafe { - clang_disposeIndex(self.x); - } - } -} +// fn cxstring_to_string_leaky(s: CXString) -> String { +// if s.data.is_null() { +// return "".to_owned(); +// } +// let c_str = unsafe { CStr::from_ptr(clang_getCString(s) as *const _) }; +// c_str.to_string_lossy().into_owned() +// } + +// fn cxstring_into_string(s: CXString) -> String { +// let ret = cxstring_to_string_leaky(s); +// unsafe { clang_disposeString(s) }; +// ret +// } + +// /// An `Index` is an environment for a set of translation units that will +// /// typically end up linked together in one final binary. +// pub struct Index { +// x: CXIndex, +// } + +// impl Index { +// /// Construct a new `Index`. +// /// +// /// The `pch` parameter controls whether declarations in pre-compiled +// /// headers are included when enumerating a translation unit's "locals". +// /// +// /// The `diag` parameter controls whether debugging diagnostics are enabled. +// pub fn new(pch: bool, diag: bool) -> Index { +// unsafe { +// Index { +// x: clang_createIndex(pch as c_int, diag as c_int), +// } +// } +// } +// } + +// impl fmt::Debug for Index { +// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { +// write!(fmt, "Index {{ }}") +// } +// } + +// impl Drop for Index { +// fn drop(&mut self) { +// unsafe { +// clang_disposeIndex(self.x); +// } +// } +// } /// A translation unit (or "compilation unit"). pub struct TranslationUnit { - x: CXTranslationUnit, + x: *mut clang_interface::clang_ASTUnit, } impl fmt::Debug for TranslationUnit { @@ -1585,7 +2000,6 @@ impl fmt::Debug for TranslationUnit { impl TranslationUnit { /// Parse a source file into a translation unit. pub fn parse( - ix: &Index, file: &str, cmd_args: &[String], unsaved: &[UnsavedFile], @@ -1598,17 +2012,16 @@ impl TranslationUnit { .collect(); let c_args: Vec<*const c_char> = _c_args.iter().map(|s| s.as_ptr()).collect(); - let mut c_unsaved: Vec = + let mut c_unsaved: Vec = unsaved.iter().map(|f| f.x).collect(); let tu = unsafe { - clang_parseTranslationUnit( - ix.x, + clang_interface::parseTranslationUnit( fname.as_ptr(), c_args.as_ptr(), c_args.len() as c_int, + opts, c_unsaved.as_mut_ptr(), c_unsaved.len() as c_uint, - opts, ) }; if tu.is_null() { @@ -1622,11 +2035,15 @@ impl TranslationUnit { /// unit. pub fn diags(&self) -> Vec { unsafe { - let num = clang_getNumDiagnostics(self.x) as usize; + let num = + clang_interface::ASTUnit_getNumDiagnostics(self.x) as usize; let mut diags = vec![]; for i in 0..num { diags.push(Diagnostic { - x: clang_getDiagnostic(self.x, i as c_uint), + x: clang_interface::ASTUnit_getDiagnostic( + self.x, + i as c_uint, + ), }); } diags @@ -1636,9 +2053,10 @@ impl TranslationUnit { /// Get a cursor pointing to the root of this translation unit's AST. pub fn cursor(&self) -> Cursor { unsafe { - Cursor { - x: clang_getTranslationUnitCursor(self.x), - } + Cursor::new( + ASTNode::Decl(clang_interface::getTranslationUnitDecl(self.x)), + self.x, + ) } } @@ -1651,44 +2069,41 @@ impl TranslationUnit { impl Drop for TranslationUnit { fn drop(&mut self) { unsafe { - clang_disposeTranslationUnit(self.x); + clang_interface::disposeASTUnit(self.x); } } } /// A diagnostic message generated while parsing a translation unit. pub struct Diagnostic { - x: CXDiagnostic, + x: *const clang_interface::clang_StoredDiagnostic, } impl Diagnostic { /// Format this diagnostic message as a string, using the given option bit /// flags. pub fn format(&self) -> String { - unsafe { - let opts = clang_defaultDiagnosticDisplayOptions(); - cxstring_into_string(clang_formatDiagnostic(self.x, opts)) - } + unsafe { clang_interface::Diagnostic_format(self.x).to_string() } } /// What is the severity of this diagnostic message? - pub fn severity(&self) -> CXDiagnosticSeverity { - unsafe { clang_getDiagnosticSeverity(self.x) } + pub fn severity(&self) -> clang_interface::CXDiagnosticSeverity::Type { + unsafe { clang_interface::Diagnostic_getSeverity(self.x) } } } -impl Drop for Diagnostic { - /// Destroy this diagnostic message. - fn drop(&mut self) { - unsafe { - clang_disposeDiagnostic(self.x); - } - } -} +// impl Drop for Diagnostic { +// /// Destroy this diagnostic message. +// fn drop(&mut self) { +// unsafe { +// clang_interface::Diagnostic_dispose(self.x); +// } +// } +// } /// A file which has not been saved to disk. pub struct UnsavedFile { - x: CXUnsavedFile, + x: clang_interface::CXUnsavedFile, /// The name of the unsaved file. Kept here to avoid leaving dangling pointers in /// `CXUnsavedFile`. pub name: CString, @@ -1700,7 +2115,7 @@ impl UnsavedFile { pub fn new(name: &str, contents: &str) -> UnsavedFile { let name = CString::new(name).unwrap(); let contents = CString::new(contents).unwrap(); - let x = CXUnsavedFile { + let x = clang_interface::CXUnsavedFile { Filename: name.as_ptr(), Contents: contents.as_ptr(), Length: contents.as_bytes().len() as c_ulong, @@ -1721,12 +2136,12 @@ impl fmt::Debug for UnsavedFile { /// Convert a cursor kind into a static string. pub fn kind_to_str(x: CXCursorKind) -> String { - unsafe { cxstring_into_string(clang_getCursorKindSpelling(x)) } + unsafe { clang_interface::CursorKind_getSpelling(x).to_string() } } /// Convert a type kind to a static string. pub fn type_to_str(x: CXTypeKind) -> String { - unsafe { cxstring_into_string(clang_getTypeKindSpelling(x)) } + unsafe { clang_interface::TypeKind_getSpelling(x).to_string() } } /// Dump the Clang AST to stdout for debugging purposes. @@ -1872,7 +2287,7 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { format!(" {}spelling = \"{}\"", prefix, ty.spelling()), ); let num_template_args = - unsafe { clang_Type_getNumTemplateArguments(ty.x) }; + unsafe { clang_interface::Type_getNumTemplateArguments(ty.x) }; if num_template_args >= 0 { print_indent( depth, @@ -1957,52 +2372,35 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { /// Try to extract the clang version to a string pub fn extract_clang_version() -> String { - unsafe { cxstring_into_string(clang_getClangVersion()) } + let version = unsafe { clang_interface::getClangVersion() }; + version.to_string() } /// A wrapper for the result of evaluating an expression. #[derive(Debug)] pub struct EvalResult { - x: CXEvalResult, + x: *mut clang_interface::EvalResult, } -impl EvalResult { - /// Evaluate `cursor` and return the result. - pub fn new(cursor: Cursor) -> Option { - // Work around https://bugs.llvm.org/show_bug.cgi?id=42532, see: - // * https://github.com/rust-lang/rust-bindgen/issues/283 - // * https://github.com/rust-lang/rust-bindgen/issues/1590 - { - let mut found_cant_eval = false; - cursor.visit(|c| { - if c.kind() == CXCursor_TypeRef && - c.cur_type().canonical_type().kind() == CXType_Unexposed - { - found_cant_eval = true; - return CXChildVisit_Break; - } - - CXChildVisit_Recurse - }); - - if found_cant_eval { - return None; - } +impl Drop for EvalResult { + fn drop(&mut self) { + unsafe { + clang_interface::deleteEvalResult(self.x); } - Some(EvalResult { - x: unsafe { clang_Cursor_Evaluate(cursor.x) }, - }) } +} +impl EvalResult { fn kind(&self) -> CXEvalResultKind { - unsafe { clang_EvalResult_getKind(self.x) } + unsafe { clang_interface::EvalResult_getKind(self.x) } } /// Try to get back the result as a double. pub fn as_double(&self) -> Option { match self.kind() { CXEval_Float => { - Some(unsafe { clang_EvalResult_getAsDouble(self.x) } as f64) + Some(unsafe { clang_interface::EvalResult_getAsDouble(self.x) } + as f64) } _ => None, } @@ -2014,8 +2412,9 @@ impl EvalResult { return None; } - if unsafe { clang_EvalResult_isUnsignedInt(self.x) } != 0 { - let value = unsafe { clang_EvalResult_getAsUnsigned(self.x) }; + if unsafe { clang_interface::EvalResult_isUnsignedInt(self.x) } { + let value = + unsafe { clang_interface::EvalResult_getAsUnsigned(self.x) }; if value > i64::max_value() as c_ulonglong { return None; } @@ -2023,7 +2422,8 @@ impl EvalResult { return Some(value as i64); } - let value = unsafe { clang_EvalResult_getAsLongLong(self.x) }; + let value = + unsafe { clang_interface::EvalResult_getAsLongLong(self.x) }; if value > i64::max_value() as c_longlong { return None; } @@ -2038,8 +2438,10 @@ impl EvalResult { pub fn as_literal_string(&self) -> Option> { match self.kind() { CXEval_StrLiteral => { + let mut stringref = + unsafe { clang_interface::EvalResult_getAsStr(self.x) }; let ret = unsafe { - CStr::from_ptr(clang_EvalResult_getAsStr(self.x)) + CStr::from_ptr(clang_interface::cString(&mut stringref)) }; Some(ret.to_bytes().to_vec()) } @@ -2048,11 +2450,11 @@ impl EvalResult { } } -impl Drop for EvalResult { - fn drop(&mut self) { - unsafe { clang_EvalResult_dispose(self.x) }; - } -} +// impl Drop for EvalResult { +// fn drop(&mut self) { +// unsafe { clang_interface::EvalResult_dispose(self.x) }; +// } +// } /// Target information obtained from libclang. #[derive(Debug)] @@ -2069,10 +2471,9 @@ impl TargetInfo { let triple; let pointer_width; unsafe { - let ti = clang_getTranslationUnitTargetInfo(tu.x); - triple = cxstring_into_string(clang_TargetInfo_getTriple(ti)); - pointer_width = clang_TargetInfo_getPointerWidth(ti); - clang_TargetInfo_dispose(ti); + let ti = clang_interface::ASTUnit_getTargetInfo(tu.x); + triple = clang_interface::TargetInfo_getTriple(ti).to_string(); + pointer_width = clang_interface::TargetInfo_getPointerWidth(ti); } assert!(pointer_width > 0); assert_eq!(pointer_width % 8, 0); diff --git a/src/clang/CMakeLists.txt b/src/clang/CMakeLists.txt new file mode 100644 index 0000000000..da4adc3a03 --- /dev/null +++ b/src/clang/CMakeLists.txt @@ -0,0 +1,121 @@ +cmake_minimum_required(VERSION 3.4.3) +project(BindgenClangInterface) + +set(SRCS + clang_interface.cpp + libclang_compat.cpp + ) + +if( PROJECT_NAME STREQUAL "LLVM" ) + # We are building in-tree, we can use LLVM cmake functions + + add_definitions(-DCLANG_BIN_PATH="${CMAKE_INSTALL_PREFIX}/bin") + + add_clang_library(BindgenClangInterface ${SRCS} DEPENDS clang-headers) + + set(LLVM_LINK_COMPONENTS support) +else() + find_package(LLVM REQUIRED CONFIG) + + # Debian and Ubuntu's clang cmake files are broken, so we can't require the + # package here. We already have to manually order the link against the clang + # libs in build.rs, so that's not so bad. + find_package(Clang CONFIG) + + include_directories(${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS}) + add_definitions(${LLVM_DEFINITIONS} ${CLANG_DEFINITIONS}) + + if (DEFINED CLANG_INSTALL_PREFIX) + add_definitions(-DCLANG_BIN_PATH="${CLANG_INSTALL_PREFIX}/bin") + elseif(DEFINED LLVM_INSTALL_PREFIX) + add_definitions(-DCLANG_BIN_PATH="${LLVM_INSTALL_PREFIX}/bin") + elseif(DEFINED LLVM_TOOLS_BINARY_DIR) + add_definitions(-DCLANG_BIN_PATH="${LLVM_TOOLS_BINARY_DIR}") + else() + message(FATAL_ERROR "Cannot find path to clang binary") + endif() + + set(LLVM_LINK_COMPONENTS support) + + # LLVM is not always built with RTTI, we don't need it either. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") + + # The library + add_library(BindgenClangInterface STATIC ${SRCS}) +endif() + +add_definitions(-DCLANG_LIBDIR_SUFFIX="${LLVM_LIBDIR_SUFFIX}") + +set_target_properties(BindgenClangInterface PROPERTIES + CXX_STANDARD 14 + CXX_EXTENSIONS OFF + ) + + +# Any changes to this list must be kept in sync with ../../build.rs in case +# cmake cannot find the clang cmake config files to generate a useful +# dependency list. +set(clang_libs + clangAST + clangFrontend + clangIndex + clangSema + clangTooling + clangBasic + clangLex + ) + +if (TARGET clang-cpp AND TARGET LLVM) + target_link_libraries(BindgenClangInterface PRIVATE LLVM clang-cpp) +else() + target_link_libraries(BindgenClangInterface PRIVATE ${clang_libs}) +endif() + +# rustc links with CC, so we need to explicitly include the C++ standard library +if (APPLE) + target_link_libraries(BindgenClangInterface PRIVATE c++) +elseif(UNIX) + target_link_libraries(BindgenClangInterface PRIVATE stdc++) +endif() + + +install(TARGETS BindgenClangInterface DESTINATION lib) + +# Gather dependencies for all libraries required by our target, recursively +function(target_link_libs_recursive out_libs target) + get_target_property(imported ${target} IMPORTED) + if (imported) + get_target_property(target_link_libs ${target} INTERFACE_LINK_LIBRARIES) + if (NOT target_link_libs) + get_target_property(target_config ${target} IMPORTED_CONFIGURATIONS) + get_target_property(target_link_libs ${target} IMPORTED_LINK_DEPENDENT_LIBRARIES_${target_config}) + endif() + else() + get_target_property(target_link_libs ${target} LINK_LIBRARIES) + endif() + if (target_link_libs) + set(libs "") + foreach(dep IN LISTS target_link_libs) + list(FIND visited_targets ${dep} visited) + if (${visited} EQUAL -1) + list(APPEND visited_targets ${dep}) + if (TARGET ${dep}) + set(dependencies "") + target_link_libs_recursive(dependencies ${dep}) + list(APPEND libs ${dependencies}) + endif() + list(APPEND libs ${dep}) + endif() + endforeach(dep) + set(visited_targets ${visited_targets} PARENT_SCOPE) + set(${out_libs} ${libs} PARENT_SCOPE) + endif() +endfunction() + +if (Clang_FOUND) + target_link_libs_recursive(link_libs BindgenClangInterface) + + file(WRITE "${CMAKE_INSTALL_PREFIX}/BindgenClangInterface.deps" "${link_libs}") +else() # we didn't find clang cmake files + file(REMOVE "${CMAKE_INSTALL_PREFIX}/BindgenClangInterface.deps") +endif() diff --git a/src/clang/clang_interface.cpp b/src/clang/clang_interface.cpp new file mode 100644 index 0000000000..baebf15a83 --- /dev/null +++ b/src/clang/clang_interface.cpp @@ -0,0 +1,1730 @@ +#include + +#include "clang/AST/Comment.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclFriend.h" +#include "clang/AST/DeclTemplate.h" +#include "clang/AST/DeclObjC.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" +#include "clang/AST/ExprObjC.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/TargetInfo.h" +#include "clang/Basic/Version.h" +#include "clang/Frontend/ASTUnit.h" +#include "clang/Index/USRGeneration.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Lex/PreprocessorOptions.h" +#include "clang-c/Documentation.h" +#include "clang-c/Index.h" + +#include "clang_interface_impl.hpp" + +using namespace clang; + +BindgenStringRef stringref() { + BindgenStringRef ref; + ref.s = nullptr; + ref.len = 0; + return ref; +} + +BindgenStringRef stringref(const char *newStr) { + BindgenStringRef ref; + ref.len = strlen(newStr); + ref.s = new char[ref.len + 1]; + strncpy(ref.s, newStr, ref.len); + ref.s[ref.len] = '\0'; + return ref; +} + +BindgenStringRef stringref(const std::string &s) { + return stringref(s.c_str()); +} + +BindgenStringRef stringref(llvm::StringRef S) { + BindgenStringRef ref; + ref.len = S.size(); + ref.s = new char[ref.len + 1]; + strncpy(ref.s, S.data(), ref.len); + ref.s[ref.len] = '\0'; + return ref; +} + +BindgenSourceRange make_sourcerange(const SourceRange &range) { + BindgenSourceRange out; + out.B = new SourceLocation(range.getBegin()); + out.E = new SourceLocation(range.getEnd()); + return out; +} + +BindgenStringRefSet make_stringrefset(std::vector &string_vec) { + BindgenStringRefSet set; + set.len = string_vec.size(); + set.strings = new BindgenStringRef[set.len]; + for (size_t i = 0; i < set.len; ++i) + set.strings[i] = stringref(string_vec[i]); + return set; +} + +void deleteString(BindgenStringRef *s) { + if (s) + delete[] s->s; +} + +char *cString(BindgenStringRef *s) { + return s ? s->s : nullptr; +} + +void deleteStringSet(BindgenStringRefSet *s) { + if (s) { + for (size_t i = 0; i < s->len; ++i) { + delete[] s->strings[i].s; + } + delete[] s->strings; + } +} + +void deleteSourceLocation(SourceLocation *s) { + if (s) + delete s; +} + +void deleteSourceRange(BindgenSourceRange *s) { + if (s) { + delete s->B; + delete s->E; + } +} + +ASTContext *ASTUnit_getContext(ASTUnit *Unit) { + return &Unit->getASTContext(); +} + +void disposeASTUnit(ASTUnit *AU) { + delete AU; +} + +unsigned ASTUnit_getNumDiagnostics(const ASTUnit *AU) { + return AU->stored_diag_size(); +} + +const StoredDiagnostic *ASTUnit_getDiagnostic(const ASTUnit *AU, unsigned i) { + return (AU->stored_diag_begin()+i); +} + +const TargetInfo *ASTUnit_getTargetInfo(ASTUnit *Unit) { + return &Unit->getASTContext().getTargetInfo(); +} + +int TargetInfo_getPointerWidth(const TargetInfo *TI) { + if (!TI) + return -1; + // Address space 0 is the normal address space for all platforms + return TI->getPointerWidth(0); +} + +BindgenStringRef TargetInfo_getTriple(const TargetInfo *TI) { + if (!TI) + return stringref(); + + std::string Triple = TI->getTriple().normalize(); + return stringref(Triple); +} + +struct EvalResult { + CXEvalResultKind EvalType; + APValue Val; + std::string stringVal; + + EvalResult() : EvalType(CXEval_UnExposed) {} + EvalResult(APValue Val) : EvalType(CXEval_UnExposed), Val(Val) { + if (Val.isInt()) + EvalType = CXEval_Int; + else if (Val.isFloat()) + EvalType = CXEval_Float; + } + EvalResult(std::string str) : EvalType(CXEval_StrLiteral), stringVal(str) {} +}; + +void deleteEvalResult(EvalResult *e) { + delete e; +} + +EvalResult *Expr_Evaluate(const Expr *E, ASTContext *Ctx) { + if (!E || E->isValueDependent()) + return nullptr; + + Expr::EvalResult res; + if (E->EvaluateAsRValue(res, *Ctx)) { + if (E->getStmtClass() == Stmt::ImplicitCastExprClass) { + const ImplicitCastExpr *I = dyn_cast(&*E); + auto *subExpr = I->getSubExprAsWritten(); + if (subExpr->getStmtClass() == Stmt::StringLiteralClass) { + auto StrE = cast(I->getSubExprAsWritten()); + return new EvalResult(StrE->getString().str()); + } + } else if (E->getStmtClass() == Stmt::StringLiteralClass) { + auto StrE = cast(&*E); + return new EvalResult(StrE->getString().str()); + } + return new EvalResult(res.Val); + } + + return nullptr; +} + +EvalResult *Decl_Evaluate(const Decl *D, ASTContext *Ctx) { + if (!D) + return nullptr; + + const Expr *E; + if (auto *Var = dyn_cast(&*D)) + E = Var->getInit(); + else if (auto *Field = dyn_cast(&*D)) + E = Field->getInClassInitializer(); + else + return nullptr; + + return Expr_Evaluate(E, Ctx); +} + +CXEvalResultKind EvalResult_getKind(EvalResult *ER) { + if (!ER) + return CXEval_UnExposed; + return ER->EvalType; +} + +double EvalResult_getAsDouble(EvalResult *ER) { + if (!ER) + return 0; + auto apFloat = ER->Val.getFloat(); + bool ignored; +#if CLANG_VERSION_MAJOR > 3 + apFloat.convert(llvm::APFloat::IEEEdouble(), + llvm::APFloat::rmNearestTiesToEven, &ignored); +#else // CLANG_VERSION_MAJOR <= 3.9 + apFloat.convert(llvm::APFloat::IEEEdouble, + llvm::APFloat::rmNearestTiesToEven, &ignored); +#endif + return apFloat.convertToDouble(); +} + +bool EvalResult_isUnsignedInt(EvalResult *ER) { + return ER && + ER->EvalType == CXEval_Int && + ER->Val.getInt().isUnsigned(); +} + +long long EvalResult_getAsLongLong(EvalResult *ER) { + if (!ER) + return 0; + + auto intVal = ER->Val.getInt(); + if (intVal.isUnsigned()) + return intVal.getZExtValue(); + else + return intVal.getExtValue(); +} + +unsigned long long EvalResult_getAsUnsigned(EvalResult *ER) { + return static_cast(EvalResult_getAsLongLong(ER)); +} + +BindgenStringRef EvalResult_getAsStr(EvalResult *ER) { + if (!ER) + return stringref(); + + return stringref(ER->stringVal); +} + +BindgenStringRef Diagnostic_format(const StoredDiagnostic *D) { + if (!D) + return stringref(); + + return stringref(D->getMessage()); +} + +const Decl *getTranslationUnitDecl(ASTUnit *Unit) { + return Unit->getASTContext().getTranslationUnitDecl(); +} + +bool CursorKind_isInvalid(CXCursorKind kind) { + return kind >= CXCursor_FirstInvalid && kind <= CXCursor_LastInvalid; +} + +const Decl *Decl_getLexicalParent(const Decl *D) { + if (!D) + return nullptr; + + const DeclContext *DC = D->getLexicalDeclContext(); + if (!DC) + return nullptr; + + return cast(DC); +} + +const Decl *Decl_getSemanticParent(const Decl *D) { + if (!D) + return nullptr; + + const DeclContext *DC = D->getDeclContext(); + if (!DC) + return nullptr; + + // We replace CXXRecordDecl's inside ClassTemplateDecls with just the + // ClassTemplateDecl because we never expose the inner CXXRecordDecl to Rust. + if (auto *RD = dyn_cast(DC)) { + auto *ClassTemplate = RD->getDescribedClassTemplate(); + if (ClassTemplate) + return ClassTemplate; + } + + return cast(DC); +} + +const Decl *Decl_getReferenced(const Decl *D) { + if (!D) + return nullptr; + + // Bindgen doesn't handle UsingDecl references specially, but if we did, this + // is where that would go. + + return D; +} + +const Decl *Decl_getCanonical(const Decl *D) { + if (!D) + return nullptr; + if (const ObjCCategoryImplDecl *CatImplD = dyn_cast(D)) + if (ObjCCategoryDecl *CatD = CatImplD->getCategoryDecl()) + return CatD; + + if (const ObjCImplDecl *ImplD = dyn_cast(D)) + if (const ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) + return IFD; + + return D->getCanonicalDecl(); +} + +const Decl *Decl_getArgument(const Decl *D, unsigned i) { + if (!D) + return nullptr; + + if (const ObjCMethodDecl *MD = dyn_cast_or_null(&*D)) { + if (i < MD->param_size()) + return MD->parameters()[i]; + } else if (const FunctionDecl *FD = dyn_cast_or_null(&*D)) { + if (i < FD->param_size()) + return FD->parameters()[i]; + } + + return nullptr; +} + +int Decl_getNumArguments(const Decl *D) { + if (const ObjCMethodDecl *MD = dyn_cast_or_null(&*D)) + return MD->param_size(); + if (const FunctionDecl *FD = dyn_cast_or_null(&*D)) + return FD->param_size(); + + return -1; +} + +BindgenStringRef Decl_getUSR(const Decl *D) { + SmallString<128> Buf; + if (index::generateUSRForDecl(&*D, Buf)) + return stringref(); + else + return stringref(Buf.str()); +} + +CXCursorKind Decl_getCXCursorKind(const Decl *D) { + if (!D) + return CXCursor_NoDeclFound; + else + return getCursorKindForDecl(&*D); +} + +bool Decl_isDefinition(const Decl *D) { + if (auto VD = dyn_cast_or_null(&*D)) + return VD->getDefinition() == &*D; + if (auto FD = dyn_cast_or_null(&*D)) + return FD->isThisDeclarationADefinition(); + if (auto TD = dyn_cast_or_null(&*D)) + return TD->getDefinition() == &*D; + + return false; +} + +SourceLocation *Decl_getLocation(const Decl *D) { + if (!D) + return nullptr; + return new SourceLocation(D->getLocation()); +} + +BindgenStringRef Decl_getRawCommentText(const Decl *D, ASTContext *Ctx) { + if (!D) + return stringref(); + + auto *RC = Ctx->getRawCommentForAnyRedecl(&*D); + return RC ? stringref(RC->getRawText(Ctx->getSourceManager())) : stringref(); +} + +comments::Comment *Decl_getParsedComment(const Decl *D, ASTContext *Ctx) { + if (!D) + return nullptr; + return Ctx->getCommentForDecl(&*D, nullptr); +} + +BindgenQualType make_type_compatible(QualType QT) { + if (QT.isNull()) + return nullptr; + + // libclang does not return AttributedTypes if + // CXTranslationUnit_IncludeAttributedTypes is not set, and bindgen assumes it + // is not set. + if (auto *ATT = QT->getAs()) + return make_type_compatible(ATT->getEquivalentType()); + + // libclang does not return ParenTypes + if (auto *PTT = QT->getAs()) + return make_type_compatible(PTT->getInnerType()); + + // Decayed types should be passed as their original type + if (auto *DT = QT->getAs()) + return make_type_compatible(DT->getOriginalType()); + + return QT.getAsOpaquePtr(); +} + +BindgenQualType Decl_getType(const Decl *D, ASTContext *Ctx) { + auto ty = QualType(); + if (!D) + return nullptr; + + if (auto *TD = dyn_cast(&*D)) + ty = Ctx->getTypeDeclType(TD); + else if (auto *ID = dyn_cast(&*D)) + ty = Ctx->getObjCInterfaceType(ID); + else if (auto *DD = dyn_cast(&*D)) + ty = DD->getType(); + else if (auto *VD = dyn_cast(&*D)) + ty = VD->getType(); + else if (auto *PD = dyn_cast(&*D)) + ty = PD->getType(); + else if (auto *FTD = dyn_cast(&*D)) + ty = FTD->getTemplatedDecl()->getType(); + else + return nullptr; + + return make_type_compatible(ty); +} + +bool Decl_isFunctionInlined(const Decl *D) { + if (auto *FD = dyn_cast_or_null(&*D)) + return FD->isInlined(); + else + return false; +} + +int Decl_getFieldDeclBitWidth(const Decl *D, ASTContext *Ctx) { + if (auto *FD = dyn_cast_or_null(&*D)) { + if (FD->isBitField()) + return FD->getBitWidthValue(*Ctx); + } + return -1; +} + +BindgenQualType Decl_getEnumDeclIntegerType(const Decl *D) { + if (auto *TD = dyn_cast_or_null(&*D)) + return make_type_compatible(TD->getIntegerType()); + else + return nullptr; +} + +int64_t Decl_getEnumConstantValue(const Decl *D) { + if (auto *TD = dyn_cast_or_null(&*D)) + return TD->getInitVal().getSExtValue(); + else + return LLONG_MIN; +} + +uint64_t Decl_getEnumConstantUnsignedValue(const Decl *D) { + if (auto *TD = dyn_cast_or_null(&*D)) + return TD->getInitVal().getZExtValue(); + else + return ULLONG_MAX; +} + +long long Decl_getOffsetOfField(const Decl *D, ASTContext *Ctx) { + auto *RD = dyn_cast_or_null(D->getDeclContext()); + auto Err = visitRecordForValidation(RD); + if (Err < 0) + return Err; + + if (auto *FD = dyn_cast_or_null(&*D)) + return Ctx->getFieldOffset(FD); + if (auto *IFD = dyn_cast_or_null(&*D)) + return Ctx->getFieldOffset(IFD); + + return -1; +} + +BindgenSourceRange Decl_getSourceRange(const Decl *D) { + return make_sourcerange(D->getSourceRange()); +} + +BindgenQualType Decl_getTypedefDeclUnderlyingType(const Decl *D) { + if (auto *TD = dyn_cast_or_null(&*D)) + return make_type_compatible(TD->getUnderlyingType()); + else + return nullptr; +} + +bool CXXField_isMutable(const Decl *D) { + if (const auto FD = dyn_cast_or_null(&*D)) + return FD->isMutable(); + else + return false; +} + +bool CXXMethod_isStatic(const Decl *D) { + auto *Method = + D ? dyn_cast_or_null(D->getAsFunction()) : nullptr; + return Method && Method->isStatic(); +} + +bool CXXMethod_isConst(const Decl *D) { + auto *Method = + D ? dyn_cast_or_null(D->getAsFunction()) : nullptr; + if (!Method) + return false; +#if CLANG_VERSION_MAJOR > 8 + return Method->getMethodQualifiers().hasConst(); +#elif CLANG_VERSION_MAJOR > 7 + return Method->getTypeQualifiers().hasConst(); +#else + return Method->getTypeQualifiers() & Qualifiers::Const; +#endif // CLANG_VERSION_MAJOR +} + +bool CXXMethod_isVirtual(const Decl *D) { + auto *Method = + D ? dyn_cast_or_null(D->getAsFunction()) : nullptr; + return Method && Method->isVirtual(); +} + +bool CXXMethod_isPureVirtual(const Decl *D) { + auto *Method = + D ? dyn_cast_or_null(D->getAsFunction()) : nullptr; + return Method && Method->isVirtual() && Method->isPure(); +} + +BindgenQualType Decl_getResultType(const Decl *D, ASTContext *Ctx) { + if (auto *MD = dyn_cast_or_null(D)) + return make_type_compatible(MD->getReturnType()); + + return Type_getResultType(Decl_getType(D, Ctx)); +} + +BindgenStringRef Expr_getSpelling(const Expr *E) { + if (auto *SL = dyn_cast_or_null(&*E)) { + SmallString<256> Buf; + llvm::raw_svector_ostream OS(Buf); + SL->outputString(OS); + return stringref(OS.str()); + } + if (auto *D = getDeclFromExpr(&*E)) + return Decl_getSpelling(D); + + return stringref(); +} + +CXCursorKind Expr_getCXCursorKind(const Expr *E) { + switch (E->getStmtClass()) { + case Stmt::NoStmtClass: + return CXCursor_NotImplemented; + case Stmt::CaseStmtClass: + return CXCursor_CaseStmt; + case Stmt::DefaultStmtClass: + return CXCursor_DefaultStmt; + case Stmt::IfStmtClass: + return CXCursor_IfStmt; + case Stmt::SwitchStmtClass: + return CXCursor_SwitchStmt; + case Stmt::WhileStmtClass: + return CXCursor_WhileStmt; + case Stmt::DoStmtClass: + return CXCursor_DoStmt; + case Stmt::ForStmtClass: + return CXCursor_ForStmt; + case Stmt::GotoStmtClass: + return CXCursor_GotoStmt; + case Stmt::IndirectGotoStmtClass: + return CXCursor_IndirectGotoStmt; + case Stmt::ContinueStmtClass: + return CXCursor_ContinueStmt; + case Stmt::BreakStmtClass: + return CXCursor_BreakStmt; + case Stmt::ReturnStmtClass: + return CXCursor_ReturnStmt; + case Stmt::GCCAsmStmtClass: + return CXCursor_GCCAsmStmt; + case Stmt::MSAsmStmtClass: + return CXCursor_MSAsmStmt; + case Stmt::ObjCAtTryStmtClass: + return CXCursor_ObjCAtTryStmt; + case Stmt::ObjCAtCatchStmtClass: + return CXCursor_ObjCAtCatchStmt; + case Stmt::ObjCAtFinallyStmtClass: + return CXCursor_ObjCAtFinallyStmt; + case Stmt::ObjCAtThrowStmtClass: + return CXCursor_ObjCAtThrowStmt; + case Stmt::ObjCAtSynchronizedStmtClass: + return CXCursor_ObjCAtSynchronizedStmt; + case Stmt::ObjCAutoreleasePoolStmtClass: + return CXCursor_ObjCAutoreleasePoolStmt; + case Stmt::ObjCForCollectionStmtClass: + return CXCursor_ObjCForCollectionStmt; + case Stmt::CXXCatchStmtClass: + return CXCursor_CXXCatchStmt; + case Stmt::CXXTryStmtClass: + return CXCursor_CXXTryStmt; + case Stmt::CXXForRangeStmtClass: + return CXCursor_CXXForRangeStmt; + case Stmt::SEHTryStmtClass: + return CXCursor_SEHTryStmt; + case Stmt::SEHExceptStmtClass: + return CXCursor_SEHExceptStmt; + case Stmt::SEHFinallyStmtClass: + return CXCursor_SEHFinallyStmt; + case Stmt::SEHLeaveStmtClass: + return CXCursor_SEHLeaveStmt; + + case Stmt::CoroutineBodyStmtClass: + case Stmt::CoreturnStmtClass: + return CXCursor_UnexposedStmt; + + case Stmt::OpaqueValueExprClass: + if (auto *Src = cast(&*E)->getSourceExpr()) + return Expr_getCXCursorKind(Src); + return CXCursor_UnexposedExpr; + + case Stmt::PseudoObjectExprClass: + return Expr_getCXCursorKind( + cast(&*E)->getSyntacticForm()); + + case Stmt::CompoundStmtClass: + return CXCursor_CompoundStmt; + + case Stmt::NullStmtClass: + return CXCursor_NullStmt; + + case Stmt::LabelStmtClass: + return CXCursor_LabelStmt; + + case Stmt::AttributedStmtClass: + return CXCursor_UnexposedStmt; + + case Stmt::DeclStmtClass: + return CXCursor_DeclStmt; + + case Stmt::CapturedStmtClass: + return CXCursor_UnexposedStmt; + + case Stmt::IntegerLiteralClass: + return CXCursor_IntegerLiteral; + +#if CLANG_VERSION_MAJOR > 7 + case Stmt::FixedPointLiteralClass: + return CXCursor_FixedPointLiteral; +#endif // CLANG_VERSION_MAJOR > 7 + + case Stmt::FloatingLiteralClass: + return CXCursor_FloatingLiteral; + + case Stmt::ImaginaryLiteralClass: + return CXCursor_ImaginaryLiteral; + + case Stmt::StringLiteralClass: + return CXCursor_StringLiteral; + + case Stmt::CharacterLiteralClass: + return CXCursor_CharacterLiteral; + +#if CLANG_VERSION_MAJOR > 7 + case Stmt::ConstantExprClass: + return Expr_getCXCursorKind(cast(&*E)->getSubExpr()); +#endif // CLANG_VERSION_MAJOR > 7 + + case Stmt::ParenExprClass: + return CXCursor_ParenExpr; + + case Stmt::UnaryOperatorClass: + return CXCursor_UnaryOperator; + + case Stmt::UnaryExprOrTypeTraitExprClass: + case Stmt::CXXNoexceptExprClass: + return CXCursor_UnaryExpr; + + case Stmt::MSPropertySubscriptExprClass: + case Stmt::ArraySubscriptExprClass: + return CXCursor_ArraySubscriptExpr; + + case Stmt::OMPArraySectionExprClass: + return CXCursor_OMPArraySectionExpr; + + case Stmt::BinaryOperatorClass: + return CXCursor_BinaryOperator; + + case Stmt::CompoundAssignOperatorClass: + return CXCursor_CompoundAssignOperator; + + case Stmt::ConditionalOperatorClass: + return CXCursor_ConditionalOperator; + + case Stmt::CStyleCastExprClass: + return CXCursor_CStyleCastExpr; + + case Stmt::CompoundLiteralExprClass: + return CXCursor_CompoundLiteralExpr; + + case Stmt::InitListExprClass: + return CXCursor_InitListExpr; + + case Stmt::AddrLabelExprClass: + return CXCursor_AddrLabelExpr; + + case Stmt::StmtExprClass: + return CXCursor_StmtExpr; + + case Stmt::GenericSelectionExprClass: + return CXCursor_GenericSelectionExpr; + + case Stmt::GNUNullExprClass: + return CXCursor_GNUNullExpr; + + case Stmt::CXXStaticCastExprClass: + return CXCursor_CXXStaticCastExpr; + + case Stmt::CXXDynamicCastExprClass: + return CXCursor_CXXDynamicCastExpr; + + case Stmt::CXXReinterpretCastExprClass: + return CXCursor_CXXReinterpretCastExpr; + + case Stmt::CXXConstCastExprClass: + return CXCursor_CXXConstCastExpr; + + case Stmt::CXXFunctionalCastExprClass: + return CXCursor_CXXFunctionalCastExpr; + + case Stmt::CXXTypeidExprClass: + return CXCursor_CXXTypeidExpr; + + case Stmt::CXXBoolLiteralExprClass: + return CXCursor_CXXBoolLiteralExpr; + + case Stmt::CXXNullPtrLiteralExprClass: + return CXCursor_CXXNullPtrLiteralExpr; + + case Stmt::CXXThisExprClass: + return CXCursor_CXXThisExpr; + + case Stmt::CXXThrowExprClass: + return CXCursor_CXXThrowExpr; + + case Stmt::CXXNewExprClass: + return CXCursor_CXXNewExpr; + + case Stmt::CXXDeleteExprClass: + return CXCursor_CXXDeleteExpr; + + case Stmt::ObjCStringLiteralClass: + return CXCursor_ObjCStringLiteral; + + case Stmt::ObjCEncodeExprClass: + return CXCursor_ObjCEncodeExpr; + + case Stmt::ObjCSelectorExprClass: + return CXCursor_ObjCSelectorExpr; + + case Stmt::ObjCProtocolExprClass: + return CXCursor_ObjCProtocolExpr; + case Stmt::ObjCBoolLiteralExprClass: + return CXCursor_ObjCBoolLiteralExpr; + +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + case Stmt::ObjCAvailabilityCheckExprClass: + return CXCursor_ObjCAvailabilityCheckExpr; +#endif // CLANG_VERSION > 3.8 + + case Stmt::ObjCBridgedCastExprClass: + return CXCursor_ObjCBridgedCastExpr; + + case Stmt::BlockExprClass: + return CXCursor_BlockExpr; + + case Stmt::PackExpansionExprClass: + return CXCursor_PackExpansionExpr; + + case Stmt::SizeOfPackExprClass: + return CXCursor_SizeOfPackExpr; + + case Stmt::DeclRefExprClass: + return CXCursor_DeclRefExpr; + + case Stmt::DependentScopeDeclRefExprClass: + case Stmt::SubstNonTypeTemplateParmExprClass: + case Stmt::SubstNonTypeTemplateParmPackExprClass: + case Stmt::FunctionParmPackExprClass: + case Stmt::UnresolvedLookupExprClass: + case Stmt::TypoExprClass: // A typo could actually be a DeclRef or a MemberRef + return CXCursor_DeclRefExpr; + + case Stmt::CXXDependentScopeMemberExprClass: + case Stmt::CXXPseudoDestructorExprClass: + case Stmt::MemberExprClass: + case Stmt::MSPropertyRefExprClass: + case Stmt::ObjCIsaExprClass: + case Stmt::ObjCIvarRefExprClass: + case Stmt::ObjCPropertyRefExprClass: + case Stmt::UnresolvedMemberExprClass: + return CXCursor_MemberRefExpr; + + case Stmt::CallExprClass: + case Stmt::CXXOperatorCallExprClass: + case Stmt::CXXMemberCallExprClass: + case Stmt::CUDAKernelCallExprClass: + case Stmt::CXXConstructExprClass: +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + case Stmt::CXXInheritedCtorInitExprClass: +#endif // CLANG_VERSION > 3.8 + case Stmt::CXXTemporaryObjectExprClass: + case Stmt::CXXUnresolvedConstructExprClass: + case Stmt::UserDefinedLiteralClass: + return CXCursor_CallExpr; + + case Stmt::LambdaExprClass: + return CXCursor_LambdaExpr; + + case Stmt::ObjCMessageExprClass: + return CXCursor_ObjCMessageExpr; + + case Stmt::MSDependentExistsStmtClass: + return CXCursor_UnexposedStmt; + case Stmt::OMPParallelDirectiveClass: + return CXCursor_OMPParallelDirective; + case Stmt::OMPSimdDirectiveClass: + return CXCursor_OMPSimdDirective; + case Stmt::OMPForDirectiveClass: + return CXCursor_OMPForDirective; + case Stmt::OMPForSimdDirectiveClass: + return CXCursor_OMPForSimdDirective; + case Stmt::OMPSectionsDirectiveClass: + return CXCursor_OMPSectionsDirective; + case Stmt::OMPSectionDirectiveClass: + return CXCursor_OMPSectionDirective; + case Stmt::OMPSingleDirectiveClass: + return CXCursor_OMPSingleDirective; + case Stmt::OMPMasterDirectiveClass: + return CXCursor_OMPMasterDirective; + case Stmt::OMPCriticalDirectiveClass: + return CXCursor_OMPCriticalDirective; + case Stmt::OMPParallelForDirectiveClass: + return CXCursor_OMPParallelForDirective; + case Stmt::OMPParallelForSimdDirectiveClass: + return CXCursor_OMPParallelForSimdDirective; + case Stmt::OMPParallelSectionsDirectiveClass: + return CXCursor_OMPParallelSectionsDirective; + case Stmt::OMPTaskDirectiveClass: + return CXCursor_OMPTaskDirective; + case Stmt::OMPTaskyieldDirectiveClass: + return CXCursor_OMPTaskyieldDirective; + case Stmt::OMPBarrierDirectiveClass: + return CXCursor_OMPBarrierDirective; + case Stmt::OMPTaskwaitDirectiveClass: + return CXCursor_OMPTaskwaitDirective; + case Stmt::OMPTaskgroupDirectiveClass: + return CXCursor_OMPTaskgroupDirective; + case Stmt::OMPFlushDirectiveClass: + return CXCursor_OMPFlushDirective; + case Stmt::OMPOrderedDirectiveClass: + return CXCursor_OMPOrderedDirective; + case Stmt::OMPAtomicDirectiveClass: + return CXCursor_OMPAtomicDirective; + case Stmt::OMPTargetDirectiveClass: + return CXCursor_OMPTargetDirective; +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + case Stmt::OMPTargetDataDirectiveClass: + return CXCursor_OMPTargetDataDirective; + case Stmt::OMPTargetEnterDataDirectiveClass: + return CXCursor_OMPTargetEnterDataDirective; + case Stmt::OMPTargetExitDataDirectiveClass: + return CXCursor_OMPTargetExitDataDirective; + case Stmt::OMPTargetParallelDirectiveClass: + return CXCursor_OMPTargetParallelDirective; + case Stmt::OMPTargetParallelForDirectiveClass: + return CXCursor_OMPTargetParallelForDirective; + case Stmt::OMPTargetUpdateDirectiveClass: + return CXCursor_OMPTargetUpdateDirective; +#endif // CLANG_VERSION > 3.8 + case Stmt::OMPTeamsDirectiveClass: + return CXCursor_OMPTeamsDirective; + case Stmt::OMPCancellationPointDirectiveClass: + return CXCursor_OMPCancellationPointDirective; + case Stmt::OMPCancelDirectiveClass: + return CXCursor_OMPCancelDirective; + case Stmt::OMPTaskLoopDirectiveClass: + return CXCursor_OMPTaskLoopDirective; + case Stmt::OMPTaskLoopSimdDirectiveClass: + return CXCursor_OMPTaskLoopSimdDirective; + case Stmt::OMPDistributeDirectiveClass: + return CXCursor_OMPDistributeDirective; +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + case Stmt::OMPDistributeParallelForDirectiveClass: + return CXCursor_OMPDistributeParallelForDirective; + case Stmt::OMPDistributeParallelForSimdDirectiveClass: + return CXCursor_OMPDistributeParallelForSimdDirective; + case Stmt::OMPDistributeSimdDirectiveClass: + return CXCursor_OMPDistributeSimdDirective; + case Stmt::OMPTargetParallelForSimdDirectiveClass: + return CXCursor_OMPTargetParallelForSimdDirective; +#endif // CLANG_VERSION > 3.8 +#if CLANG_VERSION_MAJOR > 3 + case Stmt::OMPTargetSimdDirectiveClass: + return CXCursor_OMPTargetSimdDirective; + case Stmt::OMPTeamsDistributeDirectiveClass: + return CXCursor_OMPTeamsDistributeDirective; + case Stmt::OMPTeamsDistributeSimdDirectiveClass: + return CXCursor_OMPTeamsDistributeSimdDirective; + case Stmt::OMPTeamsDistributeParallelForSimdDirectiveClass: + return CXCursor_OMPTeamsDistributeParallelForSimdDirective; + case Stmt::OMPTeamsDistributeParallelForDirectiveClass: + return CXCursor_OMPTeamsDistributeParallelForDirective; + case Stmt::OMPTargetTeamsDirectiveClass: + return CXCursor_OMPTargetTeamsDirective; + case Stmt::OMPTargetTeamsDistributeDirectiveClass: + return CXCursor_OMPTargetTeamsDistributeDirective; + case Stmt::OMPTargetTeamsDistributeParallelForDirectiveClass: + return CXCursor_OMPTargetTeamsDistributeParallelForDirective; + case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass: + return CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective; + case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass: + return CXCursor_OMPTargetTeamsDistributeSimdDirective; +#endif // CLANG_VERSION_MAJOR > 3 +#if CLANG_VERSION_MAJOR > 8 + case Stmt::BuiltinBitCastExprClass: + return CXCursor_BuiltinBitCastExpr; +#endif // CLANG_VERSION_MAJOR > 8 + + default: + return CXCursor_UnexposedExpr; + } +} + +BindgenQualType Expr_getType(const Expr *E) { return make_type_compatible(E->getType()); } + +BindgenSourceRange Expr_getSourceRange(const Expr *E) { + return make_sourcerange(E->getSourceRange()); +} + +class BindgenVisitor : public RecursiveASTVisitor { + ASTUnit &AST; + Visitor VisitFn; + CXClientData Data; + Node Parent; + +public: + explicit BindgenVisitor(ASTUnit &AST, Visitor V, CXClientData data) : AST(AST), VisitFn(V), Data(data) {} + + bool shouldVisitImplicitCode() { + return true; + } + + void setParent(Node n) { + Parent = n; + } + + bool TraverseDeclTyped(Decl *D, CXCursorKind kind) { + if (!D) + return false; + + bool skip = !Parent; + + // D->dump(); + // libclang doesn't visit the CXXRecordDecl inside ClassTemplateDecl nodes + if (Parent.kind == CXCursor_ClassTemplate + && isa(D)) + skip = true; + + // libclang exposes forward class and protocol declarations as references + if (kind == CXCursor_ObjCInterfaceDecl) { + auto *ID = cast(D); + if (!ID->isThisDeclarationADefinition()) + kind = CXCursor_ObjCClassRef; + } else if (kind == CXCursor_ObjCProtocolDecl) { + auto *PD = cast(D); + if (!PD->isThisDeclarationADefinition()) + kind = CXCursor_ObjCProtocolRef; + } + + // D->dump(); + Node node(D, kind); + if (!skip) { + // We don't want to visit implicit decls or their children + if (D->isImplicit() && !isa(D)) + return true; + + switch (VisitFn(node, Parent, &AST, Data)) { + case CXChildVisit_Break: + return false; + case CXChildVisit_Continue: + return true; + case CXChildVisit_Recurse: + break; + } + } + + // Do not recurse through references + if (kind >= CXCursor_FirstRef && kind <= CXCursor_LastRef + && kind != CXCursor_CXXBaseSpecifier) + return true; + + auto OldParent = Parent; + Parent = node; + bool res = RecursiveASTVisitor::TraverseDecl(D); + Parent = OldParent; + return res; + } + + bool TraverseDecl(Decl *D) { + return TraverseDeclTyped(D, Decl_getCXCursorKind(D)); + } + + bool TraverseExprTyped(Expr *E, CXCursorKind kind) { + if (!E) + return true; + + Node node(E, kind); + if (Parent) { + // E->dump(); + switch (VisitFn(node, Parent, &AST, Data)) { + case CXChildVisit_Break: + return false; + case CXChildVisit_Continue: + return true; + case CXChildVisit_Recurse: + break; + } + } + + auto OldParent = Parent; + Parent = node; + bool res = RecursiveASTVisitor::TraverseStmt(E); + Parent = OldParent; + return res; + } + + bool TraverseStmt(Stmt *S) { + if (!S) + return true; + if (auto *E = dyn_cast(S)) + return TraverseExprTyped(E, Expr_getCXCursorKind(E)); + return RecursiveASTVisitor::TraverseStmt(S); + } + + bool VisitSizeOfPackExpr(SizeOfPackExpr *E) { + NamedDecl *Pack = E->getPack(); + if (isa(Pack)) { + Node node(Pack, CXCursor_TypeRef); + Node parent(E, Expr_getCXCursorKind(E)); + return VisitFn(node, parent, &AST, Data) != CXChildVisit_Break; + } + if (isa(Pack)) { + Node node(Pack, CXCursor_TemplateRef); + Node parent(E, Expr_getCXCursorKind(E)); + return VisitFn(node, parent, &AST, Data) != CXChildVisit_Break; + } + return true; + } + + bool VisitTypeLoc(TypeLoc TL) { + // if (TL) TL.getTypePtr()->dump(); + return true; + } + + bool VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { + if (!TL) + return true; + return TraverseStmt(TL.getUnderlyingExpr()); + } + + bool VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { + if (!TL) + return true; + return TraverseStmt(TL.getUnderlyingExpr()); + } + + bool VisitTypedefTypeLoc(TypedefTypeLoc TL) { + if (!TL) + return true; + return TraverseDeclTyped(TL.getTypedefNameDecl(), CXCursor_TypeRef); + } + + bool VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { + if (!TL) + return true; + return TraverseDeclTyped(TL.getDecl(), CXCursor_TypeRef); + } + + bool VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { + if (!TL) + return true; + return TraverseDeclTyped(TL.getDecl(), CXCursor_TypeRef); + } + + bool VisitTagTypeLoc(TagTypeLoc TL) { + if (!TL) + return true; + if (TL.isDefinition()) + return TraverseDecl(TL.getDecl()); + else + return TraverseDeclTyped(TL.getDecl(), CXCursor_TypeRef); + } + + bool VisitRecordTypeLoc(RecordTypeLoc TL) { + if (!TL) + return true; + return TraverseDeclTyped(TL.getDecl(), CXCursor_TypeRef); + } + + bool VisitEnumTypeLoc(EnumTypeLoc TL) { + if (!TL) + return true; + return TraverseDeclTyped(TL.getDecl(), CXCursor_TypeRef); + } + + bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { + if (!TL) + return true; + return TraverseDeclTyped(TL.getDecl(), CXCursor_TypeRef); + } + + bool VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { + if (!TL) + return true; + + ASTContext &Context = AST.getASTContext(); + QualType Ty; + switch (TL.getTypePtr()->getKind()) { + case BuiltinType::ObjCId: + Ty = Context.getObjCIdType(); + break; + case BuiltinType::ObjCClass: + Ty = Context.getObjCClassType(); + break; + case BuiltinType::ObjCSel: + Ty = Context.getObjCSelType(); + break; + default: + break; + } + + if (!Ty.isNull()) { + if (auto *TD = Ty->getAs()) { + Node node(TD->getDecl(), CXCursor_TypeRef); + return VisitFn(node, Parent, &AST, Data) != CXChildVisit_Break; + } + } + + return true; + } + + bool VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { + if (!TL) + return true; + + return TraverseDeclTyped(TL.getIFaceDecl(), CXCursor_ObjCClassRef); + } + +#if CLANG_VERSION_MAJOR > 3 + bool VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { + if (!TL) + return true; + Node node(TL.getDecl(), CXCursor_TypeRef); + if (VisitFn(node, Parent, &AST, Data) == CXChildVisit_Break) + return false; + for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) { + Node node(TL.getProtocol(I), CXCursor_ObjCProtocolRef); + if (VisitFn(node, Parent, &AST, Data) == CXChildVisit_Break) + return false; + } + return true; + } +#endif // CLANG_VERSION_MAJOR > 3 + + bool VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { + if (!TL) + return true; + + for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) { + Node node(TL.getProtocol(I), CXCursor_ObjCProtocolRef); + if (VisitFn(node, Parent, &AST, Data) == CXChildVisit_Break) + return false; + } + + return true; + } + + bool TraverseTemplateName(TemplateName Name) { + Node node; + switch (Name.getKind()) { + case TemplateName::Template: + node = Node(Name.getAsTemplateDecl(), CXCursor_TemplateRef); + break; + + case TemplateName::OverloadedTemplate: + // libclang visits this, but we don't need it for bindgen + return true; + +#if CLANG_VERSION_MAJOR > 8 + case TemplateName::AssumedTemplate: + return true; +#endif // CLANG_VERSION_MAJOR > 8 + + case TemplateName::DependentTemplate: + return true; + + case TemplateName::QualifiedTemplate: + node = Node(Name.getAsQualifiedTemplateName()->getDecl(), CXCursor_TemplateRef); + break; + + case TemplateName::SubstTemplateTemplateParm: + node = Node(Name.getAsSubstTemplateTemplateParm()->getParameter(), CXCursor_TemplateRef); + break; + + case TemplateName::SubstTemplateTemplateParmPack: + node = Node(Name.getAsSubstTemplateTemplateParmPack()->getParameterPack(), CXCursor_TemplateRef); + break; + } + + switch (VisitFn(node, Parent, &AST, Data)) { + case CXChildVisit_Break: + return false; + case CXChildVisit_Continue: + return true; + case CXChildVisit_Recurse: + break; + } + + auto OldParent = Parent; + Parent = node; + bool res = RecursiveASTVisitor::TraverseTemplateName(Name); + Parent = OldParent; + return res; + } + +#if CLANG_VERSION_MAJOR > 5 + + bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base) { + if (Parent) { + switch (VisitFn(Node(&Base), Parent, &AST, Data)) { + case CXChildVisit_Break: + return false; + case CXChildVisit_Continue: + return true; + case CXChildVisit_Recurse: + break; + } + } + + auto OldParent = Parent; + Parent = Node(&Base); + bool res = RecursiveASTVisitor::TraverseCXXBaseSpecifier(Base); + Parent = OldParent; + return res; + } + +#else // CLANG_VERSION_MAJOR <= 5 + + // We need to visit the record decl instead of the base specifier here because + // clang <= 5 doesn't traverse CXXBaseSpecifiers + bool TraverseCXXRecordDecl(CXXRecordDecl *D) { + // D->dump(); + if (D && D->isCompleteDefinition()) { + bool recurse = false; + for (const auto &I : D->bases()) { + switch (VisitFn(Node(&I), Node(D, CXCursor_ClassDecl), &AST, Data)) { + case CXChildVisit_Break: + return false; + case CXChildVisit_Continue: + break; + case CXChildVisit_Recurse: + // Skip siblings and move on to other children of D + recurse = true; + break; + } + if (recurse) + break; + if (!TraverseTypeLoc(I.getTypeSourceInfo()->getTypeLoc())) + return false; + } + } + + auto OldParent = Parent; + Parent = Node(D, CXCursor_ClassDecl); + bool res = RecursiveASTVisitor::TraverseCXXRecordDecl(D); + Parent = OldParent; + return res; + } + +#endif // CLANG_VERSION_MAJOR > 5 + +#if CLANG_VERSION_MAJOR < 6 + bool TraverseClassTemplateDecl(ClassTemplateDecl *D) { + auto params = D->getTemplateParameters(); + if (params) { + for (const auto &P : *params) { + if (!TraverseDecl(P)) + return false; + } + } + + return TraverseCXXRecordDecl(D->getTemplatedDecl()); + } + + bool TraverseVarTemplateDecl(VarTemplateDecl *D) { + auto params = D->getTemplateParameters(); + if (params) { + for (const auto &P : *params) { + if (!TraverseDecl(P)) + return false; + } + } + + return TraverseVarDecl(D->getTemplatedDecl()); + } + + bool TraverseFunctionTemplateDecl(FunctionTemplateDecl *D) { + auto params = D->getTemplateParameters(); + if (params) { + for (const auto &P : *params) { + if (!TraverseDecl(P)) + return false; + } + } + + return TraverseFunctionDecl(D->getTemplatedDecl()); + } +#endif // CLANG_VERSION_MAJOR < 6 + + bool VisitAttr(Attr *A) { + if (Parent) + VisitFn(Node(A), Parent, &AST, Data); + return true; + } + + bool VisitTranslationUnitDecl(TranslationUnitDecl *TU) { + if (!AST.getPreprocessor().getPreprocessingRecord()) + return true; + + PreprocessingRecord &PPRec = + *AST.getPreprocessor().getPreprocessingRecord(); + SourceManager &SM = AST.getSourceManager(); + + bool OnlyLocalDecls = !AST.isMainFileAST() && AST.getOnlyLocalDecls(); + + if (OnlyLocalDecls) + return visitPreprocessedEntities(PPRec.local_begin(), PPRec.local_end(), + PPRec); + + return visitPreprocessedEntities(PPRec.begin(), PPRec.end(), PPRec); + } + + bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { + // We handle forward declarations in TraverseDecl + if (!D || !D->isThisDeclarationADefinition()) + return true; + + if (D->getSuperClass() + && VisitFn(Node(D->getSuperClass(), CXCursor_ObjCSuperClassRef), Parent, &AST, Data) == CXChildVisit_Break) + return false; + + for (auto I : D->protocols()) + if (VisitFn(Node(&*I, CXCursor_ObjCProtocolRef), Parent, &AST, Data) == CXChildVisit_Break) + return false; + + return true; + } + + bool VisitObjCCategoryDecl(ObjCCategoryDecl *ND) { + Node interfaceNode(ND->getClassInterface(), CXCursor_ObjCClassRef); + if (VisitFn(interfaceNode, Parent, &AST, Data) == CXChildVisit_Break) + return false; + + // TypeParamList is visited in RecursiveASTvisitor + + for (auto I : ND->protocols()) + if (VisitFn(Node(&*I, CXCursor_ObjCProtocolRef), Parent, &AST, Data) == CXChildVisit_Break) + return false; + + // We may need to do the weird hacky thing that the libclang visitor does in + // VisitObjCContainerDecl, but I hope not... + return true; + } + + bool VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { + for (auto I : PD->protocols()) + if (VisitFn(Node(&*I, CXCursor_ObjCProtocolRef), Parent, &AST, Data) == CXChildVisit_Break) + return false; + + // We may need to do the weird hacky thing that the libclang visitor does in + // VisitObjCContainerDecl, but I hope not... + return true; + } + + bool VisitObjCPropertyDecl(ObjCPropertyDecl *PD) { + if (!PD) + return true; + + // FIXME: This implements a workaround with @property declarations also + // being + // installed in the DeclContext for the @interface. Eventually this code + // should be removed. + ObjCCategoryDecl *CDecl = dyn_cast(PD->getDeclContext()); + if (!CDecl || !CDecl->IsClassExtension()) + return true; + + ObjCInterfaceDecl *ID = CDecl->getClassInterface(); + if (!ID) + return true; + + IdentifierInfo *PropertyId = PD->getIdentifier(); + ObjCPropertyDecl *prevDecl = +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + ObjCPropertyDecl::findPropertyDecl(cast(ID), PropertyId, PD->getQueryKind()); +#else // CLANG_VERSION <= 3.8 + ObjCPropertyDecl::findPropertyDecl(cast(ID), PropertyId); +#endif + + if (!prevDecl) + return true; + + // Visit synthesized methods since they will be skipped when visiting + // the @interface. + if (ObjCMethodDecl *MD = prevDecl->getGetterMethodDecl()) + if (MD->isPropertyAccessor() && MD->getLexicalDeclContext() == CDecl) + if (!TraverseDecl(MD)) + return false; + + if (ObjCMethodDecl *MD = prevDecl->getSetterMethodDecl()) + if (MD->isPropertyAccessor() && MD->getLexicalDeclContext() == CDecl) + if (!TraverseDecl(MD)) + return false; + + return true; + } + + bool VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { + if (!D) + return true; + return TraverseDecl(D) != CXChildVisit_Break; + } + +private: + template + bool visitPreprocessedEntities(InputIterator First, InputIterator Last, + PreprocessingRecord &PPRec) { + for (; First != Last; ++First) { + PreprocessedEntity *PPE = *First; + if (!PPE) + continue; + + Node node; + if (isa(PPE)) { + node = Node(PPE, CXCursor_MacroExpansion); + } else if (isa(PPE)) { + node = Node(PPE, CXCursor_MacroDefinition); + } else if (isa(PPE)) { + node = Node(PPE, CXCursor_InclusionDirective); + } + if (node) { + if (VisitFn(node, Parent, &AST, Data) == CXChildVisit_Break) + return false; + } + } + + return true; + } +}; + +void Decl_visitChildren(const Decl *Parent, CXCursorKind kind, Visitor V, + ASTUnit *Unit, CXClientData data) { + BindgenVisitor visitor(*Unit, V, data); + visitor.TraverseDeclTyped(const_cast(&*Parent), kind); +} +void Expr_visitChildren(const Expr *Parent, CXCursorKind kind, Visitor V, + ASTUnit *Unit, CXClientData data) { + BindgenVisitor visitor(*Unit, V, data); + visitor.TraverseExprTyped(const_cast(&*Parent), kind); +} +void CXXBaseSpecifier_visitChildren(const CXXBaseSpecifier *Parent, + CXCursorKind kind, Visitor V, ASTUnit *Unit, + CXClientData data) { + BindgenVisitor visitor(*Unit, V, data); +#if CLANG_VERSION_MAJOR > 5 + visitor.TraverseCXXBaseSpecifier(*Parent); +#else + // Clang <= 5 doesn't have RecursiveASTvisitor::TraverseCXXBaseSpecifier + visitor.setParent(Node(Parent)); + visitor.TraverseTypeLoc(Parent->getTypeSourceInfo()->getTypeLoc()); +#endif +} + +void disposeTokens(const ASTUnit *TU, CXToken *Tokens, unsigned NumTokens) { + delete[] Tokens; +} + +BindgenStringRef Type_getTypeSpelling(BindgenQualType T, ASTContext *Context) { + auto QT = QualType::getFromOpaquePtr(T); + SmallString<64> Str; + llvm::raw_svector_ostream OS(Str); + PrintingPolicy PP(Context->getLangOpts()); + + QT.print(OS, PP); + return stringref(OS.str()); +} + +bool Type_isConstQualifiedType(BindgenQualType T) { + auto QT = QualType::getFromOpaquePtr(T); + return QT.isLocalConstQualified(); +} + +int Type_getNumTemplateArguments(BindgenQualType T) { + auto QT = QualType::getFromOpaquePtr(T); + if (QT.isNull()) + return -1; + auto TA = GetTemplateArguments(QT); + if (!TA) + return -1; + + return GetTemplateArgumentArraySize(TA.getValue()); +} + +BindgenQualType Type_getArgType(BindgenQualType T, unsigned i) { + auto QT = QualType::getFromOpaquePtr(T); + if (QT.isNull()) + return nullptr;; + + if (const FunctionProtoType *FD = QT->getAs()) { + unsigned numParams = FD->getNumParams(); + if (i >= numParams) + return nullptr; + return make_type_compatible(FD->getParamType(i)); + } + + return nullptr; +} + +int Type_getNumArgTypes(BindgenQualType T) { + auto QT = QualType::getFromOpaquePtr(T); + if (QT.isNull()) + return -1; + + if (const FunctionProtoType *FD = QT->getAs()) { + return FD->getNumParams(); + } + + if (QT->getAs()) { + return 0; + } + + return -1; +} + +BindgenQualType Type_getCanonicalType(BindgenQualType T, ASTContext *Context) { + auto QT = QualType::getFromOpaquePtr(T); + if (QT.isNull()) + return nullptr; + + return make_type_compatible(Context->getCanonicalType(QT)); +} + +bool Type_isFunctionTypeVariadic(BindgenQualType T) { + auto QT = QualType::getFromOpaquePtr(T); + if (QT.isNull()) + return false; + + if (const FunctionProtoType *FD = QT->getAs()) + return (unsigned)FD->isVariadic(); + + if (QT->getAs()) + return true; + + return false; +} + +BindgenQualType Type_getResultType(BindgenQualType T) { + auto QT = QualType::getFromOpaquePtr(T); + if (QT.isNull()) + return nullptr; + + if (const FunctionType *FD = QT->getAs()) + return make_type_compatible(FD->getReturnType()); + + return nullptr; +} + +BindgenQualType Type_getNamedType(BindgenQualType T) { + auto QT = QualType::getFromOpaquePtr(T); + const Type *TP = QT.getTypePtrOrNull(); + + if (TP && TP->getTypeClass() == Type::Elaborated) + return make_type_compatible(cast(TP)->getNamedType()); + + return nullptr; +} + +BindgenQualType Type_getTemplateArgumentAsType(BindgenQualType T, unsigned index) { + auto QT = QualType::getFromOpaquePtr(T); + if (QT.isNull()) + return nullptr; + + auto TA = GetTemplateArguments(QT); + if (!TA) + return nullptr; + + Optional ArgQT = FindTemplateArgumentTypeAt(TA.getValue(), index); + return make_type_compatible(ArgQT.getValueOr(QualType())); +} + +unsigned Comment_getNumChildren(const comments::Comment *C) { + if (!C) + return 0; + + return C->child_count(); +} + +comments::Comment *Comment_getChild(const comments::Comment *C, unsigned index) { + if (!C || index >= C->child_count()) + return nullptr; + + return *(C->child_begin() + index); +} + +BindgenStringRef HTMLTagComment_getTagName(const comments::Comment *C) { + if (auto *HTML = dyn_cast_or_null(C)) { + return stringref(HTML->getTagName()); + } else { + return stringref(); + } +} + +unsigned HTMLStartTag_getNumAttrs(const comments::Comment *C) { + if (auto *HTML = dyn_cast_or_null(C)) { + return HTML->getNumAttrs(); + } else { + return 0; + } +} + +BindgenStringRef HTMLStartTag_getAttrName(const comments::Comment *C, unsigned i) { + if (auto *HTML = dyn_cast_or_null(C)) { + return stringref(HTML->getAttr(i).Name); + } else { + return stringref(); + } +} + +BindgenStringRef HTMLStartTag_getAttrValue(const comments::Comment *C, unsigned i) { + if (auto *HTML = dyn_cast_or_null(C)) { + return stringref(HTML->getAttr(i).Value); + } else { + return stringref(); + } +} + +BindgenStringRef FileEntry_getName(const FileEntry *F) { + if (!F) + return stringref(); + return stringref(F->getName()); +} + +BindgenStringRef getClangVersion() { + return stringref(getClangFullVersion()); +} + +bool CXXBaseSpecifier_isVirtualBase(const CXXBaseSpecifier *B) { + return B && B->isVirtual(); +} + +BindgenQualType CXXBaseSpecifier_getType(const CXXBaseSpecifier *B) { + if (!B) + return nullptr; + return make_type_compatible(B->getType()); +} + +BindgenStringRef CXXBaseSpecifier_getSpelling(const CXXBaseSpecifier *B) { + return stringref(B->getType().getAsString()); +} + +SourceLocation *CXXBaseSpecifier_getLocation(const CXXBaseSpecifier *B) { +#if CLANG_VERSION_MAJOR > 4 + return new SourceLocation(B->getBaseTypeLoc()); +#else // CLANG_VERSION_MAJOR <= 4 + return new SourceLocation(B->getLocStart()); +#endif +} + +SourceLocation *Attr_getLocation(const Attr *A) { + return new SourceLocation(A->getLocation()); +} + +SourceLocation *PreprocessedEntity_getLocation(const PreprocessedEntity *PPE) { + return new SourceLocation(PPE->getSourceRange().getBegin()); +} + +BindgenSourceRange CXXBaseSpecifier_getSourceRange(const CXXBaseSpecifier *B) { + return make_sourcerange(B->getSourceRange()); +} + +BindgenSourceRange Attr_getSourceRange(const Attr *A) { + return make_sourcerange(A->getRange()); +} + +BindgenSourceRange PreprocessedEntity_getSourceRange(const PreprocessedEntity *PPE) { + return make_sourcerange(PPE->getSourceRange()); +} + +BindgenStringRef PreprocessedEntity_getSpelling(const PreprocessedEntity *PPE) { + if (!PPE) + return stringref(); + if (const auto *MDR = dyn_cast_or_null(PPE)) + return stringref(MDR->getName()->getName()); + if (const auto *ME = dyn_cast(PPE)) + return stringref(ME->getName()->getName()); + return stringref(); +} + +const FileEntry *PreprocessedEntity_getIncludedFile(const PreprocessedEntity *PPE) { + if (const auto *ID = dyn_cast_or_null(PPE)) + return ID->getFile(); + return nullptr; +} + +CX_CXXAccessSpecifier Decl_getAccess(const Decl *D) { + auto spec = AS_none; + if (D) + spec = D->getAccess(); + return TranslateCXXAccessSpecifier(spec); +} + +CX_CXXAccessSpecifier CXXBaseSpecifier_getAccess(const CXXBaseSpecifier *B) { + auto spec = AS_none; + if (B) + spec = B->getAccessSpecifier(); + return TranslateCXXAccessSpecifier(spec); +} diff --git a/src/clang/clang_interface.hpp b/src/clang/clang_interface.hpp new file mode 100644 index 0000000000..50ce1b9b6c --- /dev/null +++ b/src/clang/clang_interface.hpp @@ -0,0 +1,272 @@ +#ifndef BINDGEN_CLANG_AST_H +#define BINDGEN_CLANG_AST_H + +#include +#include "clang-c/Documentation.h" +#include "clang-c/Index.h" + +namespace clang { +struct ASTUnit; +struct TargetInfo; +struct CompoundStmt; +struct Decl; +struct Diagnostic; +struct StoredDiagnostic; +struct TranslationUnitDecl; +struct Expr; +struct Type; +struct FileEntry; +struct SourceLocation; +struct CXXBaseSpecifier; +struct ASTContext; +struct SourceRange; +struct Attr; +struct PreprocessedEntity; + +namespace comments { +struct Comment; +struct FullComment; +} // namespace comments + +} // namespace clang + +using namespace clang; + +extern "C" { + +struct EvalResult; + +struct BindgenStringRef { + char *s; + size_t len; +}; + +// We export QualTypes back and forth to Rust as opaque pointers because we +// can't pass a C++ class by value. +typedef void* BindgenQualType; + +struct BindgenStringRefSet { + BindgenStringRef *strings; + size_t len; + + // BindgenStringRefSet() : strings(nullptr), len(0) {} +}; + + +struct BindgenSourceRange { + SourceLocation *B; + SourceLocation *E; + + // BindgenSourceRange(const SourceRange &range); + // operator bool() const { + // return B && E; + // } +}; + + + +void deleteString(BindgenStringRef *s); +char *cString(BindgenStringRef *s); + +void deleteStringSet(BindgenStringRefSet *s); + +void deleteSourceLocation(SourceLocation *s); + +void deleteSourceRange(BindgenSourceRange *s); + +void deleteEvalResult(EvalResult *e); + +ASTContext *ASTUnit_getContext(ASTUnit *); +ASTUnit *parseTranslationUnit(const char *source_filename, + const char *const *command_line_args, + int num_command_line_args, unsigned int options, + CXUnsavedFile *unsaved_files, + unsigned num_unsaved_files); +void disposeASTUnit(ASTUnit *AU); +unsigned ASTUnit_getNumDiagnostics(const ASTUnit *AU); +const StoredDiagnostic *ASTUnit_getDiagnostic(const ASTUnit *AU, unsigned i); +const TargetInfo *ASTUnit_getTargetInfo(ASTUnit *AU); + +int TargetInfo_getPointerWidth(const TargetInfo *TI); +BindgenStringRef TargetInfo_getTriple(const TargetInfo *TI); + +EvalResult *Expr_Evaluate(const Expr *E, ASTContext *Ctx); +EvalResult *Decl_Evaluate(const Decl *D, ASTContext *Ctx); +CXEvalResultKind EvalResult_getKind(EvalResult *); +double EvalResult_getAsDouble(EvalResult *); +bool EvalResult_isUnsignedInt(EvalResult *); +unsigned long long EvalResult_getAsUnsigned(EvalResult *); +long long EvalResult_getAsLongLong(EvalResult *); +BindgenStringRef EvalResult_getAsStr(EvalResult *); + +BindgenStringRef Diagnostic_format(const StoredDiagnostic *); +CXDiagnosticSeverity Diagnostic_getSeverity(const StoredDiagnostic *); + +const Decl *getTranslationUnitDecl(ASTUnit *); + +bool CursorKind_isInvalid(CXCursorKind kind); + +const Decl *Decl_getLexicalParent(const Decl *D); +const Decl *Decl_getSemanticParent(const Decl *D); +bool Decl_isDeleted(const Decl *D); +const Decl *Decl_getDefinition(const Decl *D, bool isReference); +const Decl *Decl_getReferenced(const Decl *D); +const Decl *Decl_getCanonical(const Decl *D); +const Decl *Decl_getSpecializedTemplate(const Decl *D); +CXCursorKind Decl_getTemplateCursorKind(const Decl *D); +const Decl *Decl_getArgument(const Decl *D, unsigned i); +int Decl_getNumArguments(const Decl *D); +BindgenStringRef Decl_getUSR(const Decl *D); +BindgenStringRef Decl_getSpelling(const Decl *D); +BindgenStringRef Decl_getDisplayName(const Decl *D); +BindgenStringRef Decl_getMangling(const Decl *D, ASTContext *); +BindgenStringRefSet Decl_getCXXManglings(const Decl *D, ASTContext *); +int Decl_getNumTemplateArguments(const Decl *D); +CXCursorKind Decl_getCXCursorKind(const Decl *D); +bool Decl_isDefinition(const Decl *D); +SourceLocation *Decl_getLocation(const Decl *D); +BindgenStringRef Decl_getRawCommentText(const Decl *D, ASTContext *); +comments::Comment *Decl_getParsedComment(const Decl *D, ASTContext *); +BindgenQualType Decl_getType(const Decl *D, ASTContext *); +bool Decl_isFunctionInlined(const Decl *D); +int Decl_getFieldDeclBitWidth(const Decl *D, ASTContext *); +BindgenQualType Decl_getEnumDeclIntegerType(const Decl *D); +int64_t Decl_getEnumConstantValue(const Decl *D); +uint64_t Decl_getEnumConstantUnsignedValue(const Decl *D); +long long Decl_getOffsetOfField(const Decl *D, ASTContext *); +BindgenSourceRange Decl_getSourceRange(const Decl *D); +BindgenQualType Decl_getTypedefDeclUnderlyingType(const Decl *D); +CXLinkageKind Decl_getLinkage(const Decl *D); +CXVisibilityKind Decl_getVisibility(const Decl *D); +CX_CXXAccessSpecifier Decl_getAccess(const Decl *D); +bool CXXField_isMutable(const Decl *D); +bool CXXMethod_isStatic(const Decl *D); +bool CXXMethod_isConst(const Decl *D); +bool CXXMethod_isVirtual(const Decl *D); +bool CXXMethod_isPureVirtual(const Decl *D); +BindgenQualType Decl_getResultType(const Decl *D, ASTContext *); + + +const Expr *Expr_getArgument(const Expr *E, unsigned i); +// const Decl *Expr_getSemanticParent(const Expr *); +int Expr_getNumArguments(const Expr *E); +BindgenStringRef Expr_getUSR(const Expr *E); +BindgenStringRef Expr_getSpelling(const Expr *E); +BindgenStringRef Expr_getDisplayName(const Expr *E); +BindgenStringRef Expr_getMangling(const Expr *E); +BindgenStringRefSet Expr_getCXXManglings(const Expr *E); +CXCursorKind Expr_getCXCursorKind(const Expr *E); +SourceLocation *Expr_getLocation(const Expr *E); +BindgenStringRef Expr_getRawCommentText(const Expr *E); +comments::FullComment *Expr_getParsedComment(const Expr *E); +BindgenQualType Expr_getType(const Expr *E); +BindgenSourceRange Expr_getSourceRange(const Expr *E); + +const Decl *Type_getDeclaration(BindgenQualType); + +CXCursorKind Attr_getCXCursorKind(const Attr *); + +struct Node { + CXCursorKind kind; + + union { + const Decl *decl; + const Expr *expr; + const CXXBaseSpecifier *base; + const Attr *attr; + const PreprocessedEntity *ppe; + } ptr; + + Node() : kind(CXCursor_NotImplemented) {} + Node(const Decl *decl, CXCursorKind kind) : kind(kind) { + ptr.decl = decl; + } + Node(const Expr *expr, CXCursorKind kind) : kind(kind) { + ptr.expr = expr; + } + Node(const CXXBaseSpecifier *base) : kind(CXCursor_CXXBaseSpecifier) { + ptr.base = base; + } + Node(const Attr *attr) : kind(Attr_getCXCursorKind(attr)) { + ptr.attr = attr; + } + Node(const PreprocessedEntity *ppe, CXCursorKind kind) : kind(kind) { + ptr.ppe = ppe; + } + operator bool() const { + return kind != CXCursor_NotImplemented; + } +}; + +typedef CXChildVisitResult (*Visitor)(Node N, Node parent, + ASTUnit *unit, + CXClientData client_data); + +void Decl_visitChildren(const Decl *Parent, CXCursorKind kind, Visitor V, + ASTUnit *Unit, CXClientData data); +void Expr_visitChildren(const Expr *Parent, CXCursorKind kind, Visitor V, + ASTUnit *Unit, CXClientData data); +void CXXBaseSpecifier_visitChildren(const CXXBaseSpecifier *Parent, + CXCursorKind kind, Visitor V, ASTUnit *Unit, + CXClientData data); + +void tokenize(ASTUnit *TU, BindgenSourceRange Range, CXToken **Tokens, + unsigned *NumTokens); +void disposeTokens(const ASTUnit *TU, CXToken *Tokens, unsigned NumTokens); + +CXTokenKind getTokenKind(CXToken token); +BindgenStringRef getTokenSpelling(ASTUnit *TU, CXToken token); + +CXTypeKind Type_kind(BindgenQualType, ASTContext *); +BindgenStringRef Type_getTypeSpelling(BindgenQualType, ASTContext *); +bool Type_isConstQualifiedType(BindgenQualType); +long long Type_getSizeOf(BindgenQualType, ASTContext *); +long long Type_getAlignOf(BindgenQualType, ASTContext *); +int Type_getNumTemplateArguments(BindgenQualType); +BindgenQualType Type_getArgType(BindgenQualType T, unsigned index); +int Type_getNumArgTypes(BindgenQualType); +BindgenQualType Type_getPointeeType(BindgenQualType); +BindgenQualType Type_getElementType(BindgenQualType); +int Type_getNumElements(BindgenQualType); +BindgenQualType Type_getCanonicalType(BindgenQualType, ASTContext *); +bool Type_isFunctionTypeVariadic(BindgenQualType); +BindgenQualType Type_getResultType(BindgenQualType); +CXCallingConv Type_getFunctionTypeCallingConv(BindgenQualType); +BindgenQualType Type_getNamedType(BindgenQualType); +BindgenQualType Type_getTemplateArgumentAsType(BindgenQualType T, unsigned index); + +void getSpellingLocation(ASTUnit *AST, const SourceLocation *T, FileEntry **file, int *line, int *col, int *off); + +CXCommentKind Comment_getKind(const comments::Comment *); +unsigned Comment_getNumChildren(const comments::Comment *); +comments::Comment *Comment_getChild(const comments::Comment *, unsigned index); +BindgenStringRef HTMLTagComment_getTagName(const comments::Comment *); +unsigned HTMLStartTag_getNumAttrs(const comments::Comment *); +BindgenStringRef HTMLStartTag_getAttrName(const comments::Comment *, unsigned); +BindgenStringRef HTMLStartTag_getAttrValue(const comments::Comment *, unsigned); + +BindgenStringRef CursorKind_getSpelling(CXCursorKind); +BindgenStringRef TypeKind_getSpelling(CXTypeKind); +BindgenStringRef PreprocessedEntity_getSpelling(const PreprocessedEntity *); + +BindgenStringRef FileEntry_getName(const FileEntry *); + +BindgenStringRef getClangVersion(); + +bool CXXBaseSpecifier_isVirtualBase(const CXXBaseSpecifier *); +BindgenQualType CXXBaseSpecifier_getType(const CXXBaseSpecifier *); +BindgenStringRef CXXBaseSpecifier_getSpelling(const CXXBaseSpecifier *); +SourceLocation *CXXBaseSpecifier_getLocation(const CXXBaseSpecifier *); +SourceLocation *Attr_getLocation(const Attr *); +SourceLocation *PreprocessedEntity_getLocation(const PreprocessedEntity *); +const FileEntry *PreprocessedEntity_getIncludedFile(const PreprocessedEntity *); +BindgenSourceRange CXXBaseSpecifier_getSourceRange(const CXXBaseSpecifier *); +CX_CXXAccessSpecifier CXXBaseSpecifier_getAccess(const CXXBaseSpecifier *); +BindgenSourceRange Attr_getSourceRange(const Attr *); +BindgenSourceRange PreprocessedEntity_getSourceRange(const PreprocessedEntity *); + +bool PreprocessedEntity_isFunctionMacroLike(ASTUnit *TU, const PreprocessedEntity *ppe); + +} // extern "C" + +#endif // BINDGEN_CLANG_AST_H diff --git a/src/clang/clang_interface.rs b/src/clang/clang_interface.rs new file mode 100644 index 0000000000..fa9741df1e --- /dev/null +++ b/src/clang/clang_interface.rs @@ -0,0 +1,8469 @@ +/* automatically generated by rust-bindgen 0.60.1 */ + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct __BindgenBitfieldUnit { + storage: Storage, +} +impl __BindgenBitfieldUnit { + #[inline] + pub const fn new(storage: Storage) -> Self { + Self { storage } + } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ + #[inline] + pub fn get_bit(&self, index: usize) -> bool { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = self.storage.as_ref()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + byte & mask == mask + } + #[inline] + pub fn set_bit(&mut self, index: usize, val: bool) { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = &mut self.storage.as_mut()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + if val { + *byte |= mask; + } else { + *byte &= !mask; + } + } + #[inline] + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= + self.storage.as_ref().len() + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if self.get_bit(i + bit_offset) { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] + pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= + self.storage.as_ref().len() + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + self.set_bit(index + bit_offset, val_bit_is_set); + } + } +} +pub const _GLIBCXX_CSTDINT: u32 = 1; +pub const _GLIBCXX_CXX_CONFIG_H: u32 = 1; +pub const _GLIBCXX_RELEASE: u32 = 8; +pub const __GLIBCXX__: u32 = 20190406; +pub const _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY: u32 = 1; +pub const _GLIBCXX_USE_DEPRECATED: u32 = 1; +pub const _GLIBCXX_EXTERN_TEMPLATE: u32 = 1; +pub const _GLIBCXX_USE_DUAL_ABI: u32 = 1; +pub const _GLIBCXX_USE_CXX11_ABI: u32 = 1; +pub const _GLIBCXX_INLINE_VERSION: u32 = 0; +pub const _GLIBCXX_USE_ALLOCATOR_NEW: u32 = 1; +pub const _GLIBCXX_OS_DEFINES: u32 = 1; +pub const __NO_CTYPE: u32 = 1; +pub const _FEATURES_H: u32 = 1; +pub const _ISOC95_SOURCE: u32 = 1; +pub const _ISOC99_SOURCE: u32 = 1; +pub const _ISOC11_SOURCE: u32 = 1; +pub const _POSIX_SOURCE: u32 = 1; +pub const _POSIX_C_SOURCE: u32 = 200809; +pub const _XOPEN_SOURCE: u32 = 700; +pub const _XOPEN_SOURCE_EXTENDED: u32 = 1; +pub const _LARGEFILE64_SOURCE: u32 = 1; +pub const _DEFAULT_SOURCE: u32 = 1; +pub const _ATFILE_SOURCE: u32 = 1; +pub const __USE_ISOC11: u32 = 1; +pub const __USE_ISOC99: u32 = 1; +pub const __USE_ISOC95: u32 = 1; +pub const __USE_ISOCXX11: u32 = 1; +pub const __USE_POSIX: u32 = 1; +pub const __USE_POSIX2: u32 = 1; +pub const __USE_POSIX199309: u32 = 1; +pub const __USE_POSIX199506: u32 = 1; +pub const __USE_XOPEN2K: u32 = 1; +pub const __USE_XOPEN2K8: u32 = 1; +pub const __USE_XOPEN: u32 = 1; +pub const __USE_XOPEN_EXTENDED: u32 = 1; +pub const __USE_UNIX98: u32 = 1; +pub const _LARGEFILE_SOURCE: u32 = 1; +pub const __USE_XOPEN2K8XSI: u32 = 1; +pub const __USE_XOPEN2KXSI: u32 = 1; +pub const __USE_LARGEFILE: u32 = 1; +pub const __USE_LARGEFILE64: u32 = 1; +pub const __USE_MISC: u32 = 1; +pub const __USE_ATFILE: u32 = 1; +pub const __USE_GNU: u32 = 1; +pub const __USE_FORTIFY_LEVEL: u32 = 0; +pub const __GLIBC_USE_DEPRECATED_GETS: u32 = 0; +pub const _STDC_PREDEF_H: u32 = 1; +pub const __STDC_IEC_559__: u32 = 1; +pub const __STDC_IEC_559_COMPLEX__: u32 = 1; +pub const __STDC_ISO_10646__: u32 = 201706; +pub const __GNU_LIBRARY__: u32 = 6; +pub const __GLIBC__: u32 = 2; +pub const __GLIBC_MINOR__: u32 = 28; +pub const _SYS_CDEFS_H: u32 = 1; +pub const __glibc_c99_flexarr_available: u32 = 1; +pub const __WORDSIZE: u32 = 64; +pub const __WORDSIZE_TIME64_COMPAT32: u32 = 1; +pub const __SYSCALL_WORDSIZE: u32 = 64; +pub const __HAVE_GENERIC_SELECTION: u32 = 0; +pub const _GLIBCXX_CPU_DEFINES: u32 = 1; +pub const _GLIBCXX_FAST_MATH: u32 = 0; +pub const _GLIBCXX_USE_FLOAT128: u32 = 1; +pub const _GLIBCXX_HAVE_ACOSF: u32 = 1; +pub const _GLIBCXX_HAVE_ACOSL: u32 = 1; +pub const _GLIBCXX_HAVE_ALIGNED_ALLOC: u32 = 1; +pub const _GLIBCXX_HAVE_ASINF: u32 = 1; +pub const _GLIBCXX_HAVE_ASINL: u32 = 1; +pub const _GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE: u32 = 1; +pub const _GLIBCXX_HAVE_ATAN2F: u32 = 1; +pub const _GLIBCXX_HAVE_ATAN2L: u32 = 1; +pub const _GLIBCXX_HAVE_ATANF: u32 = 1; +pub const _GLIBCXX_HAVE_ATANL: u32 = 1; +pub const _GLIBCXX_HAVE_AT_QUICK_EXIT: u32 = 1; +pub const _GLIBCXX_HAVE_CEILF: u32 = 1; +pub const _GLIBCXX_HAVE_CEILL: u32 = 1; +pub const _GLIBCXX_HAVE_COMPLEX_H: u32 = 1; +pub const _GLIBCXX_HAVE_COSF: u32 = 1; +pub const _GLIBCXX_HAVE_COSHF: u32 = 1; +pub const _GLIBCXX_HAVE_COSHL: u32 = 1; +pub const _GLIBCXX_HAVE_COSL: u32 = 1; +pub const _GLIBCXX_HAVE_DIRENT_H: u32 = 1; +pub const _GLIBCXX_HAVE_DLFCN_H: u32 = 1; +pub const _GLIBCXX_HAVE_EBADMSG: u32 = 1; +pub const _GLIBCXX_HAVE_ECANCELED: u32 = 1; +pub const _GLIBCXX_HAVE_ECHILD: u32 = 1; +pub const _GLIBCXX_HAVE_EIDRM: u32 = 1; +pub const _GLIBCXX_HAVE_ENDIAN_H: u32 = 1; +pub const _GLIBCXX_HAVE_ENODATA: u32 = 1; +pub const _GLIBCXX_HAVE_ENOLINK: u32 = 1; +pub const _GLIBCXX_HAVE_ENOSPC: u32 = 1; +pub const _GLIBCXX_HAVE_ENOSR: u32 = 1; +pub const _GLIBCXX_HAVE_ENOSTR: u32 = 1; +pub const _GLIBCXX_HAVE_ENOTRECOVERABLE: u32 = 1; +pub const _GLIBCXX_HAVE_ENOTSUP: u32 = 1; +pub const _GLIBCXX_HAVE_EOVERFLOW: u32 = 1; +pub const _GLIBCXX_HAVE_EOWNERDEAD: u32 = 1; +pub const _GLIBCXX_HAVE_EPERM: u32 = 1; +pub const _GLIBCXX_HAVE_EPROTO: u32 = 1; +pub const _GLIBCXX_HAVE_ETIME: u32 = 1; +pub const _GLIBCXX_HAVE_ETIMEDOUT: u32 = 1; +pub const _GLIBCXX_HAVE_ETXTBSY: u32 = 1; +pub const _GLIBCXX_HAVE_EWOULDBLOCK: u32 = 1; +pub const _GLIBCXX_HAVE_EXCEPTION_PTR_SINCE_GCC46: u32 = 1; +pub const _GLIBCXX_HAVE_EXECINFO_H: u32 = 1; +pub const _GLIBCXX_HAVE_EXPF: u32 = 1; +pub const _GLIBCXX_HAVE_EXPL: u32 = 1; +pub const _GLIBCXX_HAVE_FABSF: u32 = 1; +pub const _GLIBCXX_HAVE_FABSL: u32 = 1; +pub const _GLIBCXX_HAVE_FCNTL_H: u32 = 1; +pub const _GLIBCXX_HAVE_FENV_H: u32 = 1; +pub const _GLIBCXX_HAVE_FINITE: u32 = 1; +pub const _GLIBCXX_HAVE_FINITEF: u32 = 1; +pub const _GLIBCXX_HAVE_FINITEL: u32 = 1; +pub const _GLIBCXX_HAVE_FLOAT_H: u32 = 1; +pub const _GLIBCXX_HAVE_FLOORF: u32 = 1; +pub const _GLIBCXX_HAVE_FLOORL: u32 = 1; +pub const _GLIBCXX_HAVE_FMODF: u32 = 1; +pub const _GLIBCXX_HAVE_FMODL: u32 = 1; +pub const _GLIBCXX_HAVE_FREXPF: u32 = 1; +pub const _GLIBCXX_HAVE_FREXPL: u32 = 1; +pub const _GLIBCXX_HAVE_GETIPINFO: u32 = 1; +pub const _GLIBCXX_HAVE_GETS: u32 = 1; +pub const _GLIBCXX_HAVE_HYPOT: u32 = 1; +pub const _GLIBCXX_HAVE_HYPOTF: u32 = 1; +pub const _GLIBCXX_HAVE_HYPOTL: u32 = 1; +pub const _GLIBCXX_HAVE_ICONV: u32 = 1; +pub const _GLIBCXX_HAVE_INT64_T: u32 = 1; +pub const _GLIBCXX_HAVE_INT64_T_LONG: u32 = 1; +pub const _GLIBCXX_HAVE_INTTYPES_H: u32 = 1; +pub const _GLIBCXX_HAVE_ISINFF: u32 = 1; +pub const _GLIBCXX_HAVE_ISINFL: u32 = 1; +pub const _GLIBCXX_HAVE_ISNANF: u32 = 1; +pub const _GLIBCXX_HAVE_ISNANL: u32 = 1; +pub const _GLIBCXX_HAVE_ISWBLANK: u32 = 1; +pub const _GLIBCXX_HAVE_LC_MESSAGES: u32 = 1; +pub const _GLIBCXX_HAVE_LDEXPF: u32 = 1; +pub const _GLIBCXX_HAVE_LDEXPL: u32 = 1; +pub const _GLIBCXX_HAVE_LIBINTL_H: u32 = 1; +pub const _GLIBCXX_HAVE_LIMIT_AS: u32 = 1; +pub const _GLIBCXX_HAVE_LIMIT_DATA: u32 = 1; +pub const _GLIBCXX_HAVE_LIMIT_FSIZE: u32 = 1; +pub const _GLIBCXX_HAVE_LIMIT_RSS: u32 = 1; +pub const _GLIBCXX_HAVE_LIMIT_VMEM: u32 = 0; +pub const _GLIBCXX_HAVE_LINUX_FUTEX: u32 = 1; +pub const _GLIBCXX_HAVE_LINUX_RANDOM_H: u32 = 1; +pub const _GLIBCXX_HAVE_LINUX_TYPES_H: u32 = 1; +pub const _GLIBCXX_HAVE_LOCALE_H: u32 = 1; +pub const _GLIBCXX_HAVE_LOG10F: u32 = 1; +pub const _GLIBCXX_HAVE_LOG10L: u32 = 1; +pub const _GLIBCXX_HAVE_LOGF: u32 = 1; +pub const _GLIBCXX_HAVE_LOGL: u32 = 1; +pub const _GLIBCXX_HAVE_MBSTATE_T: u32 = 1; +pub const _GLIBCXX_HAVE_MEMALIGN: u32 = 1; +pub const _GLIBCXX_HAVE_MEMORY_H: u32 = 1; +pub const _GLIBCXX_HAVE_MODF: u32 = 1; +pub const _GLIBCXX_HAVE_MODFF: u32 = 1; +pub const _GLIBCXX_HAVE_MODFL: u32 = 1; +pub const _GLIBCXX_HAVE_POLL: u32 = 1; +pub const _GLIBCXX_HAVE_POSIX_MEMALIGN: u32 = 1; +pub const _GLIBCXX_HAVE_POWF: u32 = 1; +pub const _GLIBCXX_HAVE_POWL: u32 = 1; +pub const _GLIBCXX_HAVE_QUICK_EXIT: u32 = 1; +pub const _GLIBCXX_HAVE_SETENV: u32 = 1; +pub const _GLIBCXX_HAVE_SINCOS: u32 = 1; +pub const _GLIBCXX_HAVE_SINCOSF: u32 = 1; +pub const _GLIBCXX_HAVE_SINCOSL: u32 = 1; +pub const _GLIBCXX_HAVE_SINF: u32 = 1; +pub const _GLIBCXX_HAVE_SINHF: u32 = 1; +pub const _GLIBCXX_HAVE_SINHL: u32 = 1; +pub const _GLIBCXX_HAVE_SINL: u32 = 1; +pub const _GLIBCXX_HAVE_SQRTF: u32 = 1; +pub const _GLIBCXX_HAVE_SQRTL: u32 = 1; +pub const _GLIBCXX_HAVE_STDALIGN_H: u32 = 1; +pub const _GLIBCXX_HAVE_STDBOOL_H: u32 = 1; +pub const _GLIBCXX_HAVE_STDINT_H: u32 = 1; +pub const _GLIBCXX_HAVE_STDLIB_H: u32 = 1; +pub const _GLIBCXX_HAVE_STRERROR_L: u32 = 1; +pub const _GLIBCXX_HAVE_STRERROR_R: u32 = 1; +pub const _GLIBCXX_HAVE_STRINGS_H: u32 = 1; +pub const _GLIBCXX_HAVE_STRING_H: u32 = 1; +pub const _GLIBCXX_HAVE_STRTOF: u32 = 1; +pub const _GLIBCXX_HAVE_STRTOLD: u32 = 1; +pub const _GLIBCXX_HAVE_STRUCT_DIRENT_D_TYPE: u32 = 1; +pub const _GLIBCXX_HAVE_STRXFRM_L: u32 = 1; +pub const _GLIBCXX_HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_IOCTL_H: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_IPC_H: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_PARAM_H: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_RESOURCE_H: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_SDT_H: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_SEM_H: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_STATVFS_H: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_STAT_H: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_SYSINFO_H: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_TIME_H: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_TYPES_H: u32 = 1; +pub const _GLIBCXX_HAVE_SYS_UIO_H: u32 = 1; +pub const _GLIBCXX_HAVE_S_ISREG: u32 = 1; +pub const _GLIBCXX_HAVE_TANF: u32 = 1; +pub const _GLIBCXX_HAVE_TANHF: u32 = 1; +pub const _GLIBCXX_HAVE_TANHL: u32 = 1; +pub const _GLIBCXX_HAVE_TANL: u32 = 1; +pub const _GLIBCXX_HAVE_TGMATH_H: u32 = 1; +pub const _GLIBCXX_HAVE_TLS: u32 = 1; +pub const _GLIBCXX_HAVE_UCHAR_H: u32 = 1; +pub const _GLIBCXX_HAVE_UNISTD_H: u32 = 1; +pub const _GLIBCXX_HAVE_UTIME_H: u32 = 1; +pub const _GLIBCXX_HAVE_VFWSCANF: u32 = 1; +pub const _GLIBCXX_HAVE_VSWSCANF: u32 = 1; +pub const _GLIBCXX_HAVE_VWSCANF: u32 = 1; +pub const _GLIBCXX_HAVE_WCHAR_H: u32 = 1; +pub const _GLIBCXX_HAVE_WCSTOF: u32 = 1; +pub const _GLIBCXX_HAVE_WCTYPE_H: u32 = 1; +pub const _GLIBCXX_HAVE_WRITEV: u32 = 1; +pub const _GLIBCXX_HAVE___CXA_THREAD_ATEXIT_IMPL: u32 = 1; +pub const LT_OBJDIR: &[u8; 7usize] = b".libs/\0"; +pub const _GLIBCXX_PACKAGE_BUGREPORT: &[u8; 1usize] = b"\0"; +pub const _GLIBCXX_PACKAGE_NAME: &[u8; 15usize] = b"package-unused\0"; +pub const _GLIBCXX_PACKAGE_STRING: &[u8; 30usize] = + b"package-unused version-unused\0"; +pub const _GLIBCXX_PACKAGE_TARNAME: &[u8; 10usize] = b"libstdc++\0"; +pub const _GLIBCXX_PACKAGE_URL: &[u8; 1usize] = b"\0"; +pub const _GLIBCXX_PACKAGE__GLIBCXX_VERSION: &[u8; 15usize] = + b"version-unused\0"; +pub const STDC_HEADERS: u32 = 1; +pub const _GLIBCXX11_USE_C99_COMPLEX: u32 = 1; +pub const _GLIBCXX11_USE_C99_MATH: u32 = 1; +pub const _GLIBCXX11_USE_C99_STDIO: u32 = 1; +pub const _GLIBCXX11_USE_C99_STDLIB: u32 = 1; +pub const _GLIBCXX11_USE_C99_WCHAR: u32 = 1; +pub const _GLIBCXX98_USE_C99_COMPLEX: u32 = 1; +pub const _GLIBCXX98_USE_C99_MATH: u32 = 1; +pub const _GLIBCXX98_USE_C99_STDIO: u32 = 1; +pub const _GLIBCXX98_USE_C99_STDLIB: u32 = 1; +pub const _GLIBCXX98_USE_C99_WCHAR: u32 = 1; +pub const _GLIBCXX_ATOMIC_BUILTINS: u32 = 1; +pub const _GLIBCXX_FULLY_DYNAMIC_STRING: u32 = 0; +pub const _GLIBCXX_HAS_GTHREADS: u32 = 1; +pub const _GLIBCXX_HOSTED: u32 = 1; +pub const _GLIBCXX_RES_LIMITS: u32 = 1; +pub const _GLIBCXX_STDIO_EOF: i32 = -1; +pub const _GLIBCXX_STDIO_SEEK_CUR: u32 = 1; +pub const _GLIBCXX_STDIO_SEEK_END: u32 = 2; +pub const _GLIBCXX_SYMVER: u32 = 1; +pub const _GLIBCXX_SYMVER_GNU: u32 = 1; +pub const _GLIBCXX_USE_C11_UCHAR_CXX11: u32 = 1; +pub const _GLIBCXX_USE_C99: u32 = 1; +pub const _GLIBCXX_USE_C99_COMPLEX_TR1: u32 = 1; +pub const _GLIBCXX_USE_C99_CTYPE_TR1: u32 = 1; +pub const _GLIBCXX_USE_C99_FENV_TR1: u32 = 1; +pub const _GLIBCXX_USE_C99_INTTYPES_TR1: u32 = 1; +pub const _GLIBCXX_USE_C99_INTTYPES_WCHAR_T_TR1: u32 = 1; +pub const _GLIBCXX_USE_C99_MATH_TR1: u32 = 1; +pub const _GLIBCXX_USE_C99_STDINT_TR1: u32 = 1; +pub const _GLIBCXX_USE_CLOCK_MONOTONIC: u32 = 1; +pub const _GLIBCXX_USE_CLOCK_REALTIME: u32 = 1; +pub const _GLIBCXX_USE_DECIMAL_FLOAT: u32 = 1; +pub const _GLIBCXX_USE_FCHMOD: u32 = 1; +pub const _GLIBCXX_USE_FCHMODAT: u32 = 1; +pub const _GLIBCXX_USE_GETTIMEOFDAY: u32 = 1; +pub const _GLIBCXX_USE_GET_NPROCS: u32 = 1; +pub const _GLIBCXX_USE_INT128: u32 = 1; +pub const _GLIBCXX_USE_LFS: u32 = 1; +pub const _GLIBCXX_USE_LONG_LONG: u32 = 1; +pub const _GLIBCXX_USE_NANOSLEEP: u32 = 1; +pub const _GLIBCXX_USE_NLS: u32 = 1; +pub const _GLIBCXX_USE_PTHREAD_RWLOCK_T: u32 = 1; +pub const _GLIBCXX_USE_RANDOM_TR1: u32 = 1; +pub const _GLIBCXX_USE_REALPATH: u32 = 1; +pub const _GLIBCXX_USE_SCHED_YIELD: u32 = 1; +pub const _GLIBCXX_USE_SC_NPROCESSORS_ONLN: u32 = 1; +pub const _GLIBCXX_USE_SENDFILE: u32 = 1; +pub const _GLIBCXX_USE_ST_MTIM: u32 = 1; +pub const _GLIBCXX_USE_TMPNAM: u32 = 1; +pub const _GLIBCXX_USE_UTIMENSAT: u32 = 1; +pub const _GLIBCXX_USE_WCHAR_T: u32 = 1; +pub const _GLIBCXX_VERBOSE: u32 = 1; +pub const _GLIBCXX_X86_RDRAND: u32 = 1; +pub const _GTHREAD_USE_MUTEX_TIMEDLOCK: u32 = 1; +pub const _STDINT_H: u32 = 1; +pub const __GLIBC_USE_LIB_EXT2: u32 = 1; +pub const __GLIBC_USE_IEC_60559_BFP_EXT: u32 = 1; +pub const __GLIBC_USE_IEC_60559_FUNCS_EXT: u32 = 1; +pub const __GLIBC_USE_IEC_60559_TYPES_EXT: u32 = 1; +pub const _BITS_TYPES_H: u32 = 1; +pub const _BITS_TYPESIZES_H: u32 = 1; +pub const __OFF_T_MATCHES_OFF64_T: u32 = 1; +pub const __INO_T_MATCHES_INO64_T: u32 = 1; +pub const __RLIM_T_MATCHES_RLIM64_T: u32 = 1; +pub const __FD_SETSIZE: u32 = 1024; +pub const _BITS_WCHAR_H: u32 = 1; +pub const _BITS_STDINT_INTN_H: u32 = 1; +pub const _BITS_STDINT_UINTN_H: u32 = 1; +pub const INT8_MIN: i32 = -128; +pub const INT16_MIN: i32 = -32768; +pub const INT32_MIN: i32 = -2147483648; +pub const INT8_MAX: u32 = 127; +pub const INT16_MAX: u32 = 32767; +pub const INT32_MAX: u32 = 2147483647; +pub const UINT8_MAX: u32 = 255; +pub const UINT16_MAX: u32 = 65535; +pub const UINT32_MAX: u32 = 4294967295; +pub const INT_LEAST8_MIN: i32 = -128; +pub const INT_LEAST16_MIN: i32 = -32768; +pub const INT_LEAST32_MIN: i32 = -2147483648; +pub const INT_LEAST8_MAX: u32 = 127; +pub const INT_LEAST16_MAX: u32 = 32767; +pub const INT_LEAST32_MAX: u32 = 2147483647; +pub const UINT_LEAST8_MAX: u32 = 255; +pub const UINT_LEAST16_MAX: u32 = 65535; +pub const UINT_LEAST32_MAX: u32 = 4294967295; +pub const INT_FAST8_MIN: i32 = -128; +pub const INT_FAST16_MIN: i64 = -9223372036854775808; +pub const INT_FAST32_MIN: i64 = -9223372036854775808; +pub const INT_FAST8_MAX: u32 = 127; +pub const INT_FAST16_MAX: u64 = 9223372036854775807; +pub const INT_FAST32_MAX: u64 = 9223372036854775807; +pub const UINT_FAST8_MAX: u32 = 255; +pub const UINT_FAST16_MAX: i32 = -1; +pub const UINT_FAST32_MAX: i32 = -1; +pub const INTPTR_MIN: i64 = -9223372036854775808; +pub const INTPTR_MAX: u64 = 9223372036854775807; +pub const UINTPTR_MAX: i32 = -1; +pub const PTRDIFF_MIN: i64 = -9223372036854775808; +pub const PTRDIFF_MAX: u64 = 9223372036854775807; +pub const SIG_ATOMIC_MIN: i32 = -2147483648; +pub const SIG_ATOMIC_MAX: u32 = 2147483647; +pub const SIZE_MAX: i32 = -1; +pub const WINT_MIN: u32 = 0; +pub const WINT_MAX: u32 = 4294967295; +pub const INT8_WIDTH: u32 = 8; +pub const UINT8_WIDTH: u32 = 8; +pub const INT16_WIDTH: u32 = 16; +pub const UINT16_WIDTH: u32 = 16; +pub const INT32_WIDTH: u32 = 32; +pub const UINT32_WIDTH: u32 = 32; +pub const INT64_WIDTH: u32 = 64; +pub const UINT64_WIDTH: u32 = 64; +pub const INT_LEAST8_WIDTH: u32 = 8; +pub const UINT_LEAST8_WIDTH: u32 = 8; +pub const INT_LEAST16_WIDTH: u32 = 16; +pub const UINT_LEAST16_WIDTH: u32 = 16; +pub const INT_LEAST32_WIDTH: u32 = 32; +pub const UINT_LEAST32_WIDTH: u32 = 32; +pub const INT_LEAST64_WIDTH: u32 = 64; +pub const UINT_LEAST64_WIDTH: u32 = 64; +pub const INT_FAST8_WIDTH: u32 = 8; +pub const UINT_FAST8_WIDTH: u32 = 8; +pub const INT_FAST16_WIDTH: u32 = 64; +pub const UINT_FAST16_WIDTH: u32 = 64; +pub const INT_FAST32_WIDTH: u32 = 64; +pub const UINT_FAST32_WIDTH: u32 = 64; +pub const INT_FAST64_WIDTH: u32 = 64; +pub const UINT_FAST64_WIDTH: u32 = 64; +pub const INTPTR_WIDTH: u32 = 64; +pub const UINTPTR_WIDTH: u32 = 64; +pub const INTMAX_WIDTH: u32 = 64; +pub const UINTMAX_WIDTH: u32 = 64; +pub const PTRDIFF_WIDTH: u32 = 64; +pub const SIG_ATOMIC_WIDTH: u32 = 32; +pub const SIZE_WIDTH: u32 = 64; +pub const WCHAR_WIDTH: u32 = 32; +pub const WINT_WIDTH: u32 = 32; +pub const _TIME_H: u32 = 1; +pub const _BITS_TIME_H: u32 = 1; +pub const CLOCK_REALTIME: u32 = 0; +pub const CLOCK_MONOTONIC: u32 = 1; +pub const CLOCK_PROCESS_CPUTIME_ID: u32 = 2; +pub const CLOCK_THREAD_CPUTIME_ID: u32 = 3; +pub const CLOCK_MONOTONIC_RAW: u32 = 4; +pub const CLOCK_REALTIME_COARSE: u32 = 5; +pub const CLOCK_MONOTONIC_COARSE: u32 = 6; +pub const CLOCK_BOOTTIME: u32 = 7; +pub const CLOCK_REALTIME_ALARM: u32 = 8; +pub const CLOCK_BOOTTIME_ALARM: u32 = 9; +pub const CLOCK_TAI: u32 = 11; +pub const TIMER_ABSTIME: u32 = 1; +pub const _BITS_TIMEX_H: u32 = 1; +pub const __timeval_defined: u32 = 1; +pub const ADJ_OFFSET: u32 = 1; +pub const ADJ_FREQUENCY: u32 = 2; +pub const ADJ_MAXERROR: u32 = 4; +pub const ADJ_ESTERROR: u32 = 8; +pub const ADJ_STATUS: u32 = 16; +pub const ADJ_TIMECONST: u32 = 32; +pub const ADJ_TAI: u32 = 128; +pub const ADJ_SETOFFSET: u32 = 256; +pub const ADJ_MICRO: u32 = 4096; +pub const ADJ_NANO: u32 = 8192; +pub const ADJ_TICK: u32 = 16384; +pub const ADJ_OFFSET_SINGLESHOT: u32 = 32769; +pub const ADJ_OFFSET_SS_READ: u32 = 40961; +pub const MOD_OFFSET: u32 = 1; +pub const MOD_FREQUENCY: u32 = 2; +pub const MOD_MAXERROR: u32 = 4; +pub const MOD_ESTERROR: u32 = 8; +pub const MOD_STATUS: u32 = 16; +pub const MOD_TIMECONST: u32 = 32; +pub const MOD_CLKB: u32 = 16384; +pub const MOD_CLKA: u32 = 32769; +pub const MOD_TAI: u32 = 128; +pub const MOD_MICRO: u32 = 4096; +pub const MOD_NANO: u32 = 8192; +pub const STA_PLL: u32 = 1; +pub const STA_PPSFREQ: u32 = 2; +pub const STA_PPSTIME: u32 = 4; +pub const STA_FLL: u32 = 8; +pub const STA_INS: u32 = 16; +pub const STA_DEL: u32 = 32; +pub const STA_UNSYNC: u32 = 64; +pub const STA_FREQHOLD: u32 = 128; +pub const STA_PPSSIGNAL: u32 = 256; +pub const STA_PPSJITTER: u32 = 512; +pub const STA_PPSWANDER: u32 = 1024; +pub const STA_PPSERROR: u32 = 2048; +pub const STA_CLOCKERR: u32 = 4096; +pub const STA_NANO: u32 = 8192; +pub const STA_MODE: u32 = 16384; +pub const STA_CLK: u32 = 32768; +pub const STA_RONLY: u32 = 65280; +pub const __clock_t_defined: u32 = 1; +pub const __time_t_defined: u32 = 1; +pub const __struct_tm_defined: u32 = 1; +pub const _STRUCT_TIMESPEC: u32 = 1; +pub const __clockid_t_defined: u32 = 1; +pub const __timer_t_defined: u32 = 1; +pub const __itimerspec_defined: u32 = 1; +pub const _BITS_TYPES_LOCALE_T_H: u32 = 1; +pub const _BITS_TYPES___LOCALE_T_H: u32 = 1; +pub const TIME_UTC: u32 = 1; +pub const CINDEX_VERSION_MAJOR: u32 = 0; +pub const CINDEX_VERSION_MINOR: u32 = 62; +pub type std_size_t = ::std::os::raw::c_ulong; +pub type std_nullptr_t = *const ::std::os::raw::c_void; +pub type __u_char = ::std::os::raw::c_uchar; +pub type __u_short = ::std::os::raw::c_ushort; +pub type __u_int = ::std::os::raw::c_uint; +pub type __u_long = ::std::os::raw::c_ulong; +pub type __int8_t = ::std::os::raw::c_schar; +pub type __uint8_t = ::std::os::raw::c_uchar; +pub type __int16_t = ::std::os::raw::c_short; +pub type __uint16_t = ::std::os::raw::c_ushort; +pub type __int32_t = ::std::os::raw::c_int; +pub type __uint32_t = ::std::os::raw::c_uint; +pub type __int64_t = ::std::os::raw::c_long; +pub type __uint64_t = ::std::os::raw::c_ulong; +pub type __int_least8_t = __int8_t; +pub type __uint_least8_t = __uint8_t; +pub type __int_least16_t = __int16_t; +pub type __uint_least16_t = __uint16_t; +pub type __int_least32_t = __int32_t; +pub type __uint_least32_t = __uint32_t; +pub type __int_least64_t = __int64_t; +pub type __uint_least64_t = __uint64_t; +pub type __quad_t = ::std::os::raw::c_long; +pub type __u_quad_t = ::std::os::raw::c_ulong; +pub type __intmax_t = ::std::os::raw::c_long; +pub type __uintmax_t = ::std::os::raw::c_ulong; +pub type __dev_t = ::std::os::raw::c_ulong; +pub type __uid_t = ::std::os::raw::c_uint; +pub type __gid_t = ::std::os::raw::c_uint; +pub type __ino_t = ::std::os::raw::c_ulong; +pub type __ino64_t = ::std::os::raw::c_ulong; +pub type __mode_t = ::std::os::raw::c_uint; +pub type __nlink_t = ::std::os::raw::c_ulong; +pub type __off_t = ::std::os::raw::c_long; +pub type __off64_t = ::std::os::raw::c_long; +pub type __pid_t = ::std::os::raw::c_int; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __fsid_t { + pub __val: [::std::os::raw::c_int; 2usize], +} +#[test] +fn bindgen_test_layout___fsid_t() { + assert_eq!( + ::std::mem::size_of::<__fsid_t>(), + 8usize, + concat!("Size of: ", stringify!(__fsid_t)) + ); + assert_eq!( + ::std::mem::align_of::<__fsid_t>(), + 4usize, + concat!("Alignment of ", stringify!(__fsid_t)) + ); + fn test_field___val() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::<__fsid_t>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__val) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__fsid_t), + "::", + stringify!(__val) + ) + ); + } + test_field___val(); +} +pub type __clock_t = ::std::os::raw::c_long; +pub type __rlim_t = ::std::os::raw::c_ulong; +pub type __rlim64_t = ::std::os::raw::c_ulong; +pub type __id_t = ::std::os::raw::c_uint; +pub type __time_t = ::std::os::raw::c_long; +pub type __useconds_t = ::std::os::raw::c_uint; +pub type __suseconds_t = ::std::os::raw::c_long; +pub type __daddr_t = ::std::os::raw::c_int; +pub type __key_t = ::std::os::raw::c_int; +pub type __clockid_t = ::std::os::raw::c_int; +pub type __timer_t = *mut ::std::os::raw::c_void; +pub type __blksize_t = ::std::os::raw::c_long; +pub type __blkcnt_t = ::std::os::raw::c_long; +pub type __blkcnt64_t = ::std::os::raw::c_long; +pub type __fsblkcnt_t = ::std::os::raw::c_ulong; +pub type __fsblkcnt64_t = ::std::os::raw::c_ulong; +pub type __fsfilcnt_t = ::std::os::raw::c_ulong; +pub type __fsfilcnt64_t = ::std::os::raw::c_ulong; +pub type __fsword_t = ::std::os::raw::c_long; +pub type __ssize_t = ::std::os::raw::c_long; +pub type __syscall_slong_t = ::std::os::raw::c_long; +pub type __syscall_ulong_t = ::std::os::raw::c_ulong; +pub type __loff_t = __off64_t; +pub type __caddr_t = *mut ::std::os::raw::c_char; +pub type __intptr_t = ::std::os::raw::c_long; +pub type __socklen_t = ::std::os::raw::c_uint; +pub type __sig_atomic_t = ::std::os::raw::c_int; +pub type int_least8_t = __int_least8_t; +pub type int_least16_t = __int_least16_t; +pub type int_least32_t = __int_least32_t; +pub type int_least64_t = __int_least64_t; +pub type uint_least8_t = __uint_least8_t; +pub type uint_least16_t = __uint_least16_t; +pub type uint_least32_t = __uint_least32_t; +pub type uint_least64_t = __uint_least64_t; +pub type int_fast8_t = ::std::os::raw::c_schar; +pub type int_fast16_t = ::std::os::raw::c_long; +pub type int_fast32_t = ::std::os::raw::c_long; +pub type int_fast64_t = ::std::os::raw::c_long; +pub type uint_fast8_t = ::std::os::raw::c_uchar; +pub type uint_fast16_t = ::std::os::raw::c_ulong; +pub type uint_fast32_t = ::std::os::raw::c_ulong; +pub type uint_fast64_t = ::std::os::raw::c_ulong; +pub type intmax_t = __intmax_t; +pub type uintmax_t = __uintmax_t; +pub type size_t = ::std::os::raw::c_ulong; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct timeval { + pub tv_sec: __time_t, + pub tv_usec: __suseconds_t, +} +#[test] +fn bindgen_test_layout_timeval() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(timeval)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(timeval)) + ); + fn test_field_tv_sec() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tv_sec) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timeval), + "::", + stringify!(tv_sec) + ) + ); + } + test_field_tv_sec(); + fn test_field_tv_usec() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tv_usec) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(timeval), + "::", + stringify!(tv_usec) + ) + ); + } + test_field_tv_usec(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct timex { + pub modes: ::std::os::raw::c_uint, + pub offset: __syscall_slong_t, + pub freq: __syscall_slong_t, + pub maxerror: __syscall_slong_t, + pub esterror: __syscall_slong_t, + pub status: ::std::os::raw::c_int, + pub constant: __syscall_slong_t, + pub precision: __syscall_slong_t, + pub tolerance: __syscall_slong_t, + pub time: timeval, + pub tick: __syscall_slong_t, + pub ppsfreq: __syscall_slong_t, + pub jitter: __syscall_slong_t, + pub shift: ::std::os::raw::c_int, + pub stabil: __syscall_slong_t, + pub jitcnt: __syscall_slong_t, + pub calcnt: __syscall_slong_t, + pub errcnt: __syscall_slong_t, + pub stbcnt: __syscall_slong_t, + pub tai: ::std::os::raw::c_int, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize]>, +} +#[test] +fn bindgen_test_layout_timex() { + assert_eq!( + ::std::mem::size_of::(), + 208usize, + concat!("Size of: ", stringify!(timex)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(timex)) + ); + fn test_field_modes() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).modes) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(modes) + ) + ); + } + test_field_modes(); + fn test_field_offset() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(offset) + ) + ); + } + test_field_offset(); + fn test_field_freq() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).freq) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(freq) + ) + ); + } + test_field_freq(); + fn test_field_maxerror() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).maxerror) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(maxerror) + ) + ); + } + test_field_maxerror(); + fn test_field_esterror() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).esterror) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(esterror) + ) + ); + } + test_field_esterror(); + fn test_field_status() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(status) + ) + ); + } + test_field_status(); + fn test_field_constant() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).constant) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(constant) + ) + ); + } + test_field_constant(); + fn test_field_precision() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).precision) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(precision) + ) + ); + } + test_field_precision(); + fn test_field_tolerance() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tolerance) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(tolerance) + ) + ); + } + test_field_tolerance(); + fn test_field_time() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(time) + ) + ); + } + test_field_time(); + fn test_field_tick() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tick) as usize - ptr as usize + }, + 88usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(tick) + ) + ); + } + test_field_tick(); + fn test_field_ppsfreq() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ppsfreq) as usize - ptr as usize + }, + 96usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(ppsfreq) + ) + ); + } + test_field_ppsfreq(); + fn test_field_jitter() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).jitter) as usize - ptr as usize + }, + 104usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(jitter) + ) + ); + } + test_field_jitter(); + fn test_field_shift() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).shift) as usize - ptr as usize + }, + 112usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(shift) + ) + ); + } + test_field_shift(); + fn test_field_stabil() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).stabil) as usize - ptr as usize + }, + 120usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(stabil) + ) + ); + } + test_field_stabil(); + fn test_field_jitcnt() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).jitcnt) as usize - ptr as usize + }, + 128usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(jitcnt) + ) + ); + } + test_field_jitcnt(); + fn test_field_calcnt() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).calcnt) as usize - ptr as usize + }, + 136usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(calcnt) + ) + ); + } + test_field_calcnt(); + fn test_field_errcnt() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).errcnt) as usize - ptr as usize + }, + 144usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(errcnt) + ) + ); + } + test_field_errcnt(); + fn test_field_stbcnt() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).stbcnt) as usize - ptr as usize + }, + 152usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(stbcnt) + ) + ); + } + test_field_stbcnt(); + fn test_field_tai() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize + }, + 160usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(tai) + ) + ); + } + test_field_tai(); +} +extern "C" { + pub fn clock_adjtime( + __clock_id: __clockid_t, + __utx: *mut timex, + ) -> ::std::os::raw::c_int; +} +pub type clock_t = __clock_t; +pub type time_t = __time_t; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct tm { + pub tm_sec: ::std::os::raw::c_int, + pub tm_min: ::std::os::raw::c_int, + pub tm_hour: ::std::os::raw::c_int, + pub tm_mday: ::std::os::raw::c_int, + pub tm_mon: ::std::os::raw::c_int, + pub tm_year: ::std::os::raw::c_int, + pub tm_wday: ::std::os::raw::c_int, + pub tm_yday: ::std::os::raw::c_int, + pub tm_isdst: ::std::os::raw::c_int, + pub tm_gmtoff: ::std::os::raw::c_long, + pub tm_zone: *const ::std::os::raw::c_char, +} +#[test] +fn bindgen_test_layout_tm() { + assert_eq!( + ::std::mem::size_of::(), + 56usize, + concat!("Size of: ", stringify!(tm)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(tm)) + ); + fn test_field_tm_sec() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tm_sec) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_sec) + ) + ); + } + test_field_tm_sec(); + fn test_field_tm_min() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tm_min) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_min) + ) + ); + } + test_field_tm_min(); + fn test_field_tm_hour() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tm_hour) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_hour) + ) + ); + } + test_field_tm_hour(); + fn test_field_tm_mday() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tm_mday) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_mday) + ) + ); + } + test_field_tm_mday(); + fn test_field_tm_mon() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tm_mon) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_mon) + ) + ); + } + test_field_tm_mon(); + fn test_field_tm_year() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tm_year) as usize - ptr as usize + }, + 20usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_year) + ) + ); + } + test_field_tm_year(); + fn test_field_tm_wday() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tm_wday) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_wday) + ) + ); + } + test_field_tm_wday(); + fn test_field_tm_yday() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tm_yday) as usize - ptr as usize + }, + 28usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_yday) + ) + ); + } + test_field_tm_yday(); + fn test_field_tm_isdst() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tm_isdst) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_isdst) + ) + ); + } + test_field_tm_isdst(); + fn test_field_tm_gmtoff() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tm_gmtoff) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_gmtoff) + ) + ); + } + test_field_tm_gmtoff(); + fn test_field_tm_zone() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tm_zone) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_zone) + ) + ); + } + test_field_tm_zone(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct timespec { + pub tv_sec: __time_t, + pub tv_nsec: __syscall_slong_t, +} +#[test] +fn bindgen_test_layout_timespec() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(timespec)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(timespec)) + ); + fn test_field_tv_sec() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tv_sec) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timespec), + "::", + stringify!(tv_sec) + ) + ); + } + test_field_tv_sec(); + fn test_field_tv_nsec() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tv_nsec) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(timespec), + "::", + stringify!(tv_nsec) + ) + ); + } + test_field_tv_nsec(); +} +pub type clockid_t = __clockid_t; +pub type timer_t = __timer_t; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct itimerspec { + pub it_interval: timespec, + pub it_value: timespec, +} +#[test] +fn bindgen_test_layout_itimerspec() { + assert_eq!( + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(itimerspec)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(itimerspec)) + ); + fn test_field_it_interval() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).it_interval) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(itimerspec), + "::", + stringify!(it_interval) + ) + ); + } + test_field_it_interval(); + fn test_field_it_value() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).it_value) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(itimerspec), + "::", + stringify!(it_value) + ) + ); + } + test_field_it_value(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sigevent { + _unused: [u8; 0], +} +pub type pid_t = __pid_t; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __locale_struct { + pub __locales: [*mut __locale_data; 13usize], + pub __ctype_b: *const ::std::os::raw::c_ushort, + pub __ctype_tolower: *const ::std::os::raw::c_int, + pub __ctype_toupper: *const ::std::os::raw::c_int, + pub __names: [*const ::std::os::raw::c_char; 13usize], +} +#[test] +fn bindgen_test_layout___locale_struct() { + assert_eq!( + ::std::mem::size_of::<__locale_struct>(), + 232usize, + concat!("Size of: ", stringify!(__locale_struct)) + ); + assert_eq!( + ::std::mem::align_of::<__locale_struct>(), + 8usize, + concat!("Alignment of ", stringify!(__locale_struct)) + ); + fn test_field___locales() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::<__locale_struct>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__locales) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__locale_struct), + "::", + stringify!(__locales) + ) + ); + } + test_field___locales(); + fn test_field___ctype_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::<__locale_struct>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__ctype_b) as usize - ptr as usize + }, + 104usize, + concat!( + "Offset of field: ", + stringify!(__locale_struct), + "::", + stringify!(__ctype_b) + ) + ); + } + test_field___ctype_b(); + fn test_field___ctype_tolower() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::<__locale_struct>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__ctype_tolower) as usize - + ptr as usize + }, + 112usize, + concat!( + "Offset of field: ", + stringify!(__locale_struct), + "::", + stringify!(__ctype_tolower) + ) + ); + } + test_field___ctype_tolower(); + fn test_field___ctype_toupper() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::<__locale_struct>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__ctype_toupper) as usize - + ptr as usize + }, + 120usize, + concat!( + "Offset of field: ", + stringify!(__locale_struct), + "::", + stringify!(__ctype_toupper) + ) + ); + } + test_field___ctype_toupper(); + fn test_field___names() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::<__locale_struct>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__names) as usize - ptr as usize + }, + 128usize, + concat!( + "Offset of field: ", + stringify!(__locale_struct), + "::", + stringify!(__names) + ) + ); + } + test_field___names(); +} +pub type __locale_t = *mut __locale_struct; +pub type locale_t = __locale_t; +extern "C" { + pub fn clock() -> clock_t; +} +extern "C" { + pub fn time(__timer: *mut time_t) -> time_t; +} +extern "C" { + pub fn difftime(__time1: time_t, __time0: time_t) -> f64; +} +extern "C" { + pub fn mktime(__tp: *mut tm) -> time_t; +} +extern "C" { + pub fn strftime( + __s: *mut ::std::os::raw::c_char, + __maxsize: size_t, + __format: *const ::std::os::raw::c_char, + __tp: *const tm, + ) -> size_t; +} +extern "C" { + pub fn strptime( + __s: *const ::std::os::raw::c_char, + __fmt: *const ::std::os::raw::c_char, + __tp: *mut tm, + ) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn strftime_l( + __s: *mut ::std::os::raw::c_char, + __maxsize: size_t, + __format: *const ::std::os::raw::c_char, + __tp: *const tm, + __loc: locale_t, + ) -> size_t; +} +extern "C" { + pub fn strptime_l( + __s: *const ::std::os::raw::c_char, + __fmt: *const ::std::os::raw::c_char, + __tp: *mut tm, + __loc: locale_t, + ) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn gmtime(__timer: *const time_t) -> *mut tm; +} +extern "C" { + pub fn localtime(__timer: *const time_t) -> *mut tm; +} +extern "C" { + pub fn gmtime_r(__timer: *const time_t, __tp: *mut tm) -> *mut tm; +} +extern "C" { + pub fn localtime_r(__timer: *const time_t, __tp: *mut tm) -> *mut tm; +} +extern "C" { + pub fn asctime(__tp: *const tm) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn ctime(__timer: *const time_t) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn asctime_r( + __tp: *const tm, + __buf: *mut ::std::os::raw::c_char, + ) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn ctime_r( + __timer: *const time_t, + __buf: *mut ::std::os::raw::c_char, + ) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub static mut __tzname: [*mut ::std::os::raw::c_char; 2usize]; +} +extern "C" { + pub static mut __daylight: ::std::os::raw::c_int; +} +extern "C" { + pub static mut __timezone: ::std::os::raw::c_long; +} +extern "C" { + pub static mut tzname: [*mut ::std::os::raw::c_char; 2usize]; +} +extern "C" { + pub fn tzset(); +} +extern "C" { + pub static mut daylight: ::std::os::raw::c_int; +} +extern "C" { + pub static mut timezone: ::std::os::raw::c_long; +} +extern "C" { + pub fn stime(__when: *const time_t) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn timegm(__tp: *mut tm) -> time_t; +} +extern "C" { + pub fn timelocal(__tp: *mut tm) -> time_t; +} +extern "C" { + pub fn dysize(__year: ::std::os::raw::c_int) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn nanosleep( + __requested_time: *const timespec, + __remaining: *mut timespec, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clock_getres( + __clock_id: clockid_t, + __res: *mut timespec, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clock_gettime( + __clock_id: clockid_t, + __tp: *mut timespec, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clock_settime( + __clock_id: clockid_t, + __tp: *const timespec, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clock_nanosleep( + __clock_id: clockid_t, + __flags: ::std::os::raw::c_int, + __req: *const timespec, + __rem: *mut timespec, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clock_getcpuclockid( + __pid: pid_t, + __clock_id: *mut clockid_t, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn timer_create( + __clock_id: clockid_t, + __evp: *mut sigevent, + __timerid: *mut timer_t, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn timer_delete(__timerid: timer_t) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn timer_settime( + __timerid: timer_t, + __flags: ::std::os::raw::c_int, + __value: *const itimerspec, + __ovalue: *mut itimerspec, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn timer_gettime( + __timerid: timer_t, + __value: *mut itimerspec, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn timer_getoverrun(__timerid: timer_t) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn timespec_get( + __ts: *mut timespec, + __base: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub static mut getdate_err: ::std::os::raw::c_int; +} +extern "C" { + pub fn getdate(__string: *const ::std::os::raw::c_char) -> *mut tm; +} +extern "C" { + pub fn getdate_r( + __string: *const ::std::os::raw::c_char, + __resbufp: *mut tm, + ) -> ::std::os::raw::c_int; +} +pub mod CXErrorCode { + pub type Type = u32; + pub const CXError_Success: Type = 0; + pub const CXError_Failure: Type = 1; + pub const CXError_Crashed: Type = 2; + pub const CXError_InvalidArguments: Type = 3; + pub const CXError_ASTReadError: Type = 4; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXString { + pub data: *const ::std::os::raw::c_void, + pub private_flags: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_CXString() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(CXString)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXString)) + ); + fn test_field_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXString), + "::", + stringify!(data) + ) + ); + } + test_field_data(); + fn test_field_private_flags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).private_flags) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXString), + "::", + stringify!(private_flags) + ) + ); + } + test_field_private_flags(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXStringSet { + pub Strings: *mut CXString, + pub Count: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_CXStringSet() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(CXStringSet)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXStringSet)) + ); + fn test_field_Strings() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Strings) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXStringSet), + "::", + stringify!(Strings) + ) + ); + } + test_field_Strings(); + fn test_field_Count() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Count) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXStringSet), + "::", + stringify!(Count) + ) + ); + } + test_field_Count(); +} +extern "C" { + pub fn clang_getCString(string: CXString) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn clang_disposeString(string: CXString); +} +extern "C" { + pub fn clang_disposeStringSet(set: *mut CXStringSet); +} +extern "C" { + pub fn clang_getBuildSessionTimestamp() -> ::std::os::raw::c_ulonglong; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXVirtualFileOverlayImpl { + _unused: [u8; 0], +} +pub type CXVirtualFileOverlay = *mut CXVirtualFileOverlayImpl; +extern "C" { + pub fn clang_VirtualFileOverlay_create( + options: ::std::os::raw::c_uint, + ) -> CXVirtualFileOverlay; +} +extern "C" { + pub fn clang_VirtualFileOverlay_addFileMapping( + arg1: CXVirtualFileOverlay, + virtualPath: *const ::std::os::raw::c_char, + realPath: *const ::std::os::raw::c_char, + ) -> CXErrorCode::Type; +} +extern "C" { + pub fn clang_VirtualFileOverlay_setCaseSensitivity( + arg1: CXVirtualFileOverlay, + caseSensitive: ::std::os::raw::c_int, + ) -> CXErrorCode::Type; +} +extern "C" { + pub fn clang_VirtualFileOverlay_writeToBuffer( + arg1: CXVirtualFileOverlay, + options: ::std::os::raw::c_uint, + out_buffer_ptr: *mut *mut ::std::os::raw::c_char, + out_buffer_size: *mut ::std::os::raw::c_uint, + ) -> CXErrorCode::Type; +} +extern "C" { + pub fn clang_free(buffer: *mut ::std::os::raw::c_void); +} +extern "C" { + pub fn clang_VirtualFileOverlay_dispose(arg1: CXVirtualFileOverlay); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXModuleMapDescriptorImpl { + _unused: [u8; 0], +} +pub type CXModuleMapDescriptor = *mut CXModuleMapDescriptorImpl; +extern "C" { + pub fn clang_ModuleMapDescriptor_create( + options: ::std::os::raw::c_uint, + ) -> CXModuleMapDescriptor; +} +extern "C" { + pub fn clang_ModuleMapDescriptor_setFrameworkModuleName( + arg1: CXModuleMapDescriptor, + name: *const ::std::os::raw::c_char, + ) -> CXErrorCode::Type; +} +extern "C" { + pub fn clang_ModuleMapDescriptor_setUmbrellaHeader( + arg1: CXModuleMapDescriptor, + name: *const ::std::os::raw::c_char, + ) -> CXErrorCode::Type; +} +extern "C" { + pub fn clang_ModuleMapDescriptor_writeToBuffer( + arg1: CXModuleMapDescriptor, + options: ::std::os::raw::c_uint, + out_buffer_ptr: *mut *mut ::std::os::raw::c_char, + out_buffer_size: *mut ::std::os::raw::c_uint, + ) -> CXErrorCode::Type; +} +extern "C" { + pub fn clang_ModuleMapDescriptor_dispose(arg1: CXModuleMapDescriptor); +} +pub type CXIndex = *mut ::std::os::raw::c_void; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXTargetInfoImpl { + _unused: [u8; 0], +} +pub type CXTargetInfo = *mut CXTargetInfoImpl; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXTranslationUnitImpl { + _unused: [u8; 0], +} +pub type CXTranslationUnit = *mut CXTranslationUnitImpl; +pub type CXClientData = *mut ::std::os::raw::c_void; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXUnsavedFile { + pub Filename: *const ::std::os::raw::c_char, + pub Contents: *const ::std::os::raw::c_char, + pub Length: ::std::os::raw::c_ulong, +} +#[test] +fn bindgen_test_layout_CXUnsavedFile() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(CXUnsavedFile)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXUnsavedFile)) + ); + fn test_field_Filename() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Filename) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXUnsavedFile), + "::", + stringify!(Filename) + ) + ); + } + test_field_Filename(); + fn test_field_Contents() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Contents) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXUnsavedFile), + "::", + stringify!(Contents) + ) + ); + } + test_field_Contents(); + fn test_field_Length() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Length) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXUnsavedFile), + "::", + stringify!(Length) + ) + ); + } + test_field_Length(); +} +pub mod CXAvailabilityKind { + pub type Type = u32; + pub const CXAvailability_Available: Type = 0; + pub const CXAvailability_Deprecated: Type = 1; + pub const CXAvailability_NotAvailable: Type = 2; + pub const CXAvailability_NotAccessible: Type = 3; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXVersion { + pub Major: ::std::os::raw::c_int, + pub Minor: ::std::os::raw::c_int, + pub Subminor: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_CXVersion() { + assert_eq!( + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(CXVersion)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(CXVersion)) + ); + fn test_field_Major() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Major) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXVersion), + "::", + stringify!(Major) + ) + ); + } + test_field_Major(); + fn test_field_Minor() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Minor) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(CXVersion), + "::", + stringify!(Minor) + ) + ); + } + test_field_Minor(); + fn test_field_Subminor() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Subminor) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXVersion), + "::", + stringify!(Subminor) + ) + ); + } + test_field_Subminor(); +} +pub mod CXCursor_ExceptionSpecificationKind { + pub type Type = u32; + pub const CXCursor_ExceptionSpecificationKind_None: Type = 0; + pub const CXCursor_ExceptionSpecificationKind_DynamicNone: Type = 1; + pub const CXCursor_ExceptionSpecificationKind_Dynamic: Type = 2; + pub const CXCursor_ExceptionSpecificationKind_MSAny: Type = 3; + pub const CXCursor_ExceptionSpecificationKind_BasicNoexcept: Type = 4; + pub const CXCursor_ExceptionSpecificationKind_ComputedNoexcept: Type = 5; + pub const CXCursor_ExceptionSpecificationKind_Unevaluated: Type = 6; + pub const CXCursor_ExceptionSpecificationKind_Uninstantiated: Type = 7; + pub const CXCursor_ExceptionSpecificationKind_Unparsed: Type = 8; + pub const CXCursor_ExceptionSpecificationKind_NoThrow: Type = 9; +} +extern "C" { + pub fn clang_createIndex( + excludeDeclarationsFromPCH: ::std::os::raw::c_int, + displayDiagnostics: ::std::os::raw::c_int, + ) -> CXIndex; +} +extern "C" { + pub fn clang_disposeIndex(index: CXIndex); +} +pub mod CXGlobalOptFlags { + pub type Type = u32; + pub const CXGlobalOpt_None: Type = 0; + pub const CXGlobalOpt_ThreadBackgroundPriorityForIndexing: Type = 1; + pub const CXGlobalOpt_ThreadBackgroundPriorityForEditing: Type = 2; + pub const CXGlobalOpt_ThreadBackgroundPriorityForAll: Type = 3; +} +extern "C" { + pub fn clang_CXIndex_setGlobalOptions( + arg1: CXIndex, + options: ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_CXIndex_getGlobalOptions( + arg1: CXIndex, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXIndex_setInvocationEmissionPathOption( + arg1: CXIndex, + Path: *const ::std::os::raw::c_char, + ); +} +pub type CXFile = *mut ::std::os::raw::c_void; +extern "C" { + pub fn clang_getFileName(SFile: CXFile) -> CXString; +} +extern "C" { + pub fn clang_getFileTime(SFile: CXFile) -> time_t; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXFileUniqueID { + pub data: [::std::os::raw::c_ulonglong; 3usize], +} +#[test] +fn bindgen_test_layout_CXFileUniqueID() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(CXFileUniqueID)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXFileUniqueID)) + ); + fn test_field_data() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXFileUniqueID), + "::", + stringify!(data) + ) + ); + } + test_field_data(); +} +extern "C" { + pub fn clang_getFileUniqueID( + file: CXFile, + outID: *mut CXFileUniqueID, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_isFileMultipleIncludeGuarded( + tu: CXTranslationUnit, + file: CXFile, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getFile( + tu: CXTranslationUnit, + file_name: *const ::std::os::raw::c_char, + ) -> CXFile; +} +extern "C" { + pub fn clang_getFileContents( + tu: CXTranslationUnit, + file: CXFile, + size: *mut size_t, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn clang_File_isEqual( + file1: CXFile, + file2: CXFile, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_File_tryGetRealPathName(file: CXFile) -> CXString; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXSourceLocation { + pub ptr_data: [*const ::std::os::raw::c_void; 2usize], + pub int_data: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_CXSourceLocation() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(CXSourceLocation)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXSourceLocation)) + ); + fn test_field_ptr_data() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr_data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXSourceLocation), + "::", + stringify!(ptr_data) + ) + ); + } + test_field_ptr_data(); + fn test_field_int_data() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).int_data) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXSourceLocation), + "::", + stringify!(int_data) + ) + ); + } + test_field_int_data(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXSourceRange { + pub ptr_data: [*const ::std::os::raw::c_void; 2usize], + pub begin_int_data: ::std::os::raw::c_uint, + pub end_int_data: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_CXSourceRange() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(CXSourceRange)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXSourceRange)) + ); + fn test_field_ptr_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr_data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXSourceRange), + "::", + stringify!(ptr_data) + ) + ); + } + test_field_ptr_data(); + fn test_field_begin_int_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin_int_data) as usize - + ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXSourceRange), + "::", + stringify!(begin_int_data) + ) + ); + } + test_field_begin_int_data(); + fn test_field_end_int_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end_int_data) as usize - + ptr as usize + }, + 20usize, + concat!( + "Offset of field: ", + stringify!(CXSourceRange), + "::", + stringify!(end_int_data) + ) + ); + } + test_field_end_int_data(); +} +extern "C" { + pub fn clang_getNullLocation() -> CXSourceLocation; +} +extern "C" { + pub fn clang_equalLocations( + loc1: CXSourceLocation, + loc2: CXSourceLocation, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getLocation( + tu: CXTranslationUnit, + file: CXFile, + line: ::std::os::raw::c_uint, + column: ::std::os::raw::c_uint, + ) -> CXSourceLocation; +} +extern "C" { + pub fn clang_getLocationForOffset( + tu: CXTranslationUnit, + file: CXFile, + offset: ::std::os::raw::c_uint, + ) -> CXSourceLocation; +} +extern "C" { + pub fn clang_Location_isInSystemHeader( + location: CXSourceLocation, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_Location_isFromMainFile( + location: CXSourceLocation, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_getNullRange() -> CXSourceRange; +} +extern "C" { + pub fn clang_getRange( + begin: CXSourceLocation, + end: CXSourceLocation, + ) -> CXSourceRange; +} +extern "C" { + pub fn clang_equalRanges( + range1: CXSourceRange, + range2: CXSourceRange, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Range_isNull(range: CXSourceRange) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_getExpansionLocation( + location: CXSourceLocation, + file: *mut CXFile, + line: *mut ::std::os::raw::c_uint, + column: *mut ::std::os::raw::c_uint, + offset: *mut ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_getPresumedLocation( + location: CXSourceLocation, + filename: *mut CXString, + line: *mut ::std::os::raw::c_uint, + column: *mut ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_getInstantiationLocation( + location: CXSourceLocation, + file: *mut CXFile, + line: *mut ::std::os::raw::c_uint, + column: *mut ::std::os::raw::c_uint, + offset: *mut ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_getSpellingLocation( + location: CXSourceLocation, + file: *mut CXFile, + line: *mut ::std::os::raw::c_uint, + column: *mut ::std::os::raw::c_uint, + offset: *mut ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_getFileLocation( + location: CXSourceLocation, + file: *mut CXFile, + line: *mut ::std::os::raw::c_uint, + column: *mut ::std::os::raw::c_uint, + offset: *mut ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_getRangeStart(range: CXSourceRange) -> CXSourceLocation; +} +extern "C" { + pub fn clang_getRangeEnd(range: CXSourceRange) -> CXSourceLocation; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXSourceRangeList { + pub count: ::std::os::raw::c_uint, + pub ranges: *mut CXSourceRange, +} +#[test] +fn bindgen_test_layout_CXSourceRangeList() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(CXSourceRangeList)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXSourceRangeList)) + ); + fn test_field_count() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXSourceRangeList), + "::", + stringify!(count) + ) + ); + } + test_field_count(); + fn test_field_ranges() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ranges) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXSourceRangeList), + "::", + stringify!(ranges) + ) + ); + } + test_field_ranges(); +} +extern "C" { + pub fn clang_getSkippedRanges( + tu: CXTranslationUnit, + file: CXFile, + ) -> *mut CXSourceRangeList; +} +extern "C" { + pub fn clang_getAllSkippedRanges( + tu: CXTranslationUnit, + ) -> *mut CXSourceRangeList; +} +extern "C" { + pub fn clang_disposeSourceRangeList(ranges: *mut CXSourceRangeList); +} +pub mod CXDiagnosticSeverity { + pub type Type = u32; + pub const CXDiagnostic_Ignored: Type = 0; + pub const CXDiagnostic_Note: Type = 1; + pub const CXDiagnostic_Warning: Type = 2; + pub const CXDiagnostic_Error: Type = 3; + pub const CXDiagnostic_Fatal: Type = 4; +} +pub type CXDiagnostic = *mut ::std::os::raw::c_void; +pub type CXDiagnosticSet = *mut ::std::os::raw::c_void; +extern "C" { + pub fn clang_getNumDiagnosticsInSet( + Diags: CXDiagnosticSet, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getDiagnosticInSet( + Diags: CXDiagnosticSet, + Index: ::std::os::raw::c_uint, + ) -> CXDiagnostic; +} +pub mod CXLoadDiag_Error { + pub type Type = u32; + pub const CXLoadDiag_None: Type = 0; + pub const CXLoadDiag_Unknown: Type = 1; + pub const CXLoadDiag_CannotLoad: Type = 2; + pub const CXLoadDiag_InvalidFile: Type = 3; +} +extern "C" { + pub fn clang_loadDiagnostics( + file: *const ::std::os::raw::c_char, + error: *mut CXLoadDiag_Error::Type, + errorString: *mut CXString, + ) -> CXDiagnosticSet; +} +extern "C" { + pub fn clang_disposeDiagnosticSet(Diags: CXDiagnosticSet); +} +extern "C" { + pub fn clang_getChildDiagnostics(D: CXDiagnostic) -> CXDiagnosticSet; +} +extern "C" { + pub fn clang_getNumDiagnostics( + Unit: CXTranslationUnit, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getDiagnostic( + Unit: CXTranslationUnit, + Index: ::std::os::raw::c_uint, + ) -> CXDiagnostic; +} +extern "C" { + pub fn clang_getDiagnosticSetFromTU( + Unit: CXTranslationUnit, + ) -> CXDiagnosticSet; +} +extern "C" { + pub fn clang_disposeDiagnostic(Diagnostic: CXDiagnostic); +} +pub mod CXDiagnosticDisplayOptions { + pub type Type = u32; + pub const CXDiagnostic_DisplaySourceLocation: Type = 1; + pub const CXDiagnostic_DisplayColumn: Type = 2; + pub const CXDiagnostic_DisplaySourceRanges: Type = 4; + pub const CXDiagnostic_DisplayOption: Type = 8; + pub const CXDiagnostic_DisplayCategoryId: Type = 16; + pub const CXDiagnostic_DisplayCategoryName: Type = 32; +} +extern "C" { + pub fn clang_formatDiagnostic( + Diagnostic: CXDiagnostic, + Options: ::std::os::raw::c_uint, + ) -> CXString; +} +extern "C" { + pub fn clang_defaultDiagnosticDisplayOptions() -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getDiagnosticSeverity( + arg1: CXDiagnostic, + ) -> CXDiagnosticSeverity::Type; +} +extern "C" { + pub fn clang_getDiagnosticLocation(arg1: CXDiagnostic) -> CXSourceLocation; +} +extern "C" { + pub fn clang_getDiagnosticSpelling(arg1: CXDiagnostic) -> CXString; +} +extern "C" { + pub fn clang_getDiagnosticOption( + Diag: CXDiagnostic, + Disable: *mut CXString, + ) -> CXString; +} +extern "C" { + pub fn clang_getDiagnosticCategory( + arg1: CXDiagnostic, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getDiagnosticCategoryName( + Category: ::std::os::raw::c_uint, + ) -> CXString; +} +extern "C" { + pub fn clang_getDiagnosticCategoryText(arg1: CXDiagnostic) -> CXString; +} +extern "C" { + pub fn clang_getDiagnosticNumRanges( + arg1: CXDiagnostic, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getDiagnosticRange( + Diagnostic: CXDiagnostic, + Range: ::std::os::raw::c_uint, + ) -> CXSourceRange; +} +extern "C" { + pub fn clang_getDiagnosticNumFixIts( + Diagnostic: CXDiagnostic, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getDiagnosticFixIt( + Diagnostic: CXDiagnostic, + FixIt: ::std::os::raw::c_uint, + ReplacementRange: *mut CXSourceRange, + ) -> CXString; +} +extern "C" { + pub fn clang_getTranslationUnitSpelling( + CTUnit: CXTranslationUnit, + ) -> CXString; +} +extern "C" { + pub fn clang_createTranslationUnitFromSourceFile( + CIdx: CXIndex, + source_filename: *const ::std::os::raw::c_char, + num_clang_command_line_args: ::std::os::raw::c_int, + clang_command_line_args: *const *const ::std::os::raw::c_char, + num_unsaved_files: ::std::os::raw::c_uint, + unsaved_files: *mut CXUnsavedFile, + ) -> CXTranslationUnit; +} +extern "C" { + pub fn clang_createTranslationUnit( + CIdx: CXIndex, + ast_filename: *const ::std::os::raw::c_char, + ) -> CXTranslationUnit; +} +extern "C" { + pub fn clang_createTranslationUnit2( + CIdx: CXIndex, + ast_filename: *const ::std::os::raw::c_char, + out_TU: *mut CXTranslationUnit, + ) -> CXErrorCode::Type; +} +pub mod CXTranslationUnit_Flags { + pub type Type = u32; + pub const CXTranslationUnit_None: Type = 0; + pub const CXTranslationUnit_DetailedPreprocessingRecord: Type = 1; + pub const CXTranslationUnit_Incomplete: Type = 2; + pub const CXTranslationUnit_PrecompiledPreamble: Type = 4; + pub const CXTranslationUnit_CacheCompletionResults: Type = 8; + pub const CXTranslationUnit_ForSerialization: Type = 16; + pub const CXTranslationUnit_CXXChainedPCH: Type = 32; + pub const CXTranslationUnit_SkipFunctionBodies: Type = 64; + pub const CXTranslationUnit_IncludeBriefCommentsInCodeCompletion: Type = + 128; + pub const CXTranslationUnit_CreatePreambleOnFirstParse: Type = 256; + pub const CXTranslationUnit_KeepGoing: Type = 512; + pub const CXTranslationUnit_SingleFileParse: Type = 1024; + pub const CXTranslationUnit_LimitSkipFunctionBodiesToPreamble: Type = 2048; + pub const CXTranslationUnit_IncludeAttributedTypes: Type = 4096; + pub const CXTranslationUnit_VisitImplicitAttributes: Type = 8192; + pub const CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles: Type = 16384; + pub const CXTranslationUnit_RetainExcludedConditionalBlocks: Type = 32768; +} +extern "C" { + pub fn clang_defaultEditingTranslationUnitOptions() -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_parseTranslationUnit( + CIdx: CXIndex, + source_filename: *const ::std::os::raw::c_char, + command_line_args: *const *const ::std::os::raw::c_char, + num_command_line_args: ::std::os::raw::c_int, + unsaved_files: *mut CXUnsavedFile, + num_unsaved_files: ::std::os::raw::c_uint, + options: ::std::os::raw::c_uint, + ) -> CXTranslationUnit; +} +extern "C" { + pub fn clang_parseTranslationUnit2( + CIdx: CXIndex, + source_filename: *const ::std::os::raw::c_char, + command_line_args: *const *const ::std::os::raw::c_char, + num_command_line_args: ::std::os::raw::c_int, + unsaved_files: *mut CXUnsavedFile, + num_unsaved_files: ::std::os::raw::c_uint, + options: ::std::os::raw::c_uint, + out_TU: *mut CXTranslationUnit, + ) -> CXErrorCode::Type; +} +extern "C" { + pub fn clang_parseTranslationUnit2FullArgv( + CIdx: CXIndex, + source_filename: *const ::std::os::raw::c_char, + command_line_args: *const *const ::std::os::raw::c_char, + num_command_line_args: ::std::os::raw::c_int, + unsaved_files: *mut CXUnsavedFile, + num_unsaved_files: ::std::os::raw::c_uint, + options: ::std::os::raw::c_uint, + out_TU: *mut CXTranslationUnit, + ) -> CXErrorCode::Type; +} +pub mod CXSaveTranslationUnit_Flags { + pub type Type = u32; + pub const CXSaveTranslationUnit_None: Type = 0; +} +extern "C" { + pub fn clang_defaultSaveOptions( + TU: CXTranslationUnit, + ) -> ::std::os::raw::c_uint; +} +pub mod CXSaveError { + pub type Type = u32; + pub const CXSaveError_None: Type = 0; + pub const CXSaveError_Unknown: Type = 1; + pub const CXSaveError_TranslationErrors: Type = 2; + pub const CXSaveError_InvalidTU: Type = 3; +} +extern "C" { + pub fn clang_saveTranslationUnit( + TU: CXTranslationUnit, + FileName: *const ::std::os::raw::c_char, + options: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_suspendTranslationUnit( + arg1: CXTranslationUnit, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_disposeTranslationUnit(arg1: CXTranslationUnit); +} +pub mod CXReparse_Flags { + pub type Type = u32; + pub const CXReparse_None: Type = 0; +} +extern "C" { + pub fn clang_defaultReparseOptions( + TU: CXTranslationUnit, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_reparseTranslationUnit( + TU: CXTranslationUnit, + num_unsaved_files: ::std::os::raw::c_uint, + unsaved_files: *mut CXUnsavedFile, + options: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_int; +} +pub mod CXTUResourceUsageKind { + pub type Type = u32; + pub const CXTUResourceUsage_AST: Type = 1; + pub const CXTUResourceUsage_Identifiers: Type = 2; + pub const CXTUResourceUsage_Selectors: Type = 3; + pub const CXTUResourceUsage_GlobalCompletionResults: Type = 4; + pub const CXTUResourceUsage_SourceManagerContentCache: Type = 5; + pub const CXTUResourceUsage_AST_SideTables: Type = 6; + pub const CXTUResourceUsage_SourceManager_Membuffer_Malloc: Type = 7; + pub const CXTUResourceUsage_SourceManager_Membuffer_MMap: Type = 8; + pub const CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc: Type = 9; + pub const CXTUResourceUsage_ExternalASTSource_Membuffer_MMap: Type = 10; + pub const CXTUResourceUsage_Preprocessor: Type = 11; + pub const CXTUResourceUsage_PreprocessingRecord: Type = 12; + pub const CXTUResourceUsage_SourceManager_DataStructures: Type = 13; + pub const CXTUResourceUsage_Preprocessor_HeaderSearch: Type = 14; + pub const CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN: Type = 1; + pub const CXTUResourceUsage_MEMORY_IN_BYTES_END: Type = 14; + pub const CXTUResourceUsage_First: Type = 1; + pub const CXTUResourceUsage_Last: Type = 14; +} +extern "C" { + pub fn clang_getTUResourceUsageName( + kind: CXTUResourceUsageKind::Type, + ) -> *const ::std::os::raw::c_char; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXTUResourceUsageEntry { + pub kind: CXTUResourceUsageKind::Type, + pub amount: ::std::os::raw::c_ulong, +} +#[test] +fn bindgen_test_layout_CXTUResourceUsageEntry() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(CXTUResourceUsageEntry)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXTUResourceUsageEntry)) + ); + fn test_field_kind() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).kind) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXTUResourceUsageEntry), + "::", + stringify!(kind) + ) + ); + } + test_field_kind(); + fn test_field_amount() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).amount) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXTUResourceUsageEntry), + "::", + stringify!(amount) + ) + ); + } + test_field_amount(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXTUResourceUsage { + pub data: *mut ::std::os::raw::c_void, + pub numEntries: ::std::os::raw::c_uint, + pub entries: *mut CXTUResourceUsageEntry, +} +#[test] +fn bindgen_test_layout_CXTUResourceUsage() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(CXTUResourceUsage)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXTUResourceUsage)) + ); + fn test_field_data() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXTUResourceUsage), + "::", + stringify!(data) + ) + ); + } + test_field_data(); + fn test_field_numEntries() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).numEntries) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXTUResourceUsage), + "::", + stringify!(numEntries) + ) + ); + } + test_field_numEntries(); + fn test_field_entries() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).entries) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXTUResourceUsage), + "::", + stringify!(entries) + ) + ); + } + test_field_entries(); +} +extern "C" { + pub fn clang_getCXTUResourceUsage( + TU: CXTranslationUnit, + ) -> CXTUResourceUsage; +} +extern "C" { + pub fn clang_disposeCXTUResourceUsage(usage: CXTUResourceUsage); +} +extern "C" { + pub fn clang_getTranslationUnitTargetInfo( + CTUnit: CXTranslationUnit, + ) -> CXTargetInfo; +} +extern "C" { + pub fn clang_TargetInfo_dispose(Info: CXTargetInfo); +} +extern "C" { + pub fn clang_TargetInfo_getTriple(Info: CXTargetInfo) -> CXString; +} +extern "C" { + pub fn clang_TargetInfo_getPointerWidth( + Info: CXTargetInfo, + ) -> ::std::os::raw::c_int; +} +pub mod CXCursorKind { + pub type Type = u32; + pub const CXCursor_UnexposedDecl: Type = 1; + pub const CXCursor_StructDecl: Type = 2; + pub const CXCursor_UnionDecl: Type = 3; + pub const CXCursor_ClassDecl: Type = 4; + pub const CXCursor_EnumDecl: Type = 5; + pub const CXCursor_FieldDecl: Type = 6; + pub const CXCursor_EnumConstantDecl: Type = 7; + pub const CXCursor_FunctionDecl: Type = 8; + pub const CXCursor_VarDecl: Type = 9; + pub const CXCursor_ParmDecl: Type = 10; + pub const CXCursor_ObjCInterfaceDecl: Type = 11; + pub const CXCursor_ObjCCategoryDecl: Type = 12; + pub const CXCursor_ObjCProtocolDecl: Type = 13; + pub const CXCursor_ObjCPropertyDecl: Type = 14; + pub const CXCursor_ObjCIvarDecl: Type = 15; + pub const CXCursor_ObjCInstanceMethodDecl: Type = 16; + pub const CXCursor_ObjCClassMethodDecl: Type = 17; + pub const CXCursor_ObjCImplementationDecl: Type = 18; + pub const CXCursor_ObjCCategoryImplDecl: Type = 19; + pub const CXCursor_TypedefDecl: Type = 20; + pub const CXCursor_CXXMethod: Type = 21; + pub const CXCursor_Namespace: Type = 22; + pub const CXCursor_LinkageSpec: Type = 23; + pub const CXCursor_Constructor: Type = 24; + pub const CXCursor_Destructor: Type = 25; + pub const CXCursor_ConversionFunction: Type = 26; + pub const CXCursor_TemplateTypeParameter: Type = 27; + pub const CXCursor_NonTypeTemplateParameter: Type = 28; + pub const CXCursor_TemplateTemplateParameter: Type = 29; + pub const CXCursor_FunctionTemplate: Type = 30; + pub const CXCursor_ClassTemplate: Type = 31; + pub const CXCursor_ClassTemplatePartialSpecialization: Type = 32; + pub const CXCursor_NamespaceAlias: Type = 33; + pub const CXCursor_UsingDirective: Type = 34; + pub const CXCursor_UsingDeclaration: Type = 35; + pub const CXCursor_TypeAliasDecl: Type = 36; + pub const CXCursor_ObjCSynthesizeDecl: Type = 37; + pub const CXCursor_ObjCDynamicDecl: Type = 38; + pub const CXCursor_CXXAccessSpecifier: Type = 39; + pub const CXCursor_FirstDecl: Type = 1; + pub const CXCursor_LastDecl: Type = 39; + pub const CXCursor_FirstRef: Type = 40; + pub const CXCursor_ObjCSuperClassRef: Type = 40; + pub const CXCursor_ObjCProtocolRef: Type = 41; + pub const CXCursor_ObjCClassRef: Type = 42; + pub const CXCursor_TypeRef: Type = 43; + pub const CXCursor_CXXBaseSpecifier: Type = 44; + pub const CXCursor_TemplateRef: Type = 45; + pub const CXCursor_NamespaceRef: Type = 46; + pub const CXCursor_MemberRef: Type = 47; + pub const CXCursor_LabelRef: Type = 48; + pub const CXCursor_OverloadedDeclRef: Type = 49; + pub const CXCursor_VariableRef: Type = 50; + pub const CXCursor_LastRef: Type = 50; + pub const CXCursor_FirstInvalid: Type = 70; + pub const CXCursor_InvalidFile: Type = 70; + pub const CXCursor_NoDeclFound: Type = 71; + pub const CXCursor_NotImplemented: Type = 72; + pub const CXCursor_InvalidCode: Type = 73; + pub const CXCursor_LastInvalid: Type = 73; + pub const CXCursor_FirstExpr: Type = 100; + pub const CXCursor_UnexposedExpr: Type = 100; + pub const CXCursor_DeclRefExpr: Type = 101; + pub const CXCursor_MemberRefExpr: Type = 102; + pub const CXCursor_CallExpr: Type = 103; + pub const CXCursor_ObjCMessageExpr: Type = 104; + pub const CXCursor_BlockExpr: Type = 105; + pub const CXCursor_IntegerLiteral: Type = 106; + pub const CXCursor_FloatingLiteral: Type = 107; + pub const CXCursor_ImaginaryLiteral: Type = 108; + pub const CXCursor_StringLiteral: Type = 109; + pub const CXCursor_CharacterLiteral: Type = 110; + pub const CXCursor_ParenExpr: Type = 111; + pub const CXCursor_UnaryOperator: Type = 112; + pub const CXCursor_ArraySubscriptExpr: Type = 113; + pub const CXCursor_BinaryOperator: Type = 114; + pub const CXCursor_CompoundAssignOperator: Type = 115; + pub const CXCursor_ConditionalOperator: Type = 116; + pub const CXCursor_CStyleCastExpr: Type = 117; + pub const CXCursor_CompoundLiteralExpr: Type = 118; + pub const CXCursor_InitListExpr: Type = 119; + pub const CXCursor_AddrLabelExpr: Type = 120; + pub const CXCursor_StmtExpr: Type = 121; + pub const CXCursor_GenericSelectionExpr: Type = 122; + pub const CXCursor_GNUNullExpr: Type = 123; + pub const CXCursor_CXXStaticCastExpr: Type = 124; + pub const CXCursor_CXXDynamicCastExpr: Type = 125; + pub const CXCursor_CXXReinterpretCastExpr: Type = 126; + pub const CXCursor_CXXConstCastExpr: Type = 127; + pub const CXCursor_CXXFunctionalCastExpr: Type = 128; + pub const CXCursor_CXXTypeidExpr: Type = 129; + pub const CXCursor_CXXBoolLiteralExpr: Type = 130; + pub const CXCursor_CXXNullPtrLiteralExpr: Type = 131; + pub const CXCursor_CXXThisExpr: Type = 132; + pub const CXCursor_CXXThrowExpr: Type = 133; + pub const CXCursor_CXXNewExpr: Type = 134; + pub const CXCursor_CXXDeleteExpr: Type = 135; + pub const CXCursor_UnaryExpr: Type = 136; + pub const CXCursor_ObjCStringLiteral: Type = 137; + pub const CXCursor_ObjCEncodeExpr: Type = 138; + pub const CXCursor_ObjCSelectorExpr: Type = 139; + pub const CXCursor_ObjCProtocolExpr: Type = 140; + pub const CXCursor_ObjCBridgedCastExpr: Type = 141; + pub const CXCursor_PackExpansionExpr: Type = 142; + pub const CXCursor_SizeOfPackExpr: Type = 143; + pub const CXCursor_LambdaExpr: Type = 144; + pub const CXCursor_ObjCBoolLiteralExpr: Type = 145; + pub const CXCursor_ObjCSelfExpr: Type = 146; + pub const CXCursor_OMPArraySectionExpr: Type = 147; + pub const CXCursor_ObjCAvailabilityCheckExpr: Type = 148; + pub const CXCursor_FixedPointLiteral: Type = 149; + pub const CXCursor_OMPArrayShapingExpr: Type = 150; + pub const CXCursor_OMPIteratorExpr: Type = 151; + pub const CXCursor_CXXAddrspaceCastExpr: Type = 152; + pub const CXCursor_LastExpr: Type = 152; + pub const CXCursor_FirstStmt: Type = 200; + pub const CXCursor_UnexposedStmt: Type = 200; + pub const CXCursor_LabelStmt: Type = 201; + pub const CXCursor_CompoundStmt: Type = 202; + pub const CXCursor_CaseStmt: Type = 203; + pub const CXCursor_DefaultStmt: Type = 204; + pub const CXCursor_IfStmt: Type = 205; + pub const CXCursor_SwitchStmt: Type = 206; + pub const CXCursor_WhileStmt: Type = 207; + pub const CXCursor_DoStmt: Type = 208; + pub const CXCursor_ForStmt: Type = 209; + pub const CXCursor_GotoStmt: Type = 210; + pub const CXCursor_IndirectGotoStmt: Type = 211; + pub const CXCursor_ContinueStmt: Type = 212; + pub const CXCursor_BreakStmt: Type = 213; + pub const CXCursor_ReturnStmt: Type = 214; + pub const CXCursor_GCCAsmStmt: Type = 215; + pub const CXCursor_AsmStmt: Type = 215; + pub const CXCursor_ObjCAtTryStmt: Type = 216; + pub const CXCursor_ObjCAtCatchStmt: Type = 217; + pub const CXCursor_ObjCAtFinallyStmt: Type = 218; + pub const CXCursor_ObjCAtThrowStmt: Type = 219; + pub const CXCursor_ObjCAtSynchronizedStmt: Type = 220; + pub const CXCursor_ObjCAutoreleasePoolStmt: Type = 221; + pub const CXCursor_ObjCForCollectionStmt: Type = 222; + pub const CXCursor_CXXCatchStmt: Type = 223; + pub const CXCursor_CXXTryStmt: Type = 224; + pub const CXCursor_CXXForRangeStmt: Type = 225; + pub const CXCursor_SEHTryStmt: Type = 226; + pub const CXCursor_SEHExceptStmt: Type = 227; + pub const CXCursor_SEHFinallyStmt: Type = 228; + pub const CXCursor_MSAsmStmt: Type = 229; + pub const CXCursor_NullStmt: Type = 230; + pub const CXCursor_DeclStmt: Type = 231; + pub const CXCursor_OMPParallelDirective: Type = 232; + pub const CXCursor_OMPSimdDirective: Type = 233; + pub const CXCursor_OMPForDirective: Type = 234; + pub const CXCursor_OMPSectionsDirective: Type = 235; + pub const CXCursor_OMPSectionDirective: Type = 236; + pub const CXCursor_OMPSingleDirective: Type = 237; + pub const CXCursor_OMPParallelForDirective: Type = 238; + pub const CXCursor_OMPParallelSectionsDirective: Type = 239; + pub const CXCursor_OMPTaskDirective: Type = 240; + pub const CXCursor_OMPMasterDirective: Type = 241; + pub const CXCursor_OMPCriticalDirective: Type = 242; + pub const CXCursor_OMPTaskyieldDirective: Type = 243; + pub const CXCursor_OMPBarrierDirective: Type = 244; + pub const CXCursor_OMPTaskwaitDirective: Type = 245; + pub const CXCursor_OMPFlushDirective: Type = 246; + pub const CXCursor_SEHLeaveStmt: Type = 247; + pub const CXCursor_OMPOrderedDirective: Type = 248; + pub const CXCursor_OMPAtomicDirective: Type = 249; + pub const CXCursor_OMPForSimdDirective: Type = 250; + pub const CXCursor_OMPParallelForSimdDirective: Type = 251; + pub const CXCursor_OMPTargetDirective: Type = 252; + pub const CXCursor_OMPTeamsDirective: Type = 253; + pub const CXCursor_OMPTaskgroupDirective: Type = 254; + pub const CXCursor_OMPCancellationPointDirective: Type = 255; + pub const CXCursor_OMPCancelDirective: Type = 256; + pub const CXCursor_OMPTargetDataDirective: Type = 257; + pub const CXCursor_OMPTaskLoopDirective: Type = 258; + pub const CXCursor_OMPTaskLoopSimdDirective: Type = 259; + pub const CXCursor_OMPDistributeDirective: Type = 260; + pub const CXCursor_OMPTargetEnterDataDirective: Type = 261; + pub const CXCursor_OMPTargetExitDataDirective: Type = 262; + pub const CXCursor_OMPTargetParallelDirective: Type = 263; + pub const CXCursor_OMPTargetParallelForDirective: Type = 264; + pub const CXCursor_OMPTargetUpdateDirective: Type = 265; + pub const CXCursor_OMPDistributeParallelForDirective: Type = 266; + pub const CXCursor_OMPDistributeParallelForSimdDirective: Type = 267; + pub const CXCursor_OMPDistributeSimdDirective: Type = 268; + pub const CXCursor_OMPTargetParallelForSimdDirective: Type = 269; + pub const CXCursor_OMPTargetSimdDirective: Type = 270; + pub const CXCursor_OMPTeamsDistributeDirective: Type = 271; + pub const CXCursor_OMPTeamsDistributeSimdDirective: Type = 272; + pub const CXCursor_OMPTeamsDistributeParallelForSimdDirective: Type = 273; + pub const CXCursor_OMPTeamsDistributeParallelForDirective: Type = 274; + pub const CXCursor_OMPTargetTeamsDirective: Type = 275; + pub const CXCursor_OMPTargetTeamsDistributeDirective: Type = 276; + pub const CXCursor_OMPTargetTeamsDistributeParallelForDirective: Type = 277; + pub const CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective: Type = + 278; + pub const CXCursor_OMPTargetTeamsDistributeSimdDirective: Type = 279; + pub const CXCursor_BuiltinBitCastExpr: Type = 280; + pub const CXCursor_OMPMasterTaskLoopDirective: Type = 281; + pub const CXCursor_OMPParallelMasterTaskLoopDirective: Type = 282; + pub const CXCursor_OMPMasterTaskLoopSimdDirective: Type = 283; + pub const CXCursor_OMPParallelMasterTaskLoopSimdDirective: Type = 284; + pub const CXCursor_OMPParallelMasterDirective: Type = 285; + pub const CXCursor_OMPDepobjDirective: Type = 286; + pub const CXCursor_OMPScanDirective: Type = 287; + pub const CXCursor_OMPTileDirective: Type = 288; + pub const CXCursor_OMPCanonicalLoop: Type = 289; + pub const CXCursor_OMPInteropDirective: Type = 290; + pub const CXCursor_OMPDispatchDirective: Type = 291; + pub const CXCursor_OMPMaskedDirective: Type = 292; + pub const CXCursor_OMPUnrollDirective: Type = 293; + pub const CXCursor_LastStmt: Type = 293; + pub const CXCursor_TranslationUnit: Type = 300; + pub const CXCursor_FirstAttr: Type = 400; + pub const CXCursor_UnexposedAttr: Type = 400; + pub const CXCursor_IBActionAttr: Type = 401; + pub const CXCursor_IBOutletAttr: Type = 402; + pub const CXCursor_IBOutletCollectionAttr: Type = 403; + pub const CXCursor_CXXFinalAttr: Type = 404; + pub const CXCursor_CXXOverrideAttr: Type = 405; + pub const CXCursor_AnnotateAttr: Type = 406; + pub const CXCursor_AsmLabelAttr: Type = 407; + pub const CXCursor_PackedAttr: Type = 408; + pub const CXCursor_PureAttr: Type = 409; + pub const CXCursor_ConstAttr: Type = 410; + pub const CXCursor_NoDuplicateAttr: Type = 411; + pub const CXCursor_CUDAConstantAttr: Type = 412; + pub const CXCursor_CUDADeviceAttr: Type = 413; + pub const CXCursor_CUDAGlobalAttr: Type = 414; + pub const CXCursor_CUDAHostAttr: Type = 415; + pub const CXCursor_CUDASharedAttr: Type = 416; + pub const CXCursor_VisibilityAttr: Type = 417; + pub const CXCursor_DLLExport: Type = 418; + pub const CXCursor_DLLImport: Type = 419; + pub const CXCursor_NSReturnsRetained: Type = 420; + pub const CXCursor_NSReturnsNotRetained: Type = 421; + pub const CXCursor_NSReturnsAutoreleased: Type = 422; + pub const CXCursor_NSConsumesSelf: Type = 423; + pub const CXCursor_NSConsumed: Type = 424; + pub const CXCursor_ObjCException: Type = 425; + pub const CXCursor_ObjCNSObject: Type = 426; + pub const CXCursor_ObjCIndependentClass: Type = 427; + pub const CXCursor_ObjCPreciseLifetime: Type = 428; + pub const CXCursor_ObjCReturnsInnerPointer: Type = 429; + pub const CXCursor_ObjCRequiresSuper: Type = 430; + pub const CXCursor_ObjCRootClass: Type = 431; + pub const CXCursor_ObjCSubclassingRestricted: Type = 432; + pub const CXCursor_ObjCExplicitProtocolImpl: Type = 433; + pub const CXCursor_ObjCDesignatedInitializer: Type = 434; + pub const CXCursor_ObjCRuntimeVisible: Type = 435; + pub const CXCursor_ObjCBoxable: Type = 436; + pub const CXCursor_FlagEnum: Type = 437; + pub const CXCursor_ConvergentAttr: Type = 438; + pub const CXCursor_WarnUnusedAttr: Type = 439; + pub const CXCursor_WarnUnusedResultAttr: Type = 440; + pub const CXCursor_AlignedAttr: Type = 441; + pub const CXCursor_LastAttr: Type = 441; + pub const CXCursor_PreprocessingDirective: Type = 500; + pub const CXCursor_MacroDefinition: Type = 501; + pub const CXCursor_MacroExpansion: Type = 502; + pub const CXCursor_MacroInstantiation: Type = 502; + pub const CXCursor_InclusionDirective: Type = 503; + pub const CXCursor_FirstPreprocessing: Type = 500; + pub const CXCursor_LastPreprocessing: Type = 503; + pub const CXCursor_ModuleImportDecl: Type = 600; + pub const CXCursor_TypeAliasTemplateDecl: Type = 601; + pub const CXCursor_StaticAssert: Type = 602; + pub const CXCursor_FriendDecl: Type = 603; + pub const CXCursor_FirstExtraDecl: Type = 600; + pub const CXCursor_LastExtraDecl: Type = 603; + pub const CXCursor_OverloadCandidate: Type = 700; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXCursor { + pub kind: CXCursorKind::Type, + pub xdata: ::std::os::raw::c_int, + pub data: [*const ::std::os::raw::c_void; 3usize], +} +#[test] +fn bindgen_test_layout_CXCursor() { + assert_eq!( + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(CXCursor)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXCursor)) + ); + fn test_field_kind() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).kind) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXCursor), + "::", + stringify!(kind) + ) + ); + } + test_field_kind(); + fn test_field_xdata() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).xdata) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(CXCursor), + "::", + stringify!(xdata) + ) + ); + } + test_field_xdata(); + fn test_field_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXCursor), + "::", + stringify!(data) + ) + ); + } + test_field_data(); +} +extern "C" { + pub fn clang_getNullCursor() -> CXCursor; +} +extern "C" { + pub fn clang_getTranslationUnitCursor(arg1: CXTranslationUnit) -> CXCursor; +} +extern "C" { + pub fn clang_equalCursors( + arg1: CXCursor, + arg2: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_isNull(cursor: CXCursor) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_hashCursor(arg1: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getCursorKind(arg1: CXCursor) -> CXCursorKind::Type; +} +extern "C" { + pub fn clang_isDeclaration( + arg1: CXCursorKind::Type, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isInvalidDeclaration(arg1: CXCursor) + -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isReference( + arg1: CXCursorKind::Type, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isExpression( + arg1: CXCursorKind::Type, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isStatement( + arg1: CXCursorKind::Type, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isAttribute( + arg1: CXCursorKind::Type, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_hasAttrs(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isInvalid(arg1: CXCursorKind::Type) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isTranslationUnit( + arg1: CXCursorKind::Type, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isPreprocessing( + arg1: CXCursorKind::Type, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isUnexposed( + arg1: CXCursorKind::Type, + ) -> ::std::os::raw::c_uint; +} +pub mod CXLinkageKind { + pub type Type = u32; + pub const CXLinkage_Invalid: Type = 0; + pub const CXLinkage_NoLinkage: Type = 1; + pub const CXLinkage_Internal: Type = 2; + pub const CXLinkage_UniqueExternal: Type = 3; + pub const CXLinkage_External: Type = 4; +} +extern "C" { + pub fn clang_getCursorLinkage(cursor: CXCursor) -> CXLinkageKind::Type; +} +pub mod CXVisibilityKind { + pub type Type = u32; + pub const CXVisibility_Invalid: Type = 0; + pub const CXVisibility_Hidden: Type = 1; + pub const CXVisibility_Protected: Type = 2; + pub const CXVisibility_Default: Type = 3; +} +extern "C" { + pub fn clang_getCursorVisibility( + cursor: CXCursor, + ) -> CXVisibilityKind::Type; +} +extern "C" { + pub fn clang_getCursorAvailability( + cursor: CXCursor, + ) -> CXAvailabilityKind::Type; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXPlatformAvailability { + pub Platform: CXString, + pub Introduced: CXVersion, + pub Deprecated: CXVersion, + pub Obsoleted: CXVersion, + pub Unavailable: ::std::os::raw::c_int, + pub Message: CXString, +} +#[test] +fn bindgen_test_layout_CXPlatformAvailability() { + assert_eq!( + ::std::mem::size_of::(), + 72usize, + concat!("Size of: ", stringify!(CXPlatformAvailability)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXPlatformAvailability)) + ); + fn test_field_Platform() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Platform) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXPlatformAvailability), + "::", + stringify!(Platform) + ) + ); + } + test_field_Platform(); + fn test_field_Introduced() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Introduced) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXPlatformAvailability), + "::", + stringify!(Introduced) + ) + ); + } + test_field_Introduced(); + fn test_field_Deprecated() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Deprecated) as usize - ptr as usize + }, + 28usize, + concat!( + "Offset of field: ", + stringify!(CXPlatformAvailability), + "::", + stringify!(Deprecated) + ) + ); + } + test_field_Deprecated(); + fn test_field_Obsoleted() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Obsoleted) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(CXPlatformAvailability), + "::", + stringify!(Obsoleted) + ) + ); + } + test_field_Obsoleted(); + fn test_field_Unavailable() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Unavailable) as usize - ptr as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(CXPlatformAvailability), + "::", + stringify!(Unavailable) + ) + ); + } + test_field_Unavailable(); + fn test_field_Message() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Message) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(CXPlatformAvailability), + "::", + stringify!(Message) + ) + ); + } + test_field_Message(); +} +extern "C" { + pub fn clang_getCursorPlatformAvailability( + cursor: CXCursor, + always_deprecated: *mut ::std::os::raw::c_int, + deprecated_message: *mut CXString, + always_unavailable: *mut ::std::os::raw::c_int, + unavailable_message: *mut CXString, + availability: *mut CXPlatformAvailability, + availability_size: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_disposeCXPlatformAvailability( + availability: *mut CXPlatformAvailability, + ); +} +extern "C" { + pub fn clang_Cursor_getVarDeclInitializer(cursor: CXCursor) -> CXCursor; +} +extern "C" { + pub fn clang_Cursor_hasVarDeclGlobalStorage( + cursor: CXCursor, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_Cursor_hasVarDeclExternalStorage( + cursor: CXCursor, + ) -> ::std::os::raw::c_int; +} +pub mod CXLanguageKind { + pub type Type = u32; + pub const CXLanguage_Invalid: Type = 0; + pub const CXLanguage_C: Type = 1; + pub const CXLanguage_ObjC: Type = 2; + pub const CXLanguage_CPlusPlus: Type = 3; +} +extern "C" { + pub fn clang_getCursorLanguage(cursor: CXCursor) -> CXLanguageKind::Type; +} +pub mod CXTLSKind { + pub type Type = u32; + pub const CXTLS_None: Type = 0; + pub const CXTLS_Dynamic: Type = 1; + pub const CXTLS_Static: Type = 2; +} +extern "C" { + pub fn clang_getCursorTLSKind(cursor: CXCursor) -> CXTLSKind::Type; +} +extern "C" { + pub fn clang_Cursor_getTranslationUnit(arg1: CXCursor) + -> CXTranslationUnit; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXCursorSetImpl { + _unused: [u8; 0], +} +pub type CXCursorSet = *mut CXCursorSetImpl; +extern "C" { + pub fn clang_createCXCursorSet() -> CXCursorSet; +} +extern "C" { + pub fn clang_disposeCXCursorSet(cset: CXCursorSet); +} +extern "C" { + pub fn clang_CXCursorSet_contains( + cset: CXCursorSet, + cursor: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXCursorSet_insert( + cset: CXCursorSet, + cursor: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getCursorSemanticParent(cursor: CXCursor) -> CXCursor; +} +extern "C" { + pub fn clang_getCursorLexicalParent(cursor: CXCursor) -> CXCursor; +} +extern "C" { + pub fn clang_getOverriddenCursors( + cursor: CXCursor, + overridden: *mut *mut CXCursor, + num_overridden: *mut ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_disposeOverriddenCursors(overridden: *mut CXCursor); +} +extern "C" { + pub fn clang_getIncludedFile(cursor: CXCursor) -> CXFile; +} +extern "C" { + pub fn clang_getCursor( + arg1: CXTranslationUnit, + arg2: CXSourceLocation, + ) -> CXCursor; +} +extern "C" { + pub fn clang_getCursorLocation(arg1: CXCursor) -> CXSourceLocation; +} +extern "C" { + pub fn clang_getCursorExtent(arg1: CXCursor) -> CXSourceRange; +} +pub mod CXTypeKind { + pub type Type = u32; + pub const CXType_Invalid: Type = 0; + pub const CXType_Unexposed: Type = 1; + pub const CXType_Void: Type = 2; + pub const CXType_Bool: Type = 3; + pub const CXType_Char_U: Type = 4; + pub const CXType_UChar: Type = 5; + pub const CXType_Char16: Type = 6; + pub const CXType_Char32: Type = 7; + pub const CXType_UShort: Type = 8; + pub const CXType_UInt: Type = 9; + pub const CXType_ULong: Type = 10; + pub const CXType_ULongLong: Type = 11; + pub const CXType_UInt128: Type = 12; + pub const CXType_Char_S: Type = 13; + pub const CXType_SChar: Type = 14; + pub const CXType_WChar: Type = 15; + pub const CXType_Short: Type = 16; + pub const CXType_Int: Type = 17; + pub const CXType_Long: Type = 18; + pub const CXType_LongLong: Type = 19; + pub const CXType_Int128: Type = 20; + pub const CXType_Float: Type = 21; + pub const CXType_Double: Type = 22; + pub const CXType_LongDouble: Type = 23; + pub const CXType_NullPtr: Type = 24; + pub const CXType_Overload: Type = 25; + pub const CXType_Dependent: Type = 26; + pub const CXType_ObjCId: Type = 27; + pub const CXType_ObjCClass: Type = 28; + pub const CXType_ObjCSel: Type = 29; + pub const CXType_Float128: Type = 30; + pub const CXType_Half: Type = 31; + pub const CXType_Float16: Type = 32; + pub const CXType_ShortAccum: Type = 33; + pub const CXType_Accum: Type = 34; + pub const CXType_LongAccum: Type = 35; + pub const CXType_UShortAccum: Type = 36; + pub const CXType_UAccum: Type = 37; + pub const CXType_ULongAccum: Type = 38; + pub const CXType_BFloat16: Type = 39; + pub const CXType_FirstBuiltin: Type = 2; + pub const CXType_LastBuiltin: Type = 39; + pub const CXType_Complex: Type = 100; + pub const CXType_Pointer: Type = 101; + pub const CXType_BlockPointer: Type = 102; + pub const CXType_LValueReference: Type = 103; + pub const CXType_RValueReference: Type = 104; + pub const CXType_Record: Type = 105; + pub const CXType_Enum: Type = 106; + pub const CXType_Typedef: Type = 107; + pub const CXType_ObjCInterface: Type = 108; + pub const CXType_ObjCObjectPointer: Type = 109; + pub const CXType_FunctionNoProto: Type = 110; + pub const CXType_FunctionProto: Type = 111; + pub const CXType_ConstantArray: Type = 112; + pub const CXType_Vector: Type = 113; + pub const CXType_IncompleteArray: Type = 114; + pub const CXType_VariableArray: Type = 115; + pub const CXType_DependentSizedArray: Type = 116; + pub const CXType_MemberPointer: Type = 117; + pub const CXType_Auto: Type = 118; + pub const CXType_Elaborated: Type = 119; + pub const CXType_Pipe: Type = 120; + pub const CXType_OCLImage1dRO: Type = 121; + pub const CXType_OCLImage1dArrayRO: Type = 122; + pub const CXType_OCLImage1dBufferRO: Type = 123; + pub const CXType_OCLImage2dRO: Type = 124; + pub const CXType_OCLImage2dArrayRO: Type = 125; + pub const CXType_OCLImage2dDepthRO: Type = 126; + pub const CXType_OCLImage2dArrayDepthRO: Type = 127; + pub const CXType_OCLImage2dMSAARO: Type = 128; + pub const CXType_OCLImage2dArrayMSAARO: Type = 129; + pub const CXType_OCLImage2dMSAADepthRO: Type = 130; + pub const CXType_OCLImage2dArrayMSAADepthRO: Type = 131; + pub const CXType_OCLImage3dRO: Type = 132; + pub const CXType_OCLImage1dWO: Type = 133; + pub const CXType_OCLImage1dArrayWO: Type = 134; + pub const CXType_OCLImage1dBufferWO: Type = 135; + pub const CXType_OCLImage2dWO: Type = 136; + pub const CXType_OCLImage2dArrayWO: Type = 137; + pub const CXType_OCLImage2dDepthWO: Type = 138; + pub const CXType_OCLImage2dArrayDepthWO: Type = 139; + pub const CXType_OCLImage2dMSAAWO: Type = 140; + pub const CXType_OCLImage2dArrayMSAAWO: Type = 141; + pub const CXType_OCLImage2dMSAADepthWO: Type = 142; + pub const CXType_OCLImage2dArrayMSAADepthWO: Type = 143; + pub const CXType_OCLImage3dWO: Type = 144; + pub const CXType_OCLImage1dRW: Type = 145; + pub const CXType_OCLImage1dArrayRW: Type = 146; + pub const CXType_OCLImage1dBufferRW: Type = 147; + pub const CXType_OCLImage2dRW: Type = 148; + pub const CXType_OCLImage2dArrayRW: Type = 149; + pub const CXType_OCLImage2dDepthRW: Type = 150; + pub const CXType_OCLImage2dArrayDepthRW: Type = 151; + pub const CXType_OCLImage2dMSAARW: Type = 152; + pub const CXType_OCLImage2dArrayMSAARW: Type = 153; + pub const CXType_OCLImage2dMSAADepthRW: Type = 154; + pub const CXType_OCLImage2dArrayMSAADepthRW: Type = 155; + pub const CXType_OCLImage3dRW: Type = 156; + pub const CXType_OCLSampler: Type = 157; + pub const CXType_OCLEvent: Type = 158; + pub const CXType_OCLQueue: Type = 159; + pub const CXType_OCLReserveID: Type = 160; + pub const CXType_ObjCObject: Type = 161; + pub const CXType_ObjCTypeParam: Type = 162; + pub const CXType_Attributed: Type = 163; + pub const CXType_OCLIntelSubgroupAVCMcePayload: Type = 164; + pub const CXType_OCLIntelSubgroupAVCImePayload: Type = 165; + pub const CXType_OCLIntelSubgroupAVCRefPayload: Type = 166; + pub const CXType_OCLIntelSubgroupAVCSicPayload: Type = 167; + pub const CXType_OCLIntelSubgroupAVCMceResult: Type = 168; + pub const CXType_OCLIntelSubgroupAVCImeResult: Type = 169; + pub const CXType_OCLIntelSubgroupAVCRefResult: Type = 170; + pub const CXType_OCLIntelSubgroupAVCSicResult: Type = 171; + pub const CXType_OCLIntelSubgroupAVCImeResultSingleRefStreamout: Type = 172; + pub const CXType_OCLIntelSubgroupAVCImeResultDualRefStreamout: Type = 173; + pub const CXType_OCLIntelSubgroupAVCImeSingleRefStreamin: Type = 174; + pub const CXType_OCLIntelSubgroupAVCImeDualRefStreamin: Type = 175; + pub const CXType_ExtVector: Type = 176; + pub const CXType_Atomic: Type = 177; +} +pub mod CXCallingConv { + pub type Type = u32; + pub const CXCallingConv_Default: Type = 0; + pub const CXCallingConv_C: Type = 1; + pub const CXCallingConv_X86StdCall: Type = 2; + pub const CXCallingConv_X86FastCall: Type = 3; + pub const CXCallingConv_X86ThisCall: Type = 4; + pub const CXCallingConv_X86Pascal: Type = 5; + pub const CXCallingConv_AAPCS: Type = 6; + pub const CXCallingConv_AAPCS_VFP: Type = 7; + pub const CXCallingConv_X86RegCall: Type = 8; + pub const CXCallingConv_IntelOclBicc: Type = 9; + pub const CXCallingConv_Win64: Type = 10; + pub const CXCallingConv_X86_64Win64: Type = 10; + pub const CXCallingConv_X86_64SysV: Type = 11; + pub const CXCallingConv_X86VectorCall: Type = 12; + pub const CXCallingConv_Swift: Type = 13; + pub const CXCallingConv_PreserveMost: Type = 14; + pub const CXCallingConv_PreserveAll: Type = 15; + pub const CXCallingConv_AArch64VectorCall: Type = 16; + pub const CXCallingConv_SwiftAsync: Type = 17; + pub const CXCallingConv_Invalid: Type = 100; + pub const CXCallingConv_Unexposed: Type = 200; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXType { + pub kind: CXTypeKind::Type, + pub data: [*mut ::std::os::raw::c_void; 2usize], +} +#[test] +fn bindgen_test_layout_CXType() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(CXType)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXType)) + ); + fn test_field_kind() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).kind) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXType), + "::", + stringify!(kind) + ) + ); + } + test_field_kind(); + fn test_field_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXType), + "::", + stringify!(data) + ) + ); + } + test_field_data(); +} +extern "C" { + pub fn clang_getCursorType(C: CXCursor) -> CXType; +} +extern "C" { + pub fn clang_getTypeSpelling(CT: CXType) -> CXString; +} +extern "C" { + pub fn clang_getTypedefDeclUnderlyingType(C: CXCursor) -> CXType; +} +extern "C" { + pub fn clang_getEnumDeclIntegerType(C: CXCursor) -> CXType; +} +extern "C" { + pub fn clang_getEnumConstantDeclValue( + C: CXCursor, + ) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn clang_getEnumConstantDeclUnsignedValue( + C: CXCursor, + ) -> ::std::os::raw::c_ulonglong; +} +extern "C" { + pub fn clang_getFieldDeclBitWidth(C: CXCursor) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_Cursor_getNumArguments(C: CXCursor) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_Cursor_getArgument( + C: CXCursor, + i: ::std::os::raw::c_uint, + ) -> CXCursor; +} +pub mod CXTemplateArgumentKind { + pub type Type = u32; + pub const CXTemplateArgumentKind_Null: Type = 0; + pub const CXTemplateArgumentKind_Type: Type = 1; + pub const CXTemplateArgumentKind_Declaration: Type = 2; + pub const CXTemplateArgumentKind_NullPtr: Type = 3; + pub const CXTemplateArgumentKind_Integral: Type = 4; + pub const CXTemplateArgumentKind_Template: Type = 5; + pub const CXTemplateArgumentKind_TemplateExpansion: Type = 6; + pub const CXTemplateArgumentKind_Expression: Type = 7; + pub const CXTemplateArgumentKind_Pack: Type = 8; + pub const CXTemplateArgumentKind_Invalid: Type = 9; +} +extern "C" { + pub fn clang_Cursor_getNumTemplateArguments( + C: CXCursor, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_Cursor_getTemplateArgumentKind( + C: CXCursor, + I: ::std::os::raw::c_uint, + ) -> CXTemplateArgumentKind::Type; +} +extern "C" { + pub fn clang_Cursor_getTemplateArgumentType( + C: CXCursor, + I: ::std::os::raw::c_uint, + ) -> CXType; +} +extern "C" { + pub fn clang_Cursor_getTemplateArgumentValue( + C: CXCursor, + I: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn clang_Cursor_getTemplateArgumentUnsignedValue( + C: CXCursor, + I: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_ulonglong; +} +extern "C" { + pub fn clang_equalTypes(A: CXType, B: CXType) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getCanonicalType(T: CXType) -> CXType; +} +extern "C" { + pub fn clang_isConstQualifiedType(T: CXType) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_isMacroFunctionLike( + C: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_isMacroBuiltin(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_isFunctionInlined( + C: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isVolatileQualifiedType(T: CXType) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isRestrictQualifiedType(T: CXType) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getAddressSpace(T: CXType) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getTypedefName(CT: CXType) -> CXString; +} +extern "C" { + pub fn clang_getPointeeType(T: CXType) -> CXType; +} +extern "C" { + pub fn clang_getTypeDeclaration(T: CXType) -> CXCursor; +} +extern "C" { + pub fn clang_getDeclObjCTypeEncoding(C: CXCursor) -> CXString; +} +extern "C" { + pub fn clang_Type_getObjCEncoding(type_: CXType) -> CXString; +} +extern "C" { + pub fn clang_getTypeKindSpelling(K: CXTypeKind::Type) -> CXString; +} +extern "C" { + pub fn clang_getFunctionTypeCallingConv(T: CXType) -> CXCallingConv::Type; +} +extern "C" { + pub fn clang_getResultType(T: CXType) -> CXType; +} +extern "C" { + pub fn clang_getExceptionSpecificationType( + T: CXType, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_getNumArgTypes(T: CXType) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_getArgType(T: CXType, i: ::std::os::raw::c_uint) -> CXType; +} +extern "C" { + pub fn clang_Type_getObjCObjectBaseType(T: CXType) -> CXType; +} +extern "C" { + pub fn clang_Type_getNumObjCProtocolRefs( + T: CXType, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Type_getObjCProtocolDecl( + T: CXType, + i: ::std::os::raw::c_uint, + ) -> CXCursor; +} +extern "C" { + pub fn clang_Type_getNumObjCTypeArgs(T: CXType) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Type_getObjCTypeArg( + T: CXType, + i: ::std::os::raw::c_uint, + ) -> CXType; +} +extern "C" { + pub fn clang_isFunctionTypeVariadic(T: CXType) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getCursorResultType(C: CXCursor) -> CXType; +} +extern "C" { + pub fn clang_getCursorExceptionSpecificationType( + C: CXCursor, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_isPODType(T: CXType) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getElementType(T: CXType) -> CXType; +} +extern "C" { + pub fn clang_getNumElements(T: CXType) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn clang_getArrayElementType(T: CXType) -> CXType; +} +extern "C" { + pub fn clang_getArraySize(T: CXType) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn clang_Type_getNamedType(T: CXType) -> CXType; +} +extern "C" { + pub fn clang_Type_isTransparentTagTypedef( + T: CXType, + ) -> ::std::os::raw::c_uint; +} +pub mod CXTypeNullabilityKind { + pub type Type = u32; + pub const CXTypeNullability_NonNull: Type = 0; + pub const CXTypeNullability_Nullable: Type = 1; + pub const CXTypeNullability_Unspecified: Type = 2; + pub const CXTypeNullability_Invalid: Type = 3; + pub const CXTypeNullability_NullableResult: Type = 4; +} +extern "C" { + pub fn clang_Type_getNullability(T: CXType) -> CXTypeNullabilityKind::Type; +} +pub mod CXTypeLayoutError { + pub type Type = i32; + pub const CXTypeLayoutError_Invalid: Type = -1; + pub const CXTypeLayoutError_Incomplete: Type = -2; + pub const CXTypeLayoutError_Dependent: Type = -3; + pub const CXTypeLayoutError_NotConstantSize: Type = -4; + pub const CXTypeLayoutError_InvalidFieldName: Type = -5; + pub const CXTypeLayoutError_Undeduced: Type = -6; +} +extern "C" { + pub fn clang_Type_getAlignOf(T: CXType) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn clang_Type_getClassType(T: CXType) -> CXType; +} +extern "C" { + pub fn clang_Type_getSizeOf(T: CXType) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn clang_Type_getOffsetOf( + T: CXType, + S: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn clang_Type_getModifiedType(T: CXType) -> CXType; +} +extern "C" { + pub fn clang_Type_getValueType(CT: CXType) -> CXType; +} +extern "C" { + pub fn clang_Cursor_getOffsetOfField( + C: CXCursor, + ) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn clang_Cursor_isAnonymous(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_isAnonymousRecordDecl( + C: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_isInlineNamespace( + C: CXCursor, + ) -> ::std::os::raw::c_uint; +} +pub mod CXRefQualifierKind { + pub type Type = u32; + pub const CXRefQualifier_None: Type = 0; + pub const CXRefQualifier_LValue: Type = 1; + pub const CXRefQualifier_RValue: Type = 2; +} +extern "C" { + pub fn clang_Type_getNumTemplateArguments( + T: CXType, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_Type_getTemplateArgumentAsType( + T: CXType, + i: ::std::os::raw::c_uint, + ) -> CXType; +} +extern "C" { + pub fn clang_Type_getCXXRefQualifier(T: CXType) + -> CXRefQualifierKind::Type; +} +extern "C" { + pub fn clang_Cursor_isBitField(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_isVirtualBase(arg1: CXCursor) -> ::std::os::raw::c_uint; +} +pub mod CX_CXXAccessSpecifier { + pub type Type = u32; + pub const CX_CXXInvalidAccessSpecifier: Type = 0; + pub const CX_CXXPublic: Type = 1; + pub const CX_CXXProtected: Type = 2; + pub const CX_CXXPrivate: Type = 3; +} +extern "C" { + pub fn clang_getCXXAccessSpecifier( + arg1: CXCursor, + ) -> CX_CXXAccessSpecifier::Type; +} +pub mod CX_StorageClass { + pub type Type = u32; + pub const CX_SC_Invalid: Type = 0; + pub const CX_SC_None: Type = 1; + pub const CX_SC_Extern: Type = 2; + pub const CX_SC_Static: Type = 3; + pub const CX_SC_PrivateExtern: Type = 4; + pub const CX_SC_OpenCLWorkGroupLocal: Type = 5; + pub const CX_SC_Auto: Type = 6; + pub const CX_SC_Register: Type = 7; +} +extern "C" { + pub fn clang_Cursor_getStorageClass( + arg1: CXCursor, + ) -> CX_StorageClass::Type; +} +extern "C" { + pub fn clang_getNumOverloadedDecls( + cursor: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getOverloadedDecl( + cursor: CXCursor, + index: ::std::os::raw::c_uint, + ) -> CXCursor; +} +extern "C" { + pub fn clang_getIBOutletCollectionType(arg1: CXCursor) -> CXType; +} +pub mod CXChildVisitResult { + pub type Type = u32; + pub const CXChildVisit_Break: Type = 0; + pub const CXChildVisit_Continue: Type = 1; + pub const CXChildVisit_Recurse: Type = 2; +} +pub type CXCursorVisitor = ::std::option::Option< + unsafe extern "C" fn( + cursor: CXCursor, + parent: CXCursor, + client_data: CXClientData, + ) -> CXChildVisitResult::Type, +>; +extern "C" { + pub fn clang_visitChildren( + parent: CXCursor, + visitor: CXCursorVisitor, + client_data: CXClientData, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getCursorUSR(arg1: CXCursor) -> CXString; +} +extern "C" { + pub fn clang_constructUSR_ObjCClass( + class_name: *const ::std::os::raw::c_char, + ) -> CXString; +} +extern "C" { + pub fn clang_constructUSR_ObjCCategory( + class_name: *const ::std::os::raw::c_char, + category_name: *const ::std::os::raw::c_char, + ) -> CXString; +} +extern "C" { + pub fn clang_constructUSR_ObjCProtocol( + protocol_name: *const ::std::os::raw::c_char, + ) -> CXString; +} +extern "C" { + pub fn clang_constructUSR_ObjCIvar( + name: *const ::std::os::raw::c_char, + classUSR: CXString, + ) -> CXString; +} +extern "C" { + pub fn clang_constructUSR_ObjCMethod( + name: *const ::std::os::raw::c_char, + isInstanceMethod: ::std::os::raw::c_uint, + classUSR: CXString, + ) -> CXString; +} +extern "C" { + pub fn clang_constructUSR_ObjCProperty( + property: *const ::std::os::raw::c_char, + classUSR: CXString, + ) -> CXString; +} +extern "C" { + pub fn clang_getCursorSpelling(arg1: CXCursor) -> CXString; +} +extern "C" { + pub fn clang_Cursor_getSpellingNameRange( + arg1: CXCursor, + pieceIndex: ::std::os::raw::c_uint, + options: ::std::os::raw::c_uint, + ) -> CXSourceRange; +} +pub type CXPrintingPolicy = *mut ::std::os::raw::c_void; +pub mod CXPrintingPolicyProperty { + pub type Type = u32; + pub const CXPrintingPolicy_Indentation: Type = 0; + pub const CXPrintingPolicy_SuppressSpecifiers: Type = 1; + pub const CXPrintingPolicy_SuppressTagKeyword: Type = 2; + pub const CXPrintingPolicy_IncludeTagDefinition: Type = 3; + pub const CXPrintingPolicy_SuppressScope: Type = 4; + pub const CXPrintingPolicy_SuppressUnwrittenScope: Type = 5; + pub const CXPrintingPolicy_SuppressInitializers: Type = 6; + pub const CXPrintingPolicy_ConstantArraySizeAsWritten: Type = 7; + pub const CXPrintingPolicy_AnonymousTagLocations: Type = 8; + pub const CXPrintingPolicy_SuppressStrongLifetime: Type = 9; + pub const CXPrintingPolicy_SuppressLifetimeQualifiers: Type = 10; + pub const CXPrintingPolicy_SuppressTemplateArgsInCXXConstructors: Type = 11; + pub const CXPrintingPolicy_Bool: Type = 12; + pub const CXPrintingPolicy_Restrict: Type = 13; + pub const CXPrintingPolicy_Alignof: Type = 14; + pub const CXPrintingPolicy_UnderscoreAlignof: Type = 15; + pub const CXPrintingPolicy_UseVoidForZeroParams: Type = 16; + pub const CXPrintingPolicy_TerseOutput: Type = 17; + pub const CXPrintingPolicy_PolishForDeclaration: Type = 18; + pub const CXPrintingPolicy_Half: Type = 19; + pub const CXPrintingPolicy_MSWChar: Type = 20; + pub const CXPrintingPolicy_IncludeNewlines: Type = 21; + pub const CXPrintingPolicy_MSVCFormatting: Type = 22; + pub const CXPrintingPolicy_ConstantsAsWritten: Type = 23; + pub const CXPrintingPolicy_SuppressImplicitBase: Type = 24; + pub const CXPrintingPolicy_FullyQualifiedName: Type = 25; + pub const CXPrintingPolicy_LastProperty: Type = 25; +} +extern "C" { + pub fn clang_PrintingPolicy_getProperty( + Policy: CXPrintingPolicy, + Property: CXPrintingPolicyProperty::Type, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_PrintingPolicy_setProperty( + Policy: CXPrintingPolicy, + Property: CXPrintingPolicyProperty::Type, + Value: ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_getCursorPrintingPolicy(arg1: CXCursor) -> CXPrintingPolicy; +} +extern "C" { + pub fn clang_PrintingPolicy_dispose(Policy: CXPrintingPolicy); +} +extern "C" { + pub fn clang_getCursorPrettyPrinted( + Cursor: CXCursor, + Policy: CXPrintingPolicy, + ) -> CXString; +} +extern "C" { + pub fn clang_getCursorDisplayName(arg1: CXCursor) -> CXString; +} +extern "C" { + pub fn clang_getCursorReferenced(arg1: CXCursor) -> CXCursor; +} +extern "C" { + pub fn clang_getCursorDefinition(arg1: CXCursor) -> CXCursor; +} +extern "C" { + pub fn clang_isCursorDefinition(arg1: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getCanonicalCursor(arg1: CXCursor) -> CXCursor; +} +extern "C" { + pub fn clang_Cursor_getObjCSelectorIndex( + arg1: CXCursor, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_Cursor_isDynamicCall(C: CXCursor) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_Cursor_getReceiverType(C: CXCursor) -> CXType; +} +pub mod CXObjCPropertyAttrKind { + pub type Type = u32; + pub const CXObjCPropertyAttr_noattr: Type = 0; + pub const CXObjCPropertyAttr_readonly: Type = 1; + pub const CXObjCPropertyAttr_getter: Type = 2; + pub const CXObjCPropertyAttr_assign: Type = 4; + pub const CXObjCPropertyAttr_readwrite: Type = 8; + pub const CXObjCPropertyAttr_retain: Type = 16; + pub const CXObjCPropertyAttr_copy: Type = 32; + pub const CXObjCPropertyAttr_nonatomic: Type = 64; + pub const CXObjCPropertyAttr_setter: Type = 128; + pub const CXObjCPropertyAttr_atomic: Type = 256; + pub const CXObjCPropertyAttr_weak: Type = 512; + pub const CXObjCPropertyAttr_strong: Type = 1024; + pub const CXObjCPropertyAttr_unsafe_unretained: Type = 2048; + pub const CXObjCPropertyAttr_class: Type = 4096; +} +extern "C" { + pub fn clang_Cursor_getObjCPropertyAttributes( + C: CXCursor, + reserved: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_getObjCPropertyGetterName(C: CXCursor) -> CXString; +} +extern "C" { + pub fn clang_Cursor_getObjCPropertySetterName(C: CXCursor) -> CXString; +} +pub mod CXObjCDeclQualifierKind { + pub type Type = u32; + pub const CXObjCDeclQualifier_None: Type = 0; + pub const CXObjCDeclQualifier_In: Type = 1; + pub const CXObjCDeclQualifier_Inout: Type = 2; + pub const CXObjCDeclQualifier_Out: Type = 4; + pub const CXObjCDeclQualifier_Bycopy: Type = 8; + pub const CXObjCDeclQualifier_Byref: Type = 16; + pub const CXObjCDeclQualifier_Oneway: Type = 32; +} +extern "C" { + pub fn clang_Cursor_getObjCDeclQualifiers( + C: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_isObjCOptional(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_isVariadic(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_isExternalSymbol( + C: CXCursor, + language: *mut CXString, + definedIn: *mut CXString, + isGenerated: *mut ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Cursor_getCommentRange(C: CXCursor) -> CXSourceRange; +} +extern "C" { + pub fn clang_Cursor_getRawCommentText(C: CXCursor) -> CXString; +} +extern "C" { + pub fn clang_Cursor_getBriefCommentText(C: CXCursor) -> CXString; +} +extern "C" { + pub fn clang_Cursor_getMangling(arg1: CXCursor) -> CXString; +} +extern "C" { + pub fn clang_Cursor_getCXXManglings(arg1: CXCursor) -> *mut CXStringSet; +} +extern "C" { + pub fn clang_Cursor_getObjCManglings(arg1: CXCursor) -> *mut CXStringSet; +} +pub type CXModule = *mut ::std::os::raw::c_void; +extern "C" { + pub fn clang_Cursor_getModule(C: CXCursor) -> CXModule; +} +extern "C" { + pub fn clang_getModuleForFile( + arg1: CXTranslationUnit, + arg2: CXFile, + ) -> CXModule; +} +extern "C" { + pub fn clang_Module_getASTFile(Module: CXModule) -> CXFile; +} +extern "C" { + pub fn clang_Module_getParent(Module: CXModule) -> CXModule; +} +extern "C" { + pub fn clang_Module_getName(Module: CXModule) -> CXString; +} +extern "C" { + pub fn clang_Module_getFullName(Module: CXModule) -> CXString; +} +extern "C" { + pub fn clang_Module_isSystem(Module: CXModule) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_Module_getNumTopLevelHeaders( + arg1: CXTranslationUnit, + Module: CXModule, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Module_getTopLevelHeader( + arg1: CXTranslationUnit, + Module: CXModule, + Index: ::std::os::raw::c_uint, + ) -> CXFile; +} +extern "C" { + pub fn clang_CXXConstructor_isConvertingConstructor( + C: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXXConstructor_isCopyConstructor( + C: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXXConstructor_isDefaultConstructor( + C: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXXConstructor_isMoveConstructor( + C: CXCursor, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXXField_isMutable(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXXMethod_isDefaulted(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXXMethod_isPureVirtual(C: CXCursor) + -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXXMethod_isStatic(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXXMethod_isVirtual(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXXRecord_isAbstract(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_EnumDecl_isScoped(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_CXXMethod_isConst(C: CXCursor) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getTemplateCursorKind(C: CXCursor) -> CXCursorKind::Type; +} +extern "C" { + pub fn clang_getSpecializedCursorTemplate(C: CXCursor) -> CXCursor; +} +extern "C" { + pub fn clang_getCursorReferenceNameRange( + C: CXCursor, + NameFlags: ::std::os::raw::c_uint, + PieceIndex: ::std::os::raw::c_uint, + ) -> CXSourceRange; +} +pub mod CXNameRefFlags { + pub type Type = u32; + pub const CXNameRange_WantQualifier: Type = 1; + pub const CXNameRange_WantTemplateArgs: Type = 2; + pub const CXNameRange_WantSinglePiece: Type = 4; +} +pub mod CXTokenKind { + pub type Type = u32; + pub const CXToken_Punctuation: Type = 0; + pub const CXToken_Keyword: Type = 1; + pub const CXToken_Identifier: Type = 2; + pub const CXToken_Literal: Type = 3; + pub const CXToken_Comment: Type = 4; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXToken { + pub int_data: [::std::os::raw::c_uint; 4usize], + pub ptr_data: *mut ::std::os::raw::c_void, +} +#[test] +fn bindgen_test_layout_CXToken() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(CXToken)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXToken)) + ); + fn test_field_int_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).int_data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXToken), + "::", + stringify!(int_data) + ) + ); + } + test_field_int_data(); + fn test_field_ptr_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr_data) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXToken), + "::", + stringify!(ptr_data) + ) + ); + } + test_field_ptr_data(); +} +extern "C" { + pub fn clang_getToken( + TU: CXTranslationUnit, + Location: CXSourceLocation, + ) -> *mut CXToken; +} +extern "C" { + pub fn clang_getTokenKind(arg1: CXToken) -> CXTokenKind::Type; +} +extern "C" { + pub fn clang_getTokenSpelling( + arg1: CXTranslationUnit, + arg2: CXToken, + ) -> CXString; +} +extern "C" { + pub fn clang_getTokenLocation( + arg1: CXTranslationUnit, + arg2: CXToken, + ) -> CXSourceLocation; +} +extern "C" { + pub fn clang_getTokenExtent( + arg1: CXTranslationUnit, + arg2: CXToken, + ) -> CXSourceRange; +} +extern "C" { + pub fn clang_tokenize( + TU: CXTranslationUnit, + Range: CXSourceRange, + Tokens: *mut *mut CXToken, + NumTokens: *mut ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_annotateTokens( + TU: CXTranslationUnit, + Tokens: *mut CXToken, + NumTokens: ::std::os::raw::c_uint, + Cursors: *mut CXCursor, + ); +} +extern "C" { + pub fn clang_disposeTokens( + TU: CXTranslationUnit, + Tokens: *mut CXToken, + NumTokens: ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_getCursorKindSpelling(Kind: CXCursorKind::Type) -> CXString; +} +extern "C" { + pub fn clang_getDefinitionSpellingAndExtent( + arg1: CXCursor, + startBuf: *mut *const ::std::os::raw::c_char, + endBuf: *mut *const ::std::os::raw::c_char, + startLine: *mut ::std::os::raw::c_uint, + startColumn: *mut ::std::os::raw::c_uint, + endLine: *mut ::std::os::raw::c_uint, + endColumn: *mut ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_enableStackTraces(); +} +extern "C" { + pub fn clang_executeOnThread( + fn_: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + user_data: *mut ::std::os::raw::c_void, + stack_size: ::std::os::raw::c_uint, + ); +} +pub type CXCompletionString = *mut ::std::os::raw::c_void; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXCompletionResult { + pub CursorKind: CXCursorKind::Type, + pub CompletionString: CXCompletionString, +} +#[test] +fn bindgen_test_layout_CXCompletionResult() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(CXCompletionResult)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXCompletionResult)) + ); + fn test_field_CursorKind() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).CursorKind) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXCompletionResult), + "::", + stringify!(CursorKind) + ) + ); + } + test_field_CursorKind(); + fn test_field_CompletionString() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).CompletionString) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXCompletionResult), + "::", + stringify!(CompletionString) + ) + ); + } + test_field_CompletionString(); +} +pub mod CXCompletionChunkKind { + pub type Type = u32; + pub const CXCompletionChunk_Optional: Type = 0; + pub const CXCompletionChunk_TypedText: Type = 1; + pub const CXCompletionChunk_Text: Type = 2; + pub const CXCompletionChunk_Placeholder: Type = 3; + pub const CXCompletionChunk_Informative: Type = 4; + pub const CXCompletionChunk_CurrentParameter: Type = 5; + pub const CXCompletionChunk_LeftParen: Type = 6; + pub const CXCompletionChunk_RightParen: Type = 7; + pub const CXCompletionChunk_LeftBracket: Type = 8; + pub const CXCompletionChunk_RightBracket: Type = 9; + pub const CXCompletionChunk_LeftBrace: Type = 10; + pub const CXCompletionChunk_RightBrace: Type = 11; + pub const CXCompletionChunk_LeftAngle: Type = 12; + pub const CXCompletionChunk_RightAngle: Type = 13; + pub const CXCompletionChunk_Comma: Type = 14; + pub const CXCompletionChunk_ResultType: Type = 15; + pub const CXCompletionChunk_Colon: Type = 16; + pub const CXCompletionChunk_SemiColon: Type = 17; + pub const CXCompletionChunk_Equal: Type = 18; + pub const CXCompletionChunk_HorizontalSpace: Type = 19; + pub const CXCompletionChunk_VerticalSpace: Type = 20; +} +extern "C" { + pub fn clang_getCompletionChunkKind( + completion_string: CXCompletionString, + chunk_number: ::std::os::raw::c_uint, + ) -> CXCompletionChunkKind::Type; +} +extern "C" { + pub fn clang_getCompletionChunkText( + completion_string: CXCompletionString, + chunk_number: ::std::os::raw::c_uint, + ) -> CXString; +} +extern "C" { + pub fn clang_getCompletionChunkCompletionString( + completion_string: CXCompletionString, + chunk_number: ::std::os::raw::c_uint, + ) -> CXCompletionString; +} +extern "C" { + pub fn clang_getNumCompletionChunks( + completion_string: CXCompletionString, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getCompletionPriority( + completion_string: CXCompletionString, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getCompletionAvailability( + completion_string: CXCompletionString, + ) -> CXAvailabilityKind::Type; +} +extern "C" { + pub fn clang_getCompletionNumAnnotations( + completion_string: CXCompletionString, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getCompletionAnnotation( + completion_string: CXCompletionString, + annotation_number: ::std::os::raw::c_uint, + ) -> CXString; +} +extern "C" { + pub fn clang_getCompletionParent( + completion_string: CXCompletionString, + kind: *mut CXCursorKind::Type, + ) -> CXString; +} +extern "C" { + pub fn clang_getCompletionBriefComment( + completion_string: CXCompletionString, + ) -> CXString; +} +extern "C" { + pub fn clang_getCursorCompletionString( + cursor: CXCursor, + ) -> CXCompletionString; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXCodeCompleteResults { + pub Results: *mut CXCompletionResult, + pub NumResults: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_CXCodeCompleteResults() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(CXCodeCompleteResults)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXCodeCompleteResults)) + ); + fn test_field_Results() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Results) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXCodeCompleteResults), + "::", + stringify!(Results) + ) + ); + } + test_field_Results(); + fn test_field_NumResults() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).NumResults) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXCodeCompleteResults), + "::", + stringify!(NumResults) + ) + ); + } + test_field_NumResults(); +} +extern "C" { + pub fn clang_getCompletionNumFixIts( + results: *mut CXCodeCompleteResults, + completion_index: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_getCompletionFixIt( + results: *mut CXCodeCompleteResults, + completion_index: ::std::os::raw::c_uint, + fixit_index: ::std::os::raw::c_uint, + replacement_range: *mut CXSourceRange, + ) -> CXString; +} +pub mod CXCodeComplete_Flags { + pub type Type = u32; + pub const CXCodeComplete_IncludeMacros: Type = 1; + pub const CXCodeComplete_IncludeCodePatterns: Type = 2; + pub const CXCodeComplete_IncludeBriefComments: Type = 4; + pub const CXCodeComplete_SkipPreamble: Type = 8; + pub const CXCodeComplete_IncludeCompletionsWithFixIts: Type = 16; +} +pub mod CXCompletionContext { + pub type Type = u32; + pub const CXCompletionContext_Unexposed: Type = 0; + pub const CXCompletionContext_AnyType: Type = 1; + pub const CXCompletionContext_AnyValue: Type = 2; + pub const CXCompletionContext_ObjCObjectValue: Type = 4; + pub const CXCompletionContext_ObjCSelectorValue: Type = 8; + pub const CXCompletionContext_CXXClassTypeValue: Type = 16; + pub const CXCompletionContext_DotMemberAccess: Type = 32; + pub const CXCompletionContext_ArrowMemberAccess: Type = 64; + pub const CXCompletionContext_ObjCPropertyAccess: Type = 128; + pub const CXCompletionContext_EnumTag: Type = 256; + pub const CXCompletionContext_UnionTag: Type = 512; + pub const CXCompletionContext_StructTag: Type = 1024; + pub const CXCompletionContext_ClassTag: Type = 2048; + pub const CXCompletionContext_Namespace: Type = 4096; + pub const CXCompletionContext_NestedNameSpecifier: Type = 8192; + pub const CXCompletionContext_ObjCInterface: Type = 16384; + pub const CXCompletionContext_ObjCProtocol: Type = 32768; + pub const CXCompletionContext_ObjCCategory: Type = 65536; + pub const CXCompletionContext_ObjCInstanceMessage: Type = 131072; + pub const CXCompletionContext_ObjCClassMessage: Type = 262144; + pub const CXCompletionContext_ObjCSelectorName: Type = 524288; + pub const CXCompletionContext_MacroName: Type = 1048576; + pub const CXCompletionContext_NaturalLanguage: Type = 2097152; + pub const CXCompletionContext_IncludedFile: Type = 4194304; + pub const CXCompletionContext_Unknown: Type = 8388607; +} +extern "C" { + pub fn clang_defaultCodeCompleteOptions() -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_codeCompleteAt( + TU: CXTranslationUnit, + complete_filename: *const ::std::os::raw::c_char, + complete_line: ::std::os::raw::c_uint, + complete_column: ::std::os::raw::c_uint, + unsaved_files: *mut CXUnsavedFile, + num_unsaved_files: ::std::os::raw::c_uint, + options: ::std::os::raw::c_uint, + ) -> *mut CXCodeCompleteResults; +} +extern "C" { + pub fn clang_sortCodeCompletionResults( + Results: *mut CXCompletionResult, + NumResults: ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_disposeCodeCompleteResults( + Results: *mut CXCodeCompleteResults, + ); +} +extern "C" { + pub fn clang_codeCompleteGetNumDiagnostics( + Results: *mut CXCodeCompleteResults, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_codeCompleteGetDiagnostic( + Results: *mut CXCodeCompleteResults, + Index: ::std::os::raw::c_uint, + ) -> CXDiagnostic; +} +extern "C" { + pub fn clang_codeCompleteGetContexts( + Results: *mut CXCodeCompleteResults, + ) -> ::std::os::raw::c_ulonglong; +} +extern "C" { + pub fn clang_codeCompleteGetContainerKind( + Results: *mut CXCodeCompleteResults, + IsIncomplete: *mut ::std::os::raw::c_uint, + ) -> CXCursorKind::Type; +} +extern "C" { + pub fn clang_codeCompleteGetContainerUSR( + Results: *mut CXCodeCompleteResults, + ) -> CXString; +} +extern "C" { + pub fn clang_codeCompleteGetObjCSelector( + Results: *mut CXCodeCompleteResults, + ) -> CXString; +} +extern "C" { + pub fn clang_getClangVersion() -> CXString; +} +extern "C" { + pub fn clang_toggleCrashRecovery(isEnabled: ::std::os::raw::c_uint); +} +pub type CXInclusionVisitor = ::std::option::Option< + unsafe extern "C" fn( + included_file: CXFile, + inclusion_stack: *mut CXSourceLocation, + include_len: ::std::os::raw::c_uint, + client_data: CXClientData, + ), +>; +extern "C" { + pub fn clang_getInclusions( + tu: CXTranslationUnit, + visitor: CXInclusionVisitor, + client_data: CXClientData, + ); +} +pub mod CXEvalResultKind { + pub type Type = u32; + pub const CXEval_Int: Type = 1; + pub const CXEval_Float: Type = 2; + pub const CXEval_ObjCStrLiteral: Type = 3; + pub const CXEval_StrLiteral: Type = 4; + pub const CXEval_CFStr: Type = 5; + pub const CXEval_Other: Type = 6; + pub const CXEval_UnExposed: Type = 0; +} +pub type CXEvalResult = *mut ::std::os::raw::c_void; +extern "C" { + pub fn clang_Cursor_Evaluate(C: CXCursor) -> CXEvalResult; +} +extern "C" { + pub fn clang_EvalResult_getKind(E: CXEvalResult) -> CXEvalResultKind::Type; +} +extern "C" { + pub fn clang_EvalResult_getAsInt(E: CXEvalResult) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_EvalResult_getAsLongLong( + E: CXEvalResult, + ) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn clang_EvalResult_isUnsignedInt( + E: CXEvalResult, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_EvalResult_getAsUnsigned( + E: CXEvalResult, + ) -> ::std::os::raw::c_ulonglong; +} +extern "C" { + pub fn clang_EvalResult_getAsDouble(E: CXEvalResult) -> f64; +} +extern "C" { + pub fn clang_EvalResult_getAsStr( + E: CXEvalResult, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn clang_EvalResult_dispose(E: CXEvalResult); +} +pub type CXRemapping = *mut ::std::os::raw::c_void; +extern "C" { + pub fn clang_getRemappings( + path: *const ::std::os::raw::c_char, + ) -> CXRemapping; +} +extern "C" { + pub fn clang_getRemappingsFromFileList( + filePaths: *mut *const ::std::os::raw::c_char, + numFiles: ::std::os::raw::c_uint, + ) -> CXRemapping; +} +extern "C" { + pub fn clang_remap_getNumFiles(arg1: CXRemapping) + -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_remap_getFilenames( + arg1: CXRemapping, + index: ::std::os::raw::c_uint, + original: *mut CXString, + transformed: *mut CXString, + ); +} +extern "C" { + pub fn clang_remap_dispose(arg1: CXRemapping); +} +pub mod CXVisitorResult { + pub type Type = u32; + pub const CXVisit_Break: Type = 0; + pub const CXVisit_Continue: Type = 1; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXCursorAndRangeVisitor { + pub context: *mut ::std::os::raw::c_void, + pub visit: ::std::option::Option< + unsafe extern "C" fn( + context: *mut ::std::os::raw::c_void, + arg1: CXCursor, + arg2: CXSourceRange, + ) -> CXVisitorResult::Type, + >, +} +#[test] +fn bindgen_test_layout_CXCursorAndRangeVisitor() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(CXCursorAndRangeVisitor)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXCursorAndRangeVisitor)) + ); + fn test_field_context() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).context) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXCursorAndRangeVisitor), + "::", + stringify!(context) + ) + ); + } + test_field_context(); + fn test_field_visit() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).visit) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXCursorAndRangeVisitor), + "::", + stringify!(visit) + ) + ); + } + test_field_visit(); +} +pub mod CXResult { + pub type Type = u32; + pub const CXResult_Success: Type = 0; + pub const CXResult_Invalid: Type = 1; + pub const CXResult_VisitBreak: Type = 2; +} +extern "C" { + pub fn clang_findReferencesInFile( + cursor: CXCursor, + file: CXFile, + visitor: CXCursorAndRangeVisitor, + ) -> CXResult::Type; +} +extern "C" { + pub fn clang_findIncludesInFile( + TU: CXTranslationUnit, + file: CXFile, + visitor: CXCursorAndRangeVisitor, + ) -> CXResult::Type; +} +pub type CXIdxClientFile = *mut ::std::os::raw::c_void; +pub type CXIdxClientEntity = *mut ::std::os::raw::c_void; +pub type CXIdxClientContainer = *mut ::std::os::raw::c_void; +pub type CXIdxClientASTFile = *mut ::std::os::raw::c_void; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxLoc { + pub ptr_data: [*mut ::std::os::raw::c_void; 2usize], + pub int_data: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_CXIdxLoc() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(CXIdxLoc)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxLoc)) + ); + fn test_field_ptr_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr_data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxLoc), + "::", + stringify!(ptr_data) + ) + ); + } + test_field_ptr_data(); + fn test_field_int_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).int_data) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXIdxLoc), + "::", + stringify!(int_data) + ) + ); + } + test_field_int_data(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxIncludedFileInfo { + pub hashLoc: CXIdxLoc, + pub filename: *const ::std::os::raw::c_char, + pub file: CXFile, + pub isImport: ::std::os::raw::c_int, + pub isAngled: ::std::os::raw::c_int, + pub isModuleImport: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_CXIdxIncludedFileInfo() { + assert_eq!( + ::std::mem::size_of::(), + 56usize, + concat!("Size of: ", stringify!(CXIdxIncludedFileInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxIncludedFileInfo)) + ); + fn test_field_hashLoc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hashLoc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxIncludedFileInfo), + "::", + stringify!(hashLoc) + ) + ); + } + test_field_hashLoc(); + fn test_field_filename() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).filename) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(CXIdxIncludedFileInfo), + "::", + stringify!(filename) + ) + ); + } + test_field_filename(); + fn test_field_file() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).file) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(CXIdxIncludedFileInfo), + "::", + stringify!(file) + ) + ); + } + test_field_file(); + fn test_field_isImport() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).isImport) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(CXIdxIncludedFileInfo), + "::", + stringify!(isImport) + ) + ); + } + test_field_isImport(); + fn test_field_isAngled() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).isAngled) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(CXIdxIncludedFileInfo), + "::", + stringify!(isAngled) + ) + ); + } + test_field_isAngled(); + fn test_field_isModuleImport() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).isModuleImport) as usize - + ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(CXIdxIncludedFileInfo), + "::", + stringify!(isModuleImport) + ) + ); + } + test_field_isModuleImport(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxImportedASTFileInfo { + pub file: CXFile, + pub module: CXModule, + pub loc: CXIdxLoc, + pub isImplicit: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_CXIdxImportedASTFileInfo() { + assert_eq!( + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(CXIdxImportedASTFileInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxImportedASTFileInfo)) + ); + fn test_field_file() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).file) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxImportedASTFileInfo), + "::", + stringify!(file) + ) + ); + } + test_field_file(); + fn test_field_module() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).module) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxImportedASTFileInfo), + "::", + stringify!(module) + ) + ); + } + test_field_module(); + fn test_field_loc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).loc) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXIdxImportedASTFileInfo), + "::", + stringify!(loc) + ) + ); + } + test_field_loc(); + fn test_field_isImplicit() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).isImplicit) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(CXIdxImportedASTFileInfo), + "::", + stringify!(isImplicit) + ) + ); + } + test_field_isImplicit(); +} +pub mod CXIdxEntityKind { + pub type Type = u32; + pub const CXIdxEntity_Unexposed: Type = 0; + pub const CXIdxEntity_Typedef: Type = 1; + pub const CXIdxEntity_Function: Type = 2; + pub const CXIdxEntity_Variable: Type = 3; + pub const CXIdxEntity_Field: Type = 4; + pub const CXIdxEntity_EnumConstant: Type = 5; + pub const CXIdxEntity_ObjCClass: Type = 6; + pub const CXIdxEntity_ObjCProtocol: Type = 7; + pub const CXIdxEntity_ObjCCategory: Type = 8; + pub const CXIdxEntity_ObjCInstanceMethod: Type = 9; + pub const CXIdxEntity_ObjCClassMethod: Type = 10; + pub const CXIdxEntity_ObjCProperty: Type = 11; + pub const CXIdxEntity_ObjCIvar: Type = 12; + pub const CXIdxEntity_Enum: Type = 13; + pub const CXIdxEntity_Struct: Type = 14; + pub const CXIdxEntity_Union: Type = 15; + pub const CXIdxEntity_CXXClass: Type = 16; + pub const CXIdxEntity_CXXNamespace: Type = 17; + pub const CXIdxEntity_CXXNamespaceAlias: Type = 18; + pub const CXIdxEntity_CXXStaticVariable: Type = 19; + pub const CXIdxEntity_CXXStaticMethod: Type = 20; + pub const CXIdxEntity_CXXInstanceMethod: Type = 21; + pub const CXIdxEntity_CXXConstructor: Type = 22; + pub const CXIdxEntity_CXXDestructor: Type = 23; + pub const CXIdxEntity_CXXConversionFunction: Type = 24; + pub const CXIdxEntity_CXXTypeAlias: Type = 25; + pub const CXIdxEntity_CXXInterface: Type = 26; +} +pub mod CXIdxEntityLanguage { + pub type Type = u32; + pub const CXIdxEntityLang_None: Type = 0; + pub const CXIdxEntityLang_C: Type = 1; + pub const CXIdxEntityLang_ObjC: Type = 2; + pub const CXIdxEntityLang_CXX: Type = 3; + pub const CXIdxEntityLang_Swift: Type = 4; +} +pub mod CXIdxEntityCXXTemplateKind { + pub type Type = u32; + pub const CXIdxEntity_NonTemplate: Type = 0; + pub const CXIdxEntity_Template: Type = 1; + pub const CXIdxEntity_TemplatePartialSpecialization: Type = 2; + pub const CXIdxEntity_TemplateSpecialization: Type = 3; +} +pub mod CXIdxAttrKind { + pub type Type = u32; + pub const CXIdxAttr_Unexposed: Type = 0; + pub const CXIdxAttr_IBAction: Type = 1; + pub const CXIdxAttr_IBOutlet: Type = 2; + pub const CXIdxAttr_IBOutletCollection: Type = 3; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxAttrInfo { + pub kind: CXIdxAttrKind::Type, + pub cursor: CXCursor, + pub loc: CXIdxLoc, +} +#[test] +fn bindgen_test_layout_CXIdxAttrInfo() { + assert_eq!( + ::std::mem::size_of::(), + 64usize, + concat!("Size of: ", stringify!(CXIdxAttrInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxAttrInfo)) + ); + fn test_field_kind() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).kind) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxAttrInfo), + "::", + stringify!(kind) + ) + ); + } + test_field_kind(); + fn test_field_cursor() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cursor) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxAttrInfo), + "::", + stringify!(cursor) + ) + ); + } + test_field_cursor(); + fn test_field_loc() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).loc) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(CXIdxAttrInfo), + "::", + stringify!(loc) + ) + ); + } + test_field_loc(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxEntityInfo { + pub kind: CXIdxEntityKind::Type, + pub templateKind: CXIdxEntityCXXTemplateKind::Type, + pub lang: CXIdxEntityLanguage::Type, + pub name: *const ::std::os::raw::c_char, + pub USR: *const ::std::os::raw::c_char, + pub cursor: CXCursor, + pub attributes: *const *const CXIdxAttrInfo, + pub numAttributes: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_CXIdxEntityInfo() { + assert_eq!( + ::std::mem::size_of::(), + 80usize, + concat!("Size of: ", stringify!(CXIdxEntityInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxEntityInfo)) + ); + fn test_field_kind() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).kind) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityInfo), + "::", + stringify!(kind) + ) + ); + } + test_field_kind(); + fn test_field_templateKind() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).templateKind) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityInfo), + "::", + stringify!(templateKind) + ) + ); + } + test_field_templateKind(); + fn test_field_lang() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lang) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityInfo), + "::", + stringify!(lang) + ) + ); + } + test_field_lang(); + fn test_field_name() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityInfo), + "::", + stringify!(name) + ) + ); + } + test_field_name(); + fn test_field_USR() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).USR) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityInfo), + "::", + stringify!(USR) + ) + ); + } + test_field_USR(); + fn test_field_cursor() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cursor) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityInfo), + "::", + stringify!(cursor) + ) + ); + } + test_field_cursor(); + fn test_field_attributes() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).attributes) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityInfo), + "::", + stringify!(attributes) + ) + ); + } + test_field_attributes(); + fn test_field_numAttributes() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).numAttributes) as usize - + ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityInfo), + "::", + stringify!(numAttributes) + ) + ); + } + test_field_numAttributes(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxContainerInfo { + pub cursor: CXCursor, +} +#[test] +fn bindgen_test_layout_CXIdxContainerInfo() { + assert_eq!( + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(CXIdxContainerInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxContainerInfo)) + ); + fn test_field_cursor() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cursor) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxContainerInfo), + "::", + stringify!(cursor) + ) + ); + } + test_field_cursor(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxIBOutletCollectionAttrInfo { + pub attrInfo: *const CXIdxAttrInfo, + pub objcClass: *const CXIdxEntityInfo, + pub classCursor: CXCursor, + pub classLoc: CXIdxLoc, +} +#[test] +fn bindgen_test_layout_CXIdxIBOutletCollectionAttrInfo() { + assert_eq!( + ::std::mem::size_of::(), + 72usize, + concat!("Size of: ", stringify!(CXIdxIBOutletCollectionAttrInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxIBOutletCollectionAttrInfo)) + ); + fn test_field_attrInfo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + CXIdxIBOutletCollectionAttrInfo, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).attrInfo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxIBOutletCollectionAttrInfo), + "::", + stringify!(attrInfo) + ) + ); + } + test_field_attrInfo(); + fn test_field_objcClass() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + CXIdxIBOutletCollectionAttrInfo, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).objcClass) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxIBOutletCollectionAttrInfo), + "::", + stringify!(objcClass) + ) + ); + } + test_field_objcClass(); + fn test_field_classCursor() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + CXIdxIBOutletCollectionAttrInfo, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).classCursor) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXIdxIBOutletCollectionAttrInfo), + "::", + stringify!(classCursor) + ) + ); + } + test_field_classCursor(); + fn test_field_classLoc() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + CXIdxIBOutletCollectionAttrInfo, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).classLoc) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(CXIdxIBOutletCollectionAttrInfo), + "::", + stringify!(classLoc) + ) + ); + } + test_field_classLoc(); +} +pub mod CXIdxDeclInfoFlags { + pub type Type = u32; + pub const CXIdxDeclFlag_Skipped: Type = 1; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxDeclInfo { + pub entityInfo: *const CXIdxEntityInfo, + pub cursor: CXCursor, + pub loc: CXIdxLoc, + pub semanticContainer: *const CXIdxContainerInfo, + pub lexicalContainer: *const CXIdxContainerInfo, + pub isRedeclaration: ::std::os::raw::c_int, + pub isDefinition: ::std::os::raw::c_int, + pub isContainer: ::std::os::raw::c_int, + pub declAsContainer: *const CXIdxContainerInfo, + pub isImplicit: ::std::os::raw::c_int, + pub attributes: *const *const CXIdxAttrInfo, + pub numAttributes: ::std::os::raw::c_uint, + pub flags: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_CXIdxDeclInfo() { + assert_eq!( + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(CXIdxDeclInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxDeclInfo)) + ); + fn test_field_entityInfo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).entityInfo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(entityInfo) + ) + ); + } + test_field_entityInfo(); + fn test_field_cursor() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cursor) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(cursor) + ) + ); + } + test_field_cursor(); + fn test_field_loc() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).loc) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(loc) + ) + ); + } + test_field_loc(); + fn test_field_semanticContainer() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).semanticContainer) as usize - + ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(semanticContainer) + ) + ); + } + test_field_semanticContainer(); + fn test_field_lexicalContainer() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lexicalContainer) as usize - + ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(lexicalContainer) + ) + ); + } + test_field_lexicalContainer(); + fn test_field_isRedeclaration() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).isRedeclaration) as usize - + ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(isRedeclaration) + ) + ); + } + test_field_isRedeclaration(); + fn test_field_isDefinition() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).isDefinition) as usize - + ptr as usize + }, + 84usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(isDefinition) + ) + ); + } + test_field_isDefinition(); + fn test_field_isContainer() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).isContainer) as usize - ptr as usize + }, + 88usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(isContainer) + ) + ); + } + test_field_isContainer(); + fn test_field_declAsContainer() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).declAsContainer) as usize - + ptr as usize + }, + 96usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(declAsContainer) + ) + ); + } + test_field_declAsContainer(); + fn test_field_isImplicit() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).isImplicit) as usize - ptr as usize + }, + 104usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(isImplicit) + ) + ); + } + test_field_isImplicit(); + fn test_field_attributes() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).attributes) as usize - ptr as usize + }, + 112usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(attributes) + ) + ); + } + test_field_attributes(); + fn test_field_numAttributes() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).numAttributes) as usize - + ptr as usize + }, + 120usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(numAttributes) + ) + ); + } + test_field_numAttributes(); + fn test_field_flags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize + }, + 124usize, + concat!( + "Offset of field: ", + stringify!(CXIdxDeclInfo), + "::", + stringify!(flags) + ) + ); + } + test_field_flags(); +} +pub mod CXIdxObjCContainerKind { + pub type Type = u32; + pub const CXIdxObjCContainer_ForwardRef: Type = 0; + pub const CXIdxObjCContainer_Interface: Type = 1; + pub const CXIdxObjCContainer_Implementation: Type = 2; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxObjCContainerDeclInfo { + pub declInfo: *const CXIdxDeclInfo, + pub kind: CXIdxObjCContainerKind::Type, +} +#[test] +fn bindgen_test_layout_CXIdxObjCContainerDeclInfo() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(CXIdxObjCContainerDeclInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxObjCContainerDeclInfo)) + ); + fn test_field_declInfo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + CXIdxObjCContainerDeclInfo, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).declInfo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCContainerDeclInfo), + "::", + stringify!(declInfo) + ) + ); + } + test_field_declInfo(); + fn test_field_kind() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + CXIdxObjCContainerDeclInfo, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).kind) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCContainerDeclInfo), + "::", + stringify!(kind) + ) + ); + } + test_field_kind(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxBaseClassInfo { + pub base: *const CXIdxEntityInfo, + pub cursor: CXCursor, + pub loc: CXIdxLoc, +} +#[test] +fn bindgen_test_layout_CXIdxBaseClassInfo() { + assert_eq!( + ::std::mem::size_of::(), + 64usize, + concat!("Size of: ", stringify!(CXIdxBaseClassInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxBaseClassInfo)) + ); + fn test_field_base() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).base) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxBaseClassInfo), + "::", + stringify!(base) + ) + ); + } + test_field_base(); + fn test_field_cursor() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cursor) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxBaseClassInfo), + "::", + stringify!(cursor) + ) + ); + } + test_field_cursor(); + fn test_field_loc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).loc) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(CXIdxBaseClassInfo), + "::", + stringify!(loc) + ) + ); + } + test_field_loc(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxObjCProtocolRefInfo { + pub protocol: *const CXIdxEntityInfo, + pub cursor: CXCursor, + pub loc: CXIdxLoc, +} +#[test] +fn bindgen_test_layout_CXIdxObjCProtocolRefInfo() { + assert_eq!( + ::std::mem::size_of::(), + 64usize, + concat!("Size of: ", stringify!(CXIdxObjCProtocolRefInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxObjCProtocolRefInfo)) + ); + fn test_field_protocol() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).protocol) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCProtocolRefInfo), + "::", + stringify!(protocol) + ) + ); + } + test_field_protocol(); + fn test_field_cursor() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cursor) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCProtocolRefInfo), + "::", + stringify!(cursor) + ) + ); + } + test_field_cursor(); + fn test_field_loc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).loc) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCProtocolRefInfo), + "::", + stringify!(loc) + ) + ); + } + test_field_loc(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxObjCProtocolRefListInfo { + pub protocols: *const *const CXIdxObjCProtocolRefInfo, + pub numProtocols: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_CXIdxObjCProtocolRefListInfo() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(CXIdxObjCProtocolRefListInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxObjCProtocolRefListInfo)) + ); + fn test_field_protocols() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + CXIdxObjCProtocolRefListInfo, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).protocols) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCProtocolRefListInfo), + "::", + stringify!(protocols) + ) + ); + } + test_field_protocols(); + fn test_field_numProtocols() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + CXIdxObjCProtocolRefListInfo, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).numProtocols) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCProtocolRefListInfo), + "::", + stringify!(numProtocols) + ) + ); + } + test_field_numProtocols(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxObjCInterfaceDeclInfo { + pub containerInfo: *const CXIdxObjCContainerDeclInfo, + pub superInfo: *const CXIdxBaseClassInfo, + pub protocols: *const CXIdxObjCProtocolRefListInfo, +} +#[test] +fn bindgen_test_layout_CXIdxObjCInterfaceDeclInfo() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(CXIdxObjCInterfaceDeclInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxObjCInterfaceDeclInfo)) + ); + fn test_field_containerInfo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + CXIdxObjCInterfaceDeclInfo, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).containerInfo) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCInterfaceDeclInfo), + "::", + stringify!(containerInfo) + ) + ); + } + test_field_containerInfo(); + fn test_field_superInfo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + CXIdxObjCInterfaceDeclInfo, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).superInfo) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCInterfaceDeclInfo), + "::", + stringify!(superInfo) + ) + ); + } + test_field_superInfo(); + fn test_field_protocols() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + CXIdxObjCInterfaceDeclInfo, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).protocols) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCInterfaceDeclInfo), + "::", + stringify!(protocols) + ) + ); + } + test_field_protocols(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxObjCCategoryDeclInfo { + pub containerInfo: *const CXIdxObjCContainerDeclInfo, + pub objcClass: *const CXIdxEntityInfo, + pub classCursor: CXCursor, + pub classLoc: CXIdxLoc, + pub protocols: *const CXIdxObjCProtocolRefListInfo, +} +#[test] +fn bindgen_test_layout_CXIdxObjCCategoryDeclInfo() { + assert_eq!( + ::std::mem::size_of::(), + 80usize, + concat!("Size of: ", stringify!(CXIdxObjCCategoryDeclInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxObjCCategoryDeclInfo)) + ); + fn test_field_containerInfo() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < CXIdxObjCCategoryDeclInfo > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).containerInfo) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCCategoryDeclInfo), + "::", + stringify!(containerInfo) + ) + ); + } + test_field_containerInfo(); + fn test_field_objcClass() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < CXIdxObjCCategoryDeclInfo > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).objcClass) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCCategoryDeclInfo), + "::", + stringify!(objcClass) + ) + ); + } + test_field_objcClass(); + fn test_field_classCursor() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < CXIdxObjCCategoryDeclInfo > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).classCursor) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCCategoryDeclInfo), + "::", + stringify!(classCursor) + ) + ); + } + test_field_classCursor(); + fn test_field_classLoc() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < CXIdxObjCCategoryDeclInfo > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).classLoc) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCCategoryDeclInfo), + "::", + stringify!(classLoc) + ) + ); + } + test_field_classLoc(); + fn test_field_protocols() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < CXIdxObjCCategoryDeclInfo > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).protocols) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCCategoryDeclInfo), + "::", + stringify!(protocols) + ) + ); + } + test_field_protocols(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxObjCPropertyDeclInfo { + pub declInfo: *const CXIdxDeclInfo, + pub getter: *const CXIdxEntityInfo, + pub setter: *const CXIdxEntityInfo, +} +#[test] +fn bindgen_test_layout_CXIdxObjCPropertyDeclInfo() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(CXIdxObjCPropertyDeclInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxObjCPropertyDeclInfo)) + ); + fn test_field_declInfo() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < CXIdxObjCPropertyDeclInfo > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).declInfo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCPropertyDeclInfo), + "::", + stringify!(declInfo) + ) + ); + } + test_field_declInfo(); + fn test_field_getter() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < CXIdxObjCPropertyDeclInfo > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).getter) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCPropertyDeclInfo), + "::", + stringify!(getter) + ) + ); + } + test_field_getter(); + fn test_field_setter() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < CXIdxObjCPropertyDeclInfo > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).setter) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXIdxObjCPropertyDeclInfo), + "::", + stringify!(setter) + ) + ); + } + test_field_setter(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxCXXClassDeclInfo { + pub declInfo: *const CXIdxDeclInfo, + pub bases: *const *const CXIdxBaseClassInfo, + pub numBases: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_CXIdxCXXClassDeclInfo() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(CXIdxCXXClassDeclInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxCXXClassDeclInfo)) + ); + fn test_field_declInfo() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).declInfo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxCXXClassDeclInfo), + "::", + stringify!(declInfo) + ) + ); + } + test_field_declInfo(); + fn test_field_bases() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bases) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxCXXClassDeclInfo), + "::", + stringify!(bases) + ) + ); + } + test_field_bases(); + fn test_field_numBases() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).numBases) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(CXIdxCXXClassDeclInfo), + "::", + stringify!(numBases) + ) + ); + } + test_field_numBases(); +} +pub mod CXIdxEntityRefKind { + pub type Type = u32; + pub const CXIdxEntityRef_Direct: Type = 1; + pub const CXIdxEntityRef_Implicit: Type = 2; +} +pub mod CXSymbolRole { + pub type Type = u32; + pub const CXSymbolRole_None: Type = 0; + pub const CXSymbolRole_Declaration: Type = 1; + pub const CXSymbolRole_Definition: Type = 2; + pub const CXSymbolRole_Reference: Type = 4; + pub const CXSymbolRole_Read: Type = 8; + pub const CXSymbolRole_Write: Type = 16; + pub const CXSymbolRole_Call: Type = 32; + pub const CXSymbolRole_Dynamic: Type = 64; + pub const CXSymbolRole_AddressOf: Type = 128; + pub const CXSymbolRole_Implicit: Type = 256; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXIdxEntityRefInfo { + pub kind: CXIdxEntityRefKind::Type, + pub cursor: CXCursor, + pub loc: CXIdxLoc, + pub referencedEntity: *const CXIdxEntityInfo, + pub parentEntity: *const CXIdxEntityInfo, + pub container: *const CXIdxContainerInfo, + pub role: CXSymbolRole::Type, +} +#[test] +fn bindgen_test_layout_CXIdxEntityRefInfo() { + assert_eq!( + ::std::mem::size_of::(), + 96usize, + concat!("Size of: ", stringify!(CXIdxEntityRefInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXIdxEntityRefInfo)) + ); + fn test_field_kind() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).kind) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityRefInfo), + "::", + stringify!(kind) + ) + ); + } + test_field_kind(); + fn test_field_cursor() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cursor) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityRefInfo), + "::", + stringify!(cursor) + ) + ); + } + test_field_cursor(); + fn test_field_loc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).loc) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityRefInfo), + "::", + stringify!(loc) + ) + ); + } + test_field_loc(); + fn test_field_referencedEntity() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).referencedEntity) as usize - + ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityRefInfo), + "::", + stringify!(referencedEntity) + ) + ); + } + test_field_referencedEntity(); + fn test_field_parentEntity() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).parentEntity) as usize - + ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityRefInfo), + "::", + stringify!(parentEntity) + ) + ); + } + test_field_parentEntity(); + fn test_field_container() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).container) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityRefInfo), + "::", + stringify!(container) + ) + ); + } + test_field_container(); + fn test_field_role() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).role) as usize - ptr as usize + }, + 88usize, + concat!( + "Offset of field: ", + stringify!(CXIdxEntityRefInfo), + "::", + stringify!(role) + ) + ); + } + test_field_role(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct IndexerCallbacks { + pub abortQuery: ::std::option::Option< + unsafe extern "C" fn( + client_data: CXClientData, + reserved: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + pub diagnostic: ::std::option::Option< + unsafe extern "C" fn( + client_data: CXClientData, + arg1: CXDiagnosticSet, + reserved: *mut ::std::os::raw::c_void, + ), + >, + pub enteredMainFile: ::std::option::Option< + unsafe extern "C" fn( + client_data: CXClientData, + mainFile: CXFile, + reserved: *mut ::std::os::raw::c_void, + ) -> CXIdxClientFile, + >, + pub ppIncludedFile: ::std::option::Option< + unsafe extern "C" fn( + client_data: CXClientData, + arg1: *const CXIdxIncludedFileInfo, + ) -> CXIdxClientFile, + >, + pub importedASTFile: ::std::option::Option< + unsafe extern "C" fn( + client_data: CXClientData, + arg1: *const CXIdxImportedASTFileInfo, + ) -> CXIdxClientASTFile, + >, + pub startedTranslationUnit: ::std::option::Option< + unsafe extern "C" fn( + client_data: CXClientData, + reserved: *mut ::std::os::raw::c_void, + ) -> CXIdxClientContainer, + >, + pub indexDeclaration: ::std::option::Option< + unsafe extern "C" fn( + client_data: CXClientData, + arg1: *const CXIdxDeclInfo, + ), + >, + pub indexEntityReference: ::std::option::Option< + unsafe extern "C" fn( + client_data: CXClientData, + arg1: *const CXIdxEntityRefInfo, + ), + >, +} +#[test] +fn bindgen_test_layout_IndexerCallbacks() { + assert_eq!( + ::std::mem::size_of::(), + 64usize, + concat!("Size of: ", stringify!(IndexerCallbacks)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(IndexerCallbacks)) + ); + fn test_field_abortQuery() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).abortQuery) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IndexerCallbacks), + "::", + stringify!(abortQuery) + ) + ); + } + test_field_abortQuery(); + fn test_field_diagnostic() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).diagnostic) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IndexerCallbacks), + "::", + stringify!(diagnostic) + ) + ); + } + test_field_diagnostic(); + fn test_field_enteredMainFile() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enteredMainFile) as usize - + ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(IndexerCallbacks), + "::", + stringify!(enteredMainFile) + ) + ); + } + test_field_enteredMainFile(); + fn test_field_ppIncludedFile() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ppIncludedFile) as usize - + ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(IndexerCallbacks), + "::", + stringify!(ppIncludedFile) + ) + ); + } + test_field_ppIncludedFile(); + fn test_field_importedASTFile() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).importedASTFile) as usize - + ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(IndexerCallbacks), + "::", + stringify!(importedASTFile) + ) + ); + } + test_field_importedASTFile(); + fn test_field_startedTranslationUnit() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).startedTranslationUnit) as usize - + ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(IndexerCallbacks), + "::", + stringify!(startedTranslationUnit) + ) + ); + } + test_field_startedTranslationUnit(); + fn test_field_indexDeclaration() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).indexDeclaration) as usize - + ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(IndexerCallbacks), + "::", + stringify!(indexDeclaration) + ) + ); + } + test_field_indexDeclaration(); + fn test_field_indexEntityReference() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).indexEntityReference) as usize - + ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(IndexerCallbacks), + "::", + stringify!(indexEntityReference) + ) + ); + } + test_field_indexEntityReference(); +} +extern "C" { + pub fn clang_index_isEntityObjCContainerKind( + arg1: CXIdxEntityKind::Type, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_index_getObjCContainerDeclInfo( + arg1: *const CXIdxDeclInfo, + ) -> *const CXIdxObjCContainerDeclInfo; +} +extern "C" { + pub fn clang_index_getObjCInterfaceDeclInfo( + arg1: *const CXIdxDeclInfo, + ) -> *const CXIdxObjCInterfaceDeclInfo; +} +extern "C" { + pub fn clang_index_getObjCCategoryDeclInfo( + arg1: *const CXIdxDeclInfo, + ) -> *const CXIdxObjCCategoryDeclInfo; +} +extern "C" { + pub fn clang_index_getObjCProtocolRefListInfo( + arg1: *const CXIdxDeclInfo, + ) -> *const CXIdxObjCProtocolRefListInfo; +} +extern "C" { + pub fn clang_index_getObjCPropertyDeclInfo( + arg1: *const CXIdxDeclInfo, + ) -> *const CXIdxObjCPropertyDeclInfo; +} +extern "C" { + pub fn clang_index_getIBOutletCollectionAttrInfo( + arg1: *const CXIdxAttrInfo, + ) -> *const CXIdxIBOutletCollectionAttrInfo; +} +extern "C" { + pub fn clang_index_getCXXClassDeclInfo( + arg1: *const CXIdxDeclInfo, + ) -> *const CXIdxCXXClassDeclInfo; +} +extern "C" { + pub fn clang_index_getClientContainer( + arg1: *const CXIdxContainerInfo, + ) -> CXIdxClientContainer; +} +extern "C" { + pub fn clang_index_setClientContainer( + arg1: *const CXIdxContainerInfo, + arg2: CXIdxClientContainer, + ); +} +extern "C" { + pub fn clang_index_getClientEntity( + arg1: *const CXIdxEntityInfo, + ) -> CXIdxClientEntity; +} +extern "C" { + pub fn clang_index_setClientEntity( + arg1: *const CXIdxEntityInfo, + arg2: CXIdxClientEntity, + ); +} +pub type CXIndexAction = *mut ::std::os::raw::c_void; +extern "C" { + pub fn clang_IndexAction_create(CIdx: CXIndex) -> CXIndexAction; +} +extern "C" { + pub fn clang_IndexAction_dispose(arg1: CXIndexAction); +} +pub mod CXIndexOptFlags { + pub type Type = u32; + pub const CXIndexOpt_None: Type = 0; + pub const CXIndexOpt_SuppressRedundantRefs: Type = 1; + pub const CXIndexOpt_IndexFunctionLocalSymbols: Type = 2; + pub const CXIndexOpt_IndexImplicitTemplateInstantiations: Type = 4; + pub const CXIndexOpt_SuppressWarnings: Type = 8; + pub const CXIndexOpt_SkipParsedBodiesInSession: Type = 16; +} +extern "C" { + pub fn clang_indexSourceFile( + arg1: CXIndexAction, + client_data: CXClientData, + index_callbacks: *mut IndexerCallbacks, + index_callbacks_size: ::std::os::raw::c_uint, + index_options: ::std::os::raw::c_uint, + source_filename: *const ::std::os::raw::c_char, + command_line_args: *const *const ::std::os::raw::c_char, + num_command_line_args: ::std::os::raw::c_int, + unsaved_files: *mut CXUnsavedFile, + num_unsaved_files: ::std::os::raw::c_uint, + out_TU: *mut CXTranslationUnit, + TU_options: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_indexSourceFileFullArgv( + arg1: CXIndexAction, + client_data: CXClientData, + index_callbacks: *mut IndexerCallbacks, + index_callbacks_size: ::std::os::raw::c_uint, + index_options: ::std::os::raw::c_uint, + source_filename: *const ::std::os::raw::c_char, + command_line_args: *const *const ::std::os::raw::c_char, + num_command_line_args: ::std::os::raw::c_int, + unsaved_files: *mut CXUnsavedFile, + num_unsaved_files: ::std::os::raw::c_uint, + out_TU: *mut CXTranslationUnit, + TU_options: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_indexTranslationUnit( + arg1: CXIndexAction, + client_data: CXClientData, + index_callbacks: *mut IndexerCallbacks, + index_callbacks_size: ::std::os::raw::c_uint, + index_options: ::std::os::raw::c_uint, + arg2: CXTranslationUnit, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clang_indexLoc_getFileLocation( + loc: CXIdxLoc, + indexFile: *mut CXIdxClientFile, + file: *mut CXFile, + line: *mut ::std::os::raw::c_uint, + column: *mut ::std::os::raw::c_uint, + offset: *mut ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn clang_indexLoc_getCXSourceLocation( + loc: CXIdxLoc, + ) -> CXSourceLocation; +} +pub type CXFieldVisitor = ::std::option::Option< + unsafe extern "C" fn( + C: CXCursor, + client_data: CXClientData, + ) -> CXVisitorResult::Type, +>; +extern "C" { + pub fn clang_Type_visitFields( + T: CXType, + visitor: CXFieldVisitor, + client_data: CXClientData, + ) -> ::std::os::raw::c_uint; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CXComment { + pub ASTNode: *const ::std::os::raw::c_void, + pub TranslationUnit: CXTranslationUnit, +} +#[test] +fn bindgen_test_layout_CXComment() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(CXComment)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CXComment)) + ); + fn test_field_ASTNode() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ASTNode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CXComment), + "::", + stringify!(ASTNode) + ) + ); + } + test_field_ASTNode(); + fn test_field_TranslationUnit() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).TranslationUnit) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(CXComment), + "::", + stringify!(TranslationUnit) + ) + ); + } + test_field_TranslationUnit(); +} +extern "C" { + pub fn clang_Cursor_getParsedComment(C: CXCursor) -> CXComment; +} +pub mod CXCommentKind { + pub type Type = u32; + pub const CXComment_Null: Type = 0; + pub const CXComment_Text: Type = 1; + pub const CXComment_InlineCommand: Type = 2; + pub const CXComment_HTMLStartTag: Type = 3; + pub const CXComment_HTMLEndTag: Type = 4; + pub const CXComment_Paragraph: Type = 5; + pub const CXComment_BlockCommand: Type = 6; + pub const CXComment_ParamCommand: Type = 7; + pub const CXComment_TParamCommand: Type = 8; + pub const CXComment_VerbatimBlockCommand: Type = 9; + pub const CXComment_VerbatimBlockLine: Type = 10; + pub const CXComment_VerbatimLine: Type = 11; + pub const CXComment_FullComment: Type = 12; +} +pub mod CXCommentInlineCommandRenderKind { + pub type Type = u32; + pub const CXCommentInlineCommandRenderKind_Normal: Type = 0; + pub const CXCommentInlineCommandRenderKind_Bold: Type = 1; + pub const CXCommentInlineCommandRenderKind_Monospaced: Type = 2; + pub const CXCommentInlineCommandRenderKind_Emphasized: Type = 3; + pub const CXCommentInlineCommandRenderKind_Anchor: Type = 4; +} +pub mod CXCommentParamPassDirection { + pub type Type = u32; + pub const CXCommentParamPassDirection_In: Type = 0; + pub const CXCommentParamPassDirection_Out: Type = 1; + pub const CXCommentParamPassDirection_InOut: Type = 2; +} +extern "C" { + pub fn clang_Comment_getKind(Comment: CXComment) -> CXCommentKind::Type; +} +extern "C" { + pub fn clang_Comment_getNumChildren( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_Comment_getChild( + Comment: CXComment, + ChildIdx: ::std::os::raw::c_uint, + ) -> CXComment; +} +extern "C" { + pub fn clang_Comment_isWhitespace( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_InlineContentComment_hasTrailingNewline( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_TextComment_getText(Comment: CXComment) -> CXString; +} +extern "C" { + pub fn clang_InlineCommandComment_getCommandName( + Comment: CXComment, + ) -> CXString; +} +extern "C" { + pub fn clang_InlineCommandComment_getRenderKind( + Comment: CXComment, + ) -> CXCommentInlineCommandRenderKind::Type; +} +extern "C" { + pub fn clang_InlineCommandComment_getNumArgs( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_InlineCommandComment_getArgText( + Comment: CXComment, + ArgIdx: ::std::os::raw::c_uint, + ) -> CXString; +} +extern "C" { + pub fn clang_HTMLTagComment_getTagName(Comment: CXComment) -> CXString; +} +extern "C" { + pub fn clang_HTMLStartTagComment_isSelfClosing( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_HTMLStartTag_getNumAttrs( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_HTMLStartTag_getAttrName( + Comment: CXComment, + AttrIdx: ::std::os::raw::c_uint, + ) -> CXString; +} +extern "C" { + pub fn clang_HTMLStartTag_getAttrValue( + Comment: CXComment, + AttrIdx: ::std::os::raw::c_uint, + ) -> CXString; +} +extern "C" { + pub fn clang_BlockCommandComment_getCommandName( + Comment: CXComment, + ) -> CXString; +} +extern "C" { + pub fn clang_BlockCommandComment_getNumArgs( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_BlockCommandComment_getArgText( + Comment: CXComment, + ArgIdx: ::std::os::raw::c_uint, + ) -> CXString; +} +extern "C" { + pub fn clang_BlockCommandComment_getParagraph( + Comment: CXComment, + ) -> CXComment; +} +extern "C" { + pub fn clang_ParamCommandComment_getParamName( + Comment: CXComment, + ) -> CXString; +} +extern "C" { + pub fn clang_ParamCommandComment_isParamIndexValid( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_ParamCommandComment_getParamIndex( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_ParamCommandComment_isDirectionExplicit( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_ParamCommandComment_getDirection( + Comment: CXComment, + ) -> CXCommentParamPassDirection::Type; +} +extern "C" { + pub fn clang_TParamCommandComment_getParamName( + Comment: CXComment, + ) -> CXString; +} +extern "C" { + pub fn clang_TParamCommandComment_isParamPositionValid( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_TParamCommandComment_getDepth( + Comment: CXComment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_TParamCommandComment_getIndex( + Comment: CXComment, + Depth: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn clang_VerbatimBlockLineComment_getText( + Comment: CXComment, + ) -> CXString; +} +extern "C" { + pub fn clang_VerbatimLineComment_getText(Comment: CXComment) -> CXString; +} +extern "C" { + pub fn clang_HTMLTagComment_getAsString(Comment: CXComment) -> CXString; +} +extern "C" { + pub fn clang_FullComment_getAsHTML(Comment: CXComment) -> CXString; +} +extern "C" { + pub fn clang_FullComment_getAsXML(Comment: CXComment) -> CXString; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_ASTUnit { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_TargetInfo { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_CompoundStmt { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_Decl { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_Diagnostic { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_StoredDiagnostic { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_TranslationUnitDecl { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_Expr { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_Type { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_FileEntry { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_SourceLocation { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_CXXBaseSpecifier { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_ASTContext { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_SourceRange { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_Attr { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_PreprocessedEntity { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_comments_Comment { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct clang_comments_FullComment { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct EvalResult { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug)] +pub struct BindgenStringRef { + pub s: *mut ::std::os::raw::c_char, + pub len: size_t, +} +#[test] +fn bindgen_test_layout_BindgenStringRef() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(BindgenStringRef)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(BindgenStringRef)) + ); + fn test_field_s() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(BindgenStringRef), + "::", + stringify!(s) + ) + ); + } + test_field_s(); + fn test_field_len() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(BindgenStringRef), + "::", + stringify!(len) + ) + ); + } + test_field_len(); +} +pub type BindgenQualType = *mut ::std::os::raw::c_void; +#[repr(C)] +#[derive(Debug)] +pub struct BindgenStringRefSet { + pub strings: *mut BindgenStringRef, + pub len: size_t, +} +#[test] +fn bindgen_test_layout_BindgenStringRefSet() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(BindgenStringRefSet)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(BindgenStringRefSet)) + ); + fn test_field_strings() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).strings) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(BindgenStringRefSet), + "::", + stringify!(strings) + ) + ); + } + test_field_strings(); + fn test_field_len() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(BindgenStringRefSet), + "::", + stringify!(len) + ) + ); + } + test_field_len(); +} +#[repr(C)] +#[derive(Debug)] +pub struct BindgenSourceRange { + pub B: *mut clang_SourceLocation, + pub E: *mut clang_SourceLocation, +} +#[test] +fn bindgen_test_layout_BindgenSourceRange() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(BindgenSourceRange)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(BindgenSourceRange)) + ); + fn test_field_B() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).B) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(BindgenSourceRange), + "::", + stringify!(B) + ) + ); + } + test_field_B(); + fn test_field_E() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).E) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(BindgenSourceRange), + "::", + stringify!(E) + ) + ); + } + test_field_E(); +} +extern "C" { + pub fn deleteString(s: *mut BindgenStringRef); +} +extern "C" { + pub fn cString(s: *mut BindgenStringRef) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn deleteStringSet(s: *mut BindgenStringRefSet); +} +extern "C" { + pub fn deleteSourceLocation(s: *mut clang_SourceLocation); +} +extern "C" { + pub fn deleteSourceRange(s: *mut BindgenSourceRange); +} +extern "C" { + pub fn deleteEvalResult(e: *mut EvalResult); +} +extern "C" { + pub fn ASTUnit_getContext( + arg1: *mut clang_ASTUnit, + ) -> *mut clang_ASTContext; +} +extern "C" { + pub fn parseTranslationUnit( + source_filename: *const ::std::os::raw::c_char, + command_line_args: *const *const ::std::os::raw::c_char, + num_command_line_args: ::std::os::raw::c_int, + options: ::std::os::raw::c_uint, + unsaved_files: *mut CXUnsavedFile, + num_unsaved_files: ::std::os::raw::c_uint, + ) -> *mut clang_ASTUnit; +} +extern "C" { + pub fn disposeASTUnit(AU: *mut clang_ASTUnit); +} +extern "C" { + pub fn ASTUnit_getNumDiagnostics( + AU: *const clang_ASTUnit, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn ASTUnit_getDiagnostic( + AU: *const clang_ASTUnit, + i: ::std::os::raw::c_uint, + ) -> *const clang_StoredDiagnostic; +} +extern "C" { + pub fn ASTUnit_getTargetInfo( + AU: *mut clang_ASTUnit, + ) -> *const clang_TargetInfo; +} +extern "C" { + pub fn TargetInfo_getPointerWidth( + TI: *const clang_TargetInfo, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn TargetInfo_getTriple( + TI: *const clang_TargetInfo, + ) -> BindgenStringRef; +} +extern "C" { + pub fn Expr_Evaluate( + E: *const clang_Expr, + Ctx: *mut clang_ASTContext, + ) -> *mut EvalResult; +} +extern "C" { + pub fn Decl_Evaluate( + D: *const clang_Decl, + Ctx: *mut clang_ASTContext, + ) -> *mut EvalResult; +} +extern "C" { + pub fn EvalResult_getKind(arg1: *mut EvalResult) -> CXEvalResultKind::Type; +} +extern "C" { + pub fn EvalResult_getAsDouble(arg1: *mut EvalResult) -> f64; +} +extern "C" { + pub fn EvalResult_isUnsignedInt(arg1: *mut EvalResult) -> bool; +} +extern "C" { + pub fn EvalResult_getAsUnsigned( + arg1: *mut EvalResult, + ) -> ::std::os::raw::c_ulonglong; +} +extern "C" { + pub fn EvalResult_getAsLongLong( + arg1: *mut EvalResult, + ) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn EvalResult_getAsStr(arg1: *mut EvalResult) -> BindgenStringRef; +} +extern "C" { + pub fn Diagnostic_format( + arg1: *const clang_StoredDiagnostic, + ) -> BindgenStringRef; +} +extern "C" { + pub fn Diagnostic_getSeverity( + arg1: *const clang_StoredDiagnostic, + ) -> CXDiagnosticSeverity::Type; +} +extern "C" { + pub fn getTranslationUnitDecl( + arg1: *mut clang_ASTUnit, + ) -> *const clang_Decl; +} +extern "C" { + pub fn CursorKind_isInvalid(kind: CXCursorKind::Type) -> bool; +} +extern "C" { + pub fn Decl_getLexicalParent(D: *const clang_Decl) -> *const clang_Decl; +} +extern "C" { + pub fn Decl_getSemanticParent(D: *const clang_Decl) -> *const clang_Decl; +} +extern "C" { + pub fn Decl_isDeleted(D: *const clang_Decl) -> bool; +} +extern "C" { + pub fn Decl_getDefinition( + D: *const clang_Decl, + isReference: bool, + ) -> *const clang_Decl; +} +extern "C" { + pub fn Decl_getReferenced(D: *const clang_Decl) -> *const clang_Decl; +} +extern "C" { + pub fn Decl_getCanonical(D: *const clang_Decl) -> *const clang_Decl; +} +extern "C" { + pub fn Decl_getSpecializedTemplate( + D: *const clang_Decl, + ) -> *const clang_Decl; +} +extern "C" { + pub fn Decl_getTemplateCursorKind( + D: *const clang_Decl, + ) -> CXCursorKind::Type; +} +extern "C" { + pub fn Decl_getArgument( + D: *const clang_Decl, + i: ::std::os::raw::c_uint, + ) -> *const clang_Decl; +} +extern "C" { + pub fn Decl_getNumArguments(D: *const clang_Decl) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn Decl_getUSR(D: *const clang_Decl) -> BindgenStringRef; +} +extern "C" { + pub fn Decl_getSpelling(D: *const clang_Decl) -> BindgenStringRef; +} +extern "C" { + pub fn Decl_getDisplayName(D: *const clang_Decl) -> BindgenStringRef; +} +extern "C" { + pub fn Decl_getMangling( + D: *const clang_Decl, + arg1: *mut clang_ASTContext, + ) -> BindgenStringRef; +} +extern "C" { + pub fn Decl_getCXXManglings( + D: *const clang_Decl, + arg1: *mut clang_ASTContext, + ) -> BindgenStringRefSet; +} +extern "C" { + pub fn Decl_getNumTemplateArguments( + D: *const clang_Decl, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn Decl_getCXCursorKind(D: *const clang_Decl) -> CXCursorKind::Type; +} +extern "C" { + pub fn Decl_isDefinition(D: *const clang_Decl) -> bool; +} +extern "C" { + pub fn Decl_getLocation(D: *const clang_Decl) -> *mut clang_SourceLocation; +} +extern "C" { + pub fn Decl_getRawCommentText( + D: *const clang_Decl, + arg1: *mut clang_ASTContext, + ) -> BindgenStringRef; +} +extern "C" { + pub fn Decl_getParsedComment( + D: *const clang_Decl, + arg1: *mut clang_ASTContext, + ) -> *mut clang_comments_Comment; +} +extern "C" { + pub fn Decl_getType( + D: *const clang_Decl, + arg1: *mut clang_ASTContext, + ) -> BindgenQualType; +} +extern "C" { + pub fn Decl_isFunctionInlined(D: *const clang_Decl) -> bool; +} +extern "C" { + pub fn Decl_getFieldDeclBitWidth( + D: *const clang_Decl, + arg1: *mut clang_ASTContext, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn Decl_getEnumDeclIntegerType(D: *const clang_Decl) + -> BindgenQualType; +} +extern "C" { + pub fn Decl_getEnumConstantValue(D: *const clang_Decl) -> i64; +} +extern "C" { + pub fn Decl_getEnumConstantUnsignedValue(D: *const clang_Decl) -> u64; +} +extern "C" { + pub fn Decl_getOffsetOfField( + D: *const clang_Decl, + arg1: *mut clang_ASTContext, + ) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn Decl_getSourceRange(D: *const clang_Decl) -> BindgenSourceRange; +} +extern "C" { + pub fn Decl_getTypedefDeclUnderlyingType( + D: *const clang_Decl, + ) -> BindgenQualType; +} +extern "C" { + pub fn Decl_getLinkage(D: *const clang_Decl) -> CXLinkageKind::Type; +} +extern "C" { + pub fn Decl_getVisibility(D: *const clang_Decl) -> CXVisibilityKind::Type; +} +extern "C" { + pub fn Decl_getAccess(D: *const clang_Decl) -> CX_CXXAccessSpecifier::Type; +} +extern "C" { + pub fn CXXField_isMutable(D: *const clang_Decl) -> bool; +} +extern "C" { + pub fn CXXMethod_isStatic(D: *const clang_Decl) -> bool; +} +extern "C" { + pub fn CXXMethod_isConst(D: *const clang_Decl) -> bool; +} +extern "C" { + pub fn CXXMethod_isVirtual(D: *const clang_Decl) -> bool; +} +extern "C" { + pub fn CXXMethod_isPureVirtual(D: *const clang_Decl) -> bool; +} +extern "C" { + pub fn Decl_getResultType( + D: *const clang_Decl, + arg1: *mut clang_ASTContext, + ) -> BindgenQualType; +} +extern "C" { + pub fn Expr_getArgument( + E: *const clang_Expr, + i: ::std::os::raw::c_uint, + ) -> *const clang_Expr; +} +extern "C" { + pub fn Expr_getNumArguments(E: *const clang_Expr) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn Expr_getUSR(E: *const clang_Expr) -> BindgenStringRef; +} +extern "C" { + pub fn Expr_getSpelling(E: *const clang_Expr) -> BindgenStringRef; +} +extern "C" { + pub fn Expr_getDisplayName(E: *const clang_Expr) -> BindgenStringRef; +} +extern "C" { + pub fn Expr_getMangling(E: *const clang_Expr) -> BindgenStringRef; +} +extern "C" { + pub fn Expr_getCXXManglings(E: *const clang_Expr) -> BindgenStringRefSet; +} +extern "C" { + pub fn Expr_getCXCursorKind(E: *const clang_Expr) -> CXCursorKind::Type; +} +extern "C" { + pub fn Expr_getLocation(E: *const clang_Expr) -> *mut clang_SourceLocation; +} +extern "C" { + pub fn Expr_getRawCommentText(E: *const clang_Expr) -> BindgenStringRef; +} +extern "C" { + pub fn Expr_getParsedComment( + E: *const clang_Expr, + ) -> *mut clang_comments_FullComment; +} +extern "C" { + pub fn Expr_getType(E: *const clang_Expr) -> BindgenQualType; +} +extern "C" { + pub fn Expr_getSourceRange(E: *const clang_Expr) -> BindgenSourceRange; +} +extern "C" { + pub fn Type_getDeclaration(arg1: BindgenQualType) -> *const clang_Decl; +} +extern "C" { + pub fn Attr_getCXCursorKind(arg1: *const clang_Attr) -> CXCursorKind::Type; +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Node { + pub kind: CXCursorKind::Type, + pub ptr: Node__bindgen_ty_1, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union Node__bindgen_ty_1 { + pub decl: *const clang_Decl, + pub expr: *const clang_Expr, + pub base: *const clang_CXXBaseSpecifier, + pub attr: *const clang_Attr, + pub ppe: *const clang_PreprocessedEntity, +} +#[test] +fn bindgen_test_layout_Node__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Node__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Node__bindgen_ty_1)) + ); + fn test_field_decl() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).decl) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Node__bindgen_ty_1), + "::", + stringify!(decl) + ) + ); + } + test_field_decl(); + fn test_field_expr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).expr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Node__bindgen_ty_1), + "::", + stringify!(expr) + ) + ); + } + test_field_expr(); + fn test_field_base() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).base) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Node__bindgen_ty_1), + "::", + stringify!(base) + ) + ); + } + test_field_base(); + fn test_field_attr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).attr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Node__bindgen_ty_1), + "::", + stringify!(attr) + ) + ); + } + test_field_attr(); + fn test_field_ppe() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ppe) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Node__bindgen_ty_1), + "::", + stringify!(ppe) + ) + ); + } + test_field_ppe(); +} +#[test] +fn bindgen_test_layout_Node() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Node)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Node)) + ); + fn test_field_kind() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).kind) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Node), + "::", + stringify!(kind) + ) + ); + } + test_field_kind(); + fn test_field_ptr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(Node), + "::", + stringify!(ptr) + ) + ); + } + test_field_ptr(); +} +pub type Visitor = ::std::option::Option< + unsafe extern "C" fn( + N: Node, + parent: Node, + unit: *mut clang_ASTUnit, + client_data: CXClientData, + ) -> CXChildVisitResult::Type, +>; +extern "C" { + pub fn Decl_visitChildren( + Parent: *const clang_Decl, + kind: CXCursorKind::Type, + V: Visitor, + Unit: *mut clang_ASTUnit, + data: CXClientData, + ); +} +extern "C" { + pub fn Expr_visitChildren( + Parent: *const clang_Expr, + kind: CXCursorKind::Type, + V: Visitor, + Unit: *mut clang_ASTUnit, + data: CXClientData, + ); +} +extern "C" { + pub fn CXXBaseSpecifier_visitChildren( + Parent: *const clang_CXXBaseSpecifier, + kind: CXCursorKind::Type, + V: Visitor, + Unit: *mut clang_ASTUnit, + data: CXClientData, + ); +} +extern "C" { + pub fn tokenize( + TU: *mut clang_ASTUnit, + Range: BindgenSourceRange, + Tokens: *mut *mut CXToken, + NumTokens: *mut ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn disposeTokens( + TU: *const clang_ASTUnit, + Tokens: *mut CXToken, + NumTokens: ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn getTokenKind(token: CXToken) -> CXTokenKind::Type; +} +extern "C" { + pub fn getTokenSpelling( + TU: *mut clang_ASTUnit, + token: CXToken, + ) -> BindgenStringRef; +} +extern "C" { + pub fn Type_kind( + arg1: BindgenQualType, + arg2: *mut clang_ASTContext, + ) -> CXTypeKind::Type; +} +extern "C" { + pub fn Type_getTypeSpelling( + arg1: BindgenQualType, + arg2: *mut clang_ASTContext, + ) -> BindgenStringRef; +} +extern "C" { + pub fn Type_isConstQualifiedType(arg1: BindgenQualType) -> bool; +} +extern "C" { + pub fn Type_getSizeOf( + arg1: BindgenQualType, + arg2: *mut clang_ASTContext, + ) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn Type_getAlignOf( + arg1: BindgenQualType, + arg2: *mut clang_ASTContext, + ) -> ::std::os::raw::c_longlong; +} +extern "C" { + pub fn Type_getNumTemplateArguments( + arg1: BindgenQualType, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn Type_getArgType( + T: BindgenQualType, + index: ::std::os::raw::c_uint, + ) -> BindgenQualType; +} +extern "C" { + pub fn Type_getNumArgTypes(arg1: BindgenQualType) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn Type_getPointeeType(arg1: BindgenQualType) -> BindgenQualType; +} +extern "C" { + pub fn Type_getElementType(arg1: BindgenQualType) -> BindgenQualType; +} +extern "C" { + pub fn Type_getNumElements(arg1: BindgenQualType) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn Type_getCanonicalType( + arg1: BindgenQualType, + arg2: *mut clang_ASTContext, + ) -> BindgenQualType; +} +extern "C" { + pub fn Type_isFunctionTypeVariadic(arg1: BindgenQualType) -> bool; +} +extern "C" { + pub fn Type_getResultType(arg1: BindgenQualType) -> BindgenQualType; +} +extern "C" { + pub fn Type_getFunctionTypeCallingConv( + arg1: BindgenQualType, + ) -> CXCallingConv::Type; +} +extern "C" { + pub fn Type_getNamedType(arg1: BindgenQualType) -> BindgenQualType; +} +extern "C" { + pub fn Type_getTemplateArgumentAsType( + T: BindgenQualType, + index: ::std::os::raw::c_uint, + ) -> BindgenQualType; +} +extern "C" { + pub fn getSpellingLocation( + AST: *mut clang_ASTUnit, + T: *const clang_SourceLocation, + file: *mut *mut clang_FileEntry, + line: *mut ::std::os::raw::c_int, + col: *mut ::std::os::raw::c_int, + off: *mut ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn Comment_getKind( + arg1: *const clang_comments_Comment, + ) -> CXCommentKind::Type; +} +extern "C" { + pub fn Comment_getNumChildren( + arg1: *const clang_comments_Comment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn Comment_getChild( + arg1: *const clang_comments_Comment, + index: ::std::os::raw::c_uint, + ) -> *mut clang_comments_Comment; +} +extern "C" { + pub fn HTMLTagComment_getTagName( + arg1: *const clang_comments_Comment, + ) -> BindgenStringRef; +} +extern "C" { + pub fn HTMLStartTag_getNumAttrs( + arg1: *const clang_comments_Comment, + ) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn HTMLStartTag_getAttrName( + arg1: *const clang_comments_Comment, + arg2: ::std::os::raw::c_uint, + ) -> BindgenStringRef; +} +extern "C" { + pub fn HTMLStartTag_getAttrValue( + arg1: *const clang_comments_Comment, + arg2: ::std::os::raw::c_uint, + ) -> BindgenStringRef; +} +extern "C" { + pub fn CursorKind_getSpelling(arg1: CXCursorKind::Type) + -> BindgenStringRef; +} +extern "C" { + pub fn TypeKind_getSpelling(arg1: CXTypeKind::Type) -> BindgenStringRef; +} +extern "C" { + pub fn PreprocessedEntity_getSpelling( + arg1: *const clang_PreprocessedEntity, + ) -> BindgenStringRef; +} +extern "C" { + pub fn FileEntry_getName(arg1: *const clang_FileEntry) -> BindgenStringRef; +} +extern "C" { + pub fn getClangVersion() -> BindgenStringRef; +} +extern "C" { + pub fn CXXBaseSpecifier_isVirtualBase( + arg1: *const clang_CXXBaseSpecifier, + ) -> bool; +} +extern "C" { + pub fn CXXBaseSpecifier_getType( + arg1: *const clang_CXXBaseSpecifier, + ) -> BindgenQualType; +} +extern "C" { + pub fn CXXBaseSpecifier_getSpelling( + arg1: *const clang_CXXBaseSpecifier, + ) -> BindgenStringRef; +} +extern "C" { + pub fn CXXBaseSpecifier_getLocation( + arg1: *const clang_CXXBaseSpecifier, + ) -> *mut clang_SourceLocation; +} +extern "C" { + pub fn Attr_getLocation( + arg1: *const clang_Attr, + ) -> *mut clang_SourceLocation; +} +extern "C" { + pub fn PreprocessedEntity_getLocation( + arg1: *const clang_PreprocessedEntity, + ) -> *mut clang_SourceLocation; +} +extern "C" { + pub fn PreprocessedEntity_getIncludedFile( + arg1: *const clang_PreprocessedEntity, + ) -> *const clang_FileEntry; +} +extern "C" { + pub fn CXXBaseSpecifier_getSourceRange( + arg1: *const clang_CXXBaseSpecifier, + ) -> BindgenSourceRange; +} +extern "C" { + pub fn CXXBaseSpecifier_getAccess( + arg1: *const clang_CXXBaseSpecifier, + ) -> CX_CXXAccessSpecifier::Type; +} +extern "C" { + pub fn Attr_getSourceRange(arg1: *const clang_Attr) -> BindgenSourceRange; +} +extern "C" { + pub fn PreprocessedEntity_getSourceRange( + arg1: *const clang_PreprocessedEntity, + ) -> BindgenSourceRange; +} +extern "C" { + pub fn PreprocessedEntity_isFunctionMacroLike( + TU: *mut clang_ASTUnit, + ppe: *const clang_PreprocessedEntity, + ) -> bool; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __locale_data { + pub _address: u8, +} diff --git a/src/clang/clang_interface_impl.hpp b/src/clang/clang_interface_impl.hpp new file mode 100644 index 0000000000..4fd5919162 --- /dev/null +++ b/src/clang/clang_interface_impl.hpp @@ -0,0 +1,50 @@ +#ifndef BINDGEN_CLANG_INTERFACE_IMPL_H +#define BINDGEN_CLANG_INTERFACE_IMPL_H + +#include "clang/AST/Decl.h" +#include "clang/AST/Expr.h" +#include "clang/Basic/Version.h" + +#define BINDGEN_IMPLEMENTATION +#include "clang_interface.hpp" + +using namespace clang; + +namespace clang { + +#if CLANG_VERSION_MAJOR < 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR <= 8) +// Clang <= 3.8 doesn't include this enum, but we can still expose the same +// functionality +typedef enum { + CXEval_Int = 1 , + CXEval_Float = 2, + CXEval_ObjCStrLiteral = 3, + CXEval_StrLiteral = 4, + CXEval_CFStr = 5, + CXEval_Other = 6, + + CXEval_UnExposed = 0 + +} CXEvalResultKind ; +#endif + +} // namespace clang + +// Utility functions defined in ClangAST.cpp +BindgenStringRef stringref(); +BindgenStringRef stringref(const char *newStr); +BindgenStringRef stringref(const std::string &s); +BindgenStringRef stringref(llvm::StringRef S); +BindgenStringRefSet make_stringrefset(std::vector &string_vec); +BindgenQualType make_type_compatible(QualType QT); + +// Functions defined in libclang_compat.cpp +const Decl *getDeclFromExpr(const Stmt *E); +long long visitRecordForValidation(const RecordDecl *RD); +Optional> GetTemplateArguments(QualType Type); +unsigned GetTemplateArgumentArraySize(ArrayRef TA); +Optional FindTemplateArgumentTypeAt(ArrayRef TA, + unsigned index); +CX_CXXAccessSpecifier TranslateCXXAccessSpecifier(AccessSpecifier spec); + +#endif // BINDGEN_CLANG_INTERFACE_IMPL_H diff --git a/src/clang/libclang_compat.cpp b/src/clang/libclang_compat.cpp new file mode 100644 index 0000000000..fb045dd1df --- /dev/null +++ b/src/clang/libclang_compat.cpp @@ -0,0 +1,2121 @@ +// The functions in this file are adapted from the LLVM Project, used under the +// Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include "llvm/Support/CrashRecoveryContext.h" +#include "clang/AST/Attr.h" +#include "clang/AST/Comment.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclFriend.h" +#include "clang/AST/DeclTemplate.h" +#include "clang/AST/DeclObjC.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" +#include "clang/AST/ExprObjC.h" +#include "clang/AST/Mangle.h" +#include "clang/Basic/TargetInfo.h" +#include "clang/Basic/Version.h" +#include "clang/Frontend/ASTUnit.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/CompilerInvocation.h" +#include "clang/Lex/Lexer.h" +#include "clang/Lex/Preprocessor.h" +#include "clang-c/Documentation.h" +#include "clang-c/Index.h" +#include "llvm/IR/DataLayout.h" +#include "llvm/IR/Mangler.h" + +#if CLANG_VERSION_MAJOR <= 8 && \ + (CLANG_VERSION_MAJOR > 3 || \ + CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR > 8) +#include "clang/Index/CodegenNameGenerator.h" +#endif // CLANG_VERSION_MAJOR <= 8 + +#include "clang_interface_impl.hpp" + +using namespace clang; + +// From CIndex.cpp +const Decl *getDeclFromExpr(const Stmt *E) { + if (const ImplicitCastExpr *CE = dyn_cast(E)) + return getDeclFromExpr(CE->getSubExpr()); + + if (const DeclRefExpr *RefExpr = dyn_cast(E)) + return RefExpr->getDecl(); + if (const MemberExpr *ME = dyn_cast(E)) + return ME->getMemberDecl(); + if (const ObjCIvarRefExpr *RE = dyn_cast(E)) + return RE->getDecl(); + if (const ObjCPropertyRefExpr *PRE = dyn_cast(E)) { + if (PRE->isExplicitProperty()) + return PRE->getExplicitProperty(); + // It could be messaging both getter and setter as in: + // ++myobj.myprop; + // in which case prefer to associate the setter since it is less obvious + // from inspecting the source that the setter is going to get called. + if (PRE->isMessagingSetter()) + return PRE->getImplicitPropertySetter(); + return PRE->getImplicitPropertyGetter(); + } + if (const PseudoObjectExpr *POE = dyn_cast(E)) + return getDeclFromExpr(POE->getSyntacticForm()); + if (const OpaqueValueExpr *OVE = dyn_cast(E)) + if (Expr *Src = OVE->getSourceExpr()) + return getDeclFromExpr(Src); + + if (const CallExpr *CE = dyn_cast(E)) + return getDeclFromExpr(CE->getCallee()); + if (const CXXConstructExpr *CE = dyn_cast(E)) + if (!CE->isElidable()) + return CE->getConstructor(); +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + if (const CXXInheritedCtorInitExpr *CE = + dyn_cast(E)) + return CE->getConstructor(); +#endif // CLANG_VERSION > 3.8 + if (const ObjCMessageExpr *OME = dyn_cast(E)) + return OME->getMethodDecl(); + + if (const ObjCProtocolExpr *PE = dyn_cast(E)) + return PE->getProtocol(); + if (const SubstNonTypeTemplateParmPackExpr *NTTP + = dyn_cast(E)) + return NTTP->getParameterPack(); + if (const SizeOfPackExpr *SizeOfPack = dyn_cast(E)) + if (isa(SizeOfPack->getPack()) || + isa(SizeOfPack->getPack())) + return SizeOfPack->getPack(); + + return nullptr; +} + +// From CXType.cpp +static bool isTypeIncompleteForLayout(QualType QT) { + return QT->isIncompleteType() && !QT->isIncompleteArrayType(); +} + +// Adapted from CXType.cpp +long long visitRecordForValidation(const RecordDecl *RD) { + if (!RD) + return -1; + RD = RD->getDefinition(); + if (!RD || RD->isInvalidDecl() || !RD->isCompleteDefinition()) + return -1; + for (const auto *I : RD->fields()){ + QualType FQT = I->getType(); + if (isTypeIncompleteForLayout(FQT)) + return CXTypeLayoutError_Incomplete; + if (FQT->isDependentType()) + return CXTypeLayoutError_Dependent; + // recurse + if (const RecordType *ChildType = I->getType()->getAs()) { + if (const RecordDecl *Child = ChildType->getDecl()) { + long long ret = visitRecordForValidation(Child); + if (ret < 0) + return ret; + } + } + // else try next field + } + if (auto *Class = dyn_cast(RD)) { + for (const CXXBaseSpecifier &Base : Class->bases()) { + auto *baseDecl = Base.getType()->getAsCXXRecordDecl(); + long long ret = visitRecordForValidation(baseDecl); + if (ret < 0) + return ret; + } + } + return 0; +} + +// From CXType.cpp +static CXTypeKind GetBuiltinTypeKind(const BuiltinType *BT) { +#define BTCASE(K) case BuiltinType::K: return CXType_##K + switch (BT->getKind()) { + BTCASE(Void); + BTCASE(Bool); + BTCASE(Char_U); + BTCASE(UChar); + BTCASE(Char16); + BTCASE(Char32); + BTCASE(UShort); + BTCASE(UInt); + BTCASE(ULong); + BTCASE(ULongLong); + BTCASE(UInt128); + BTCASE(Char_S); + BTCASE(SChar); + case BuiltinType::WChar_S: return CXType_WChar; + case BuiltinType::WChar_U: return CXType_WChar; + BTCASE(Short); + BTCASE(Int); + BTCASE(Long); + BTCASE(LongLong); + BTCASE(Int128); + BTCASE(Float); + BTCASE(Double); + BTCASE(LongDouble); +#if CLANG_VERSION_MAJOR > 6 + BTCASE(ShortAccum); + BTCASE(Accum); + BTCASE(LongAccum); + BTCASE(UShortAccum); + BTCASE(UAccum); + BTCASE(ULongAccum); +#endif // CLANG_VERSION_MAJOR > 6 +#if CLANG_VERSION_MAJOR > 5 + BTCASE(Float16); +#endif // CLANG_VERSION_MAJOR > 5 +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + BTCASE(Float128); +#endif + BTCASE(NullPtr); + BTCASE(Overload); + BTCASE(Dependent); + BTCASE(ObjCId); + BTCASE(ObjCClass); + BTCASE(ObjCSel); +#if CLANG_VERSION_MAJOR > 7 +#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) BTCASE(Id); +#include "clang/Basic/OpenCLExtensionTypes.def" +#endif // CLANG_VERSION_MAJOR > 7 +#if CLANG_VERSION_MAJOR > 4 +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) BTCASE(Id); +#include "clang/Basic/OpenCLImageTypes.def" +#undef IMAGE_TYPE + BTCASE(Half); + BTCASE(OCLSampler); + BTCASE(OCLEvent); + BTCASE(OCLQueue); + BTCASE(OCLReserveID); +#endif // CLANG_VERSION_MAJOR > 4 + default: + return CXType_Unexposed; + } +#undef BTCASE +} + +// Adapted from GetTypeKind in CXType.cpp +CXTypeKind Type_kind(BindgenQualType T, ASTContext *Context) { + auto QT = QualType::getFromOpaquePtr(T); + const Type *TP = QT.getTypePtrOrNull(); + if (!TP) + return CXType_Invalid; + + // libclang checks for these builtin types specially and matches on things + // that appear to be correct +#if CLANG_VERSION_MAJOR > 7 + bool isObjc = Context->getLangOpts().ObjC; +#else + bool isObjc = Context->getLangOpts().ObjC1; +#endif // CLANG_VERSION_MAJOR + if (isObjc) { + QualType UT = QT.getUnqualifiedType(); + if (Context->isObjCIdType(UT)) + return CXType_ObjCId; + if (Context->isObjCClassType(UT)) + return CXType_ObjCClass; + if (Context->isObjCSelType(UT)) + return CXType_ObjCSel; + } + +#define TKCASE(K) case Type::K: return CXType_##K + switch (TP->getTypeClass()) { + case Type::Builtin: + return GetBuiltinTypeKind(cast(TP)); + TKCASE(Complex); + TKCASE(Pointer); + TKCASE(BlockPointer); + TKCASE(LValueReference); + TKCASE(RValueReference); + TKCASE(Record); + TKCASE(Enum); + TKCASE(Typedef); + TKCASE(ObjCInterface); + TKCASE(ObjCObjectPointer); + TKCASE(FunctionNoProto); + TKCASE(FunctionProto); + TKCASE(ConstantArray); + TKCASE(IncompleteArray); + TKCASE(VariableArray); + TKCASE(DependentSizedArray); + TKCASE(Vector); + TKCASE(MemberPointer); + TKCASE(Auto); +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + TKCASE(Elaborated); +#endif // CLANG_VERSION > 3.8 +#if CLANG_VERSION_MAJOR > 4 + TKCASE(Pipe); +#endif // CLANG_VERSION_MAJOR > 4 +#if CLANG_VERSION_MAJOR > 7 + TKCASE(Attributed); + TKCASE(ObjCObject); + TKCASE(ObjCTypeParam); +#endif // CLANG_VERSION_MAJOR > 7 +#if CLANG_VERSION_MAJOR > 8 + TKCASE(ExtVector); +#endif // CLANG_VERSION_MAJOR > 8 + default: + return CXType_Unexposed; + } +#undef TKCASE +} + +// From CXType.cpp +Optional> +GetTemplateArguments(QualType Type) { + assert(!Type.isNull()); +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + if (const auto *Specialization = Type->getAs()) + return Specialization->template_arguments(); +#endif + + if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) { + const auto *TemplateDecl = + dyn_cast(RecordDecl); + if (TemplateDecl) + return TemplateDecl->getTemplateArgs().asArray(); + } + + return None; +} + +// From CXType.cpp +unsigned GetTemplateArgumentArraySize(ArrayRef TA) { + unsigned size = TA.size(); + for (const auto &Arg : TA) + if (Arg.getKind() == TemplateArgument::Pack) + size += Arg.pack_size() - 1; + return size; +} + +// From CXType.cpp +static Optional TemplateArgumentToQualType(const TemplateArgument &A) { + if (A.getKind() == TemplateArgument::Type) + return A.getAsType(); + return None; +} + +// From CXType.cpp +Optional +FindTemplateArgumentTypeAt(ArrayRef TA, unsigned index) { + unsigned current = 0; + for (const auto &A : TA) { + if (A.getKind() == TemplateArgument::Pack) { + if (index < current + A.pack_size()) + return TemplateArgumentToQualType(A.getPackAsArray()[index - current]); + current += A.pack_size(); + continue; + } + if (current == index) + return TemplateArgumentToQualType(A); + current++; + } + return None; +} + +// Adapted from CXSourceLocation.cpp +static void createNullLocation(FileEntry **file, int *line, + int *column, int *offset = nullptr) { + if (file) + *file = nullptr; + if (line) + *line = 0; + if (column) + *column = 0; + if (offset) + *offset = 0; +} + +// Adapted from clang_getCursorKindSpelling in CIndex.cpp +BindgenStringRef CursorKind_getSpelling(CXCursorKind Kind) { + switch (Kind) { + case CXCursor_FunctionDecl: + return stringref("FunctionDecl"); + case CXCursor_TypedefDecl: + return stringref("TypedefDecl"); + case CXCursor_EnumDecl: + return stringref("EnumDecl"); + case CXCursor_EnumConstantDecl: + return stringref("EnumConstantDecl"); + case CXCursor_StructDecl: + return stringref("StructDecl"); + case CXCursor_UnionDecl: + return stringref("UnionDecl"); + case CXCursor_ClassDecl: + return stringref("ClassDecl"); + case CXCursor_FieldDecl: + return stringref("FieldDecl"); + case CXCursor_VarDecl: + return stringref("VarDecl"); + case CXCursor_ParmDecl: + return stringref("ParmDecl"); + case CXCursor_ObjCInterfaceDecl: + return stringref("ObjCInterfaceDecl"); + case CXCursor_ObjCCategoryDecl: + return stringref("ObjCCategoryDecl"); + case CXCursor_ObjCProtocolDecl: + return stringref("ObjCProtocolDecl"); + case CXCursor_ObjCPropertyDecl: + return stringref("ObjCPropertyDecl"); + case CXCursor_ObjCIvarDecl: + return stringref("ObjCIvarDecl"); + case CXCursor_ObjCInstanceMethodDecl: + return stringref("ObjCInstanceMethodDecl"); + case CXCursor_ObjCClassMethodDecl: + return stringref("ObjCClassMethodDecl"); + case CXCursor_ObjCImplementationDecl: + return stringref("ObjCImplementationDecl"); + case CXCursor_ObjCCategoryImplDecl: + return stringref("ObjCCategoryImplDecl"); + case CXCursor_CXXMethod: + return stringref("CXXMethod"); + case CXCursor_UnexposedDecl: + return stringref("UnexposedDecl"); + case CXCursor_ObjCSuperClassRef: + return stringref("ObjCSuperClassRef"); + case CXCursor_ObjCProtocolRef: + return stringref("ObjCProtocolRef"); + case CXCursor_ObjCClassRef: + return stringref("ObjCClassRef"); + case CXCursor_TypeRef: + return stringref("TypeRef"); + case CXCursor_TemplateRef: + return stringref("TemplateRef"); + case CXCursor_NamespaceRef: + return stringref("NamespaceRef"); + case CXCursor_MemberRef: + return stringref("MemberRef"); + case CXCursor_LabelRef: + return stringref("LabelRef"); + case CXCursor_OverloadedDeclRef: + return stringref("OverloadedDeclRef"); + case CXCursor_VariableRef: + return stringref("VariableRef"); + case CXCursor_IntegerLiteral: + return stringref("IntegerLiteral"); +#if CLANG_VERSION_MAJOR > 6 + case CXCursor_FixedPointLiteral: + return stringref("FixedPointLiteral"); +#endif // CLANG_VERSION_MAJOR > 6 + case CXCursor_FloatingLiteral: + return stringref("FloatingLiteral"); + case CXCursor_ImaginaryLiteral: + return stringref("ImaginaryLiteral"); + case CXCursor_StringLiteral: + return stringref("StringLiteral"); + case CXCursor_CharacterLiteral: + return stringref("CharacterLiteral"); + case CXCursor_ParenExpr: + return stringref("ParenExpr"); + case CXCursor_UnaryOperator: + return stringref("UnaryOperator"); + case CXCursor_ArraySubscriptExpr: + return stringref("ArraySubscriptExpr"); + case CXCursor_OMPArraySectionExpr: + return stringref("OMPArraySectionExpr"); + case CXCursor_BinaryOperator: + return stringref("BinaryOperator"); + case CXCursor_CompoundAssignOperator: + return stringref("CompoundAssignOperator"); + case CXCursor_ConditionalOperator: + return stringref("ConditionalOperator"); + case CXCursor_CStyleCastExpr: + return stringref("CStyleCastExpr"); + case CXCursor_CompoundLiteralExpr: + return stringref("CompoundLiteralExpr"); + case CXCursor_InitListExpr: + return stringref("InitListExpr"); + case CXCursor_AddrLabelExpr: + return stringref("AddrLabelExpr"); + case CXCursor_StmtExpr: + return stringref("StmtExpr"); + case CXCursor_GenericSelectionExpr: + return stringref("GenericSelectionExpr"); + case CXCursor_GNUNullExpr: + return stringref("GNUNullExpr"); + case CXCursor_CXXStaticCastExpr: + return stringref("CXXStaticCastExpr"); + case CXCursor_CXXDynamicCastExpr: + return stringref("CXXDynamicCastExpr"); + case CXCursor_CXXReinterpretCastExpr: + return stringref("CXXReinterpretCastExpr"); + case CXCursor_CXXConstCastExpr: + return stringref("CXXConstCastExpr"); + case CXCursor_CXXFunctionalCastExpr: + return stringref("CXXFunctionalCastExpr"); + case CXCursor_CXXTypeidExpr: + return stringref("CXXTypeidExpr"); + case CXCursor_CXXBoolLiteralExpr: + return stringref("CXXBoolLiteralExpr"); + case CXCursor_CXXNullPtrLiteralExpr: + return stringref("CXXNullPtrLiteralExpr"); + case CXCursor_CXXThisExpr: + return stringref("CXXThisExpr"); + case CXCursor_CXXThrowExpr: + return stringref("CXXThrowExpr"); + case CXCursor_CXXNewExpr: + return stringref("CXXNewExpr"); + case CXCursor_CXXDeleteExpr: + return stringref("CXXDeleteExpr"); + case CXCursor_UnaryExpr: + return stringref("UnaryExpr"); + case CXCursor_ObjCStringLiteral: + return stringref("ObjCStringLiteral"); + case CXCursor_ObjCBoolLiteralExpr: + return stringref("ObjCBoolLiteralExpr"); +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + case CXCursor_ObjCAvailabilityCheckExpr: + return stringref("ObjCAvailabilityCheckExpr"); +#endif + case CXCursor_ObjCSelfExpr: + return stringref("ObjCSelfExpr"); + case CXCursor_ObjCEncodeExpr: + return stringref("ObjCEncodeExpr"); + case CXCursor_ObjCSelectorExpr: + return stringref("ObjCSelectorExpr"); + case CXCursor_ObjCProtocolExpr: + return stringref("ObjCProtocolExpr"); + case CXCursor_ObjCBridgedCastExpr: + return stringref("ObjCBridgedCastExpr"); + case CXCursor_BlockExpr: + return stringref("BlockExpr"); + case CXCursor_PackExpansionExpr: + return stringref("PackExpansionExpr"); + case CXCursor_SizeOfPackExpr: + return stringref("SizeOfPackExpr"); + case CXCursor_LambdaExpr: + return stringref("LambdaExpr"); + case CXCursor_UnexposedExpr: + return stringref("UnexposedExpr"); + case CXCursor_DeclRefExpr: + return stringref("DeclRefExpr"); + case CXCursor_MemberRefExpr: + return stringref("MemberRefExpr"); + case CXCursor_CallExpr: + return stringref("CallExpr"); + case CXCursor_ObjCMessageExpr: + return stringref("ObjCMessageExpr"); +#if CLANG_VERSION_MAJOR > 8 + case CXCursor_BuiltinBitCastExpr: + return stringref("BuiltinBitCastExpr"); +#endif // CLANG_VERSION_MAJOR > 8 + case CXCursor_UnexposedStmt: + return stringref("UnexposedStmt"); + case CXCursor_DeclStmt: + return stringref("DeclStmt"); + case CXCursor_LabelStmt: + return stringref("LabelStmt"); + case CXCursor_CompoundStmt: + return stringref("CompoundStmt"); + case CXCursor_CaseStmt: + return stringref("CaseStmt"); + case CXCursor_DefaultStmt: + return stringref("DefaultStmt"); + case CXCursor_IfStmt: + return stringref("IfStmt"); + case CXCursor_SwitchStmt: + return stringref("SwitchStmt"); + case CXCursor_WhileStmt: + return stringref("WhileStmt"); + case CXCursor_DoStmt: + return stringref("DoStmt"); + case CXCursor_ForStmt: + return stringref("ForStmt"); + case CXCursor_GotoStmt: + return stringref("GotoStmt"); + case CXCursor_IndirectGotoStmt: + return stringref("IndirectGotoStmt"); + case CXCursor_ContinueStmt: + return stringref("ContinueStmt"); + case CXCursor_BreakStmt: + return stringref("BreakStmt"); + case CXCursor_ReturnStmt: + return stringref("ReturnStmt"); + case CXCursor_GCCAsmStmt: + return stringref("GCCAsmStmt"); + case CXCursor_MSAsmStmt: + return stringref("MSAsmStmt"); + case CXCursor_ObjCAtTryStmt: + return stringref("ObjCAtTryStmt"); + case CXCursor_ObjCAtCatchStmt: + return stringref("ObjCAtCatchStmt"); + case CXCursor_ObjCAtFinallyStmt: + return stringref("ObjCAtFinallyStmt"); + case CXCursor_ObjCAtThrowStmt: + return stringref("ObjCAtThrowStmt"); + case CXCursor_ObjCAtSynchronizedStmt: + return stringref("ObjCAtSynchronizedStmt"); + case CXCursor_ObjCAutoreleasePoolStmt: + return stringref("ObjCAutoreleasePoolStmt"); + case CXCursor_ObjCForCollectionStmt: + return stringref("ObjCForCollectionStmt"); + case CXCursor_CXXCatchStmt: + return stringref("CXXCatchStmt"); + case CXCursor_CXXTryStmt: + return stringref("CXXTryStmt"); + case CXCursor_CXXForRangeStmt: + return stringref("CXXForRangeStmt"); + case CXCursor_SEHTryStmt: + return stringref("SEHTryStmt"); + case CXCursor_SEHExceptStmt: + return stringref("SEHExceptStmt"); + case CXCursor_SEHFinallyStmt: + return stringref("SEHFinallyStmt"); + case CXCursor_SEHLeaveStmt: + return stringref("SEHLeaveStmt"); + case CXCursor_NullStmt: + return stringref("NullStmt"); + case CXCursor_InvalidFile: + return stringref("InvalidFile"); + case CXCursor_InvalidCode: + return stringref("InvalidCode"); + case CXCursor_NoDeclFound: + return stringref("NoDeclFound"); + case CXCursor_NotImplemented: + return stringref("NotImplemented"); + case CXCursor_TranslationUnit: + return stringref("TranslationUnit"); + case CXCursor_UnexposedAttr: + return stringref("UnexposedAttr"); + case CXCursor_IBActionAttr: + return stringref("attribute(ibaction)"); + case CXCursor_IBOutletAttr: + return stringref("attribute(iboutlet)"); + case CXCursor_IBOutletCollectionAttr: + return stringref("attribute(iboutletcollection)"); + case CXCursor_CXXFinalAttr: + return stringref("attribute(final)"); + case CXCursor_CXXOverrideAttr: + return stringref("attribute(override)"); + case CXCursor_AnnotateAttr: + return stringref("attribute(annotate)"); + case CXCursor_AsmLabelAttr: + return stringref("asm label"); + case CXCursor_PackedAttr: + return stringref("attribute(packed)"); + case CXCursor_PureAttr: + return stringref("attribute(pure)"); + case CXCursor_ConstAttr: + return stringref("attribute(const)"); + case CXCursor_NoDuplicateAttr: + return stringref("attribute(noduplicate)"); + case CXCursor_CUDAConstantAttr: + return stringref("attribute(constant)"); + case CXCursor_CUDADeviceAttr: + return stringref("attribute(device)"); + case CXCursor_CUDAGlobalAttr: + return stringref("attribute(global)"); + case CXCursor_CUDAHostAttr: + return stringref("attribute(host)"); + case CXCursor_CUDASharedAttr: + return stringref("attribute(shared)"); + case CXCursor_VisibilityAttr: + return stringref("attribute(visibility)"); + case CXCursor_DLLExport: + return stringref("attribute(dllexport)"); + case CXCursor_DLLImport: + return stringref("attribute(dllimport)"); +#if CLANG_VERSION_MAJOR > 7 + case CXCursor_NSReturnsRetained: + return stringref("attribute(ns_returns_retained)"); + case CXCursor_NSReturnsNotRetained: + return stringref("attribute(ns_returns_not_retained)"); + case CXCursor_NSReturnsAutoreleased: + return stringref("attribute(ns_returns_autoreleased)"); + case CXCursor_NSConsumesSelf: + return stringref("attribute(ns_consumes_self)"); + case CXCursor_NSConsumed: + return stringref("attribute(ns_consumed)"); + case CXCursor_ObjCException: + return stringref("attribute(objc_exception)"); + case CXCursor_ObjCNSObject: + return stringref("attribute(NSObject)"); + case CXCursor_ObjCIndependentClass: + return stringref("attribute(objc_independent_class)"); + case CXCursor_ObjCPreciseLifetime: + return stringref("attribute(objc_precise_lifetime)"); + case CXCursor_ObjCReturnsInnerPointer: + return stringref("attribute(objc_returns_inner_pointer)"); + case CXCursor_ObjCRequiresSuper: + return stringref("attribute(objc_requires_super)"); + case CXCursor_ObjCRootClass: + return stringref("attribute(objc_root_class)"); + case CXCursor_ObjCSubclassingRestricted: + return stringref("attribute(objc_subclassing_restricted)"); + case CXCursor_ObjCExplicitProtocolImpl: + return stringref("attribute(objc_protocol_requires_explicit_implementation)"); + case CXCursor_ObjCDesignatedInitializer: + return stringref("attribute(objc_designated_initializer)"); + case CXCursor_ObjCRuntimeVisible: + return stringref("attribute(objc_runtime_visible)"); + case CXCursor_ObjCBoxable: + return stringref("attribute(objc_boxable)"); + case CXCursor_FlagEnum: + return stringref("attribute(flag_enum)"); +#endif // CLANG_VERSION_MAJOR > 7 + case CXCursor_PreprocessingDirective: + return stringref("preprocessing directive"); + case CXCursor_MacroDefinition: + return stringref("macro definition"); + case CXCursor_MacroExpansion: + return stringref("macro expansion"); + case CXCursor_InclusionDirective: + return stringref("inclusion directive"); + case CXCursor_Namespace: + return stringref("Namespace"); + case CXCursor_LinkageSpec: + return stringref("LinkageSpec"); + case CXCursor_CXXBaseSpecifier: + return stringref("C++ base class specifier"); + case CXCursor_Constructor: + return stringref("CXXConstructor"); + case CXCursor_Destructor: + return stringref("CXXDestructor"); + case CXCursor_ConversionFunction: + return stringref("CXXConversion"); + case CXCursor_TemplateTypeParameter: + return stringref("TemplateTypeParameter"); + case CXCursor_NonTypeTemplateParameter: + return stringref("NonTypeTemplateParameter"); + case CXCursor_TemplateTemplateParameter: + return stringref("TemplateTemplateParameter"); + case CXCursor_FunctionTemplate: + return stringref("FunctionTemplate"); + case CXCursor_ClassTemplate: + return stringref("ClassTemplate"); + case CXCursor_ClassTemplatePartialSpecialization: + return stringref("ClassTemplatePartialSpecialization"); + case CXCursor_NamespaceAlias: + return stringref("NamespaceAlias"); + case CXCursor_UsingDirective: + return stringref("UsingDirective"); + case CXCursor_UsingDeclaration: + return stringref("UsingDeclaration"); + case CXCursor_TypeAliasDecl: + return stringref("TypeAliasDecl"); + case CXCursor_ObjCSynthesizeDecl: + return stringref("ObjCSynthesizeDecl"); + case CXCursor_ObjCDynamicDecl: + return stringref("ObjCDynamicDecl"); + case CXCursor_CXXAccessSpecifier: + return stringref("CXXAccessSpecifier"); + case CXCursor_ModuleImportDecl: + return stringref("ModuleImport"); + case CXCursor_OMPParallelDirective: + return stringref("OMPParallelDirective"); + case CXCursor_OMPSimdDirective: + return stringref("OMPSimdDirective"); + case CXCursor_OMPForDirective: + return stringref("OMPForDirective"); + case CXCursor_OMPForSimdDirective: + return stringref("OMPForSimdDirective"); + case CXCursor_OMPSectionsDirective: + return stringref("OMPSectionsDirective"); + case CXCursor_OMPSectionDirective: + return stringref("OMPSectionDirective"); + case CXCursor_OMPSingleDirective: + return stringref("OMPSingleDirective"); + case CXCursor_OMPMasterDirective: + return stringref("OMPMasterDirective"); + case CXCursor_OMPCriticalDirective: + return stringref("OMPCriticalDirective"); + case CXCursor_OMPParallelForDirective: + return stringref("OMPParallelForDirective"); + case CXCursor_OMPParallelForSimdDirective: + return stringref("OMPParallelForSimdDirective"); + case CXCursor_OMPParallelSectionsDirective: + return stringref("OMPParallelSectionsDirective"); + case CXCursor_OMPTaskDirective: + return stringref("OMPTaskDirective"); + case CXCursor_OMPTaskyieldDirective: + return stringref("OMPTaskyieldDirective"); + case CXCursor_OMPBarrierDirective: + return stringref("OMPBarrierDirective"); + case CXCursor_OMPTaskwaitDirective: + return stringref("OMPTaskwaitDirective"); + case CXCursor_OMPTaskgroupDirective: + return stringref("OMPTaskgroupDirective"); + case CXCursor_OMPFlushDirective: + return stringref("OMPFlushDirective"); + case CXCursor_OMPOrderedDirective: + return stringref("OMPOrderedDirective"); + case CXCursor_OMPAtomicDirective: + return stringref("OMPAtomicDirective"); + case CXCursor_OMPTargetDirective: + return stringref("OMPTargetDirective"); + case CXCursor_OMPTargetDataDirective: + return stringref("OMPTargetDataDirective"); +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + case CXCursor_OMPTargetEnterDataDirective: + return stringref("OMPTargetEnterDataDirective"); + case CXCursor_OMPTargetExitDataDirective: + return stringref("OMPTargetExitDataDirective"); + case CXCursor_OMPTargetParallelDirective: + return stringref("OMPTargetParallelDirective"); + case CXCursor_OMPTargetParallelForDirective: + return stringref("OMPTargetParallelForDirective"); + case CXCursor_OMPTargetUpdateDirective: + return stringref("OMPTargetUpdateDirective"); +#endif + case CXCursor_OMPTeamsDirective: + return stringref("OMPTeamsDirective"); + case CXCursor_OMPCancellationPointDirective: + return stringref("OMPCancellationPointDirective"); + case CXCursor_OMPCancelDirective: + return stringref("OMPCancelDirective"); + case CXCursor_OMPTaskLoopDirective: + return stringref("OMPTaskLoopDirective"); + case CXCursor_OMPTaskLoopSimdDirective: + return stringref("OMPTaskLoopSimdDirective"); + case CXCursor_OMPDistributeDirective: + return stringref("OMPDistributeDirective"); +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + case CXCursor_OMPDistributeParallelForDirective: + return stringref("OMPDistributeParallelForDirective"); + case CXCursor_OMPDistributeParallelForSimdDirective: + return stringref("OMPDistributeParallelForSimdDirective"); + case CXCursor_OMPDistributeSimdDirective: + return stringref("OMPDistributeSimdDirective"); + case CXCursor_OMPTargetParallelForSimdDirective: + return stringref("OMPTargetParallelForSimdDirective"); +#endif +#if CLANG_VERSION_MAJOR > 3 + case CXCursor_OMPTargetSimdDirective: + return stringref("OMPTargetSimdDirective"); + case CXCursor_OMPTeamsDistributeDirective: + return stringref("OMPTeamsDistributeDirective"); + case CXCursor_OMPTeamsDistributeSimdDirective: + return stringref("OMPTeamsDistributeSimdDirective"); + case CXCursor_OMPTeamsDistributeParallelForSimdDirective: + return stringref("OMPTeamsDistributeParallelForSimdDirective"); + case CXCursor_OMPTeamsDistributeParallelForDirective: + return stringref("OMPTeamsDistributeParallelForDirective"); + case CXCursor_OMPTargetTeamsDirective: + return stringref("OMPTargetTeamsDirective"); + case CXCursor_OMPTargetTeamsDistributeDirective: + return stringref("OMPTargetTeamsDistributeDirective"); + case CXCursor_OMPTargetTeamsDistributeParallelForDirective: + return stringref("OMPTargetTeamsDistributeParallelForDirective"); + case CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective: + return stringref( + "OMPTargetTeamsDistributeParallelForSimdDirective"); + case CXCursor_OMPTargetTeamsDistributeSimdDirective: + return stringref("OMPTargetTeamsDistributeSimdDirective"); + case CXCursor_FriendDecl: + return stringref("FriendDecl"); +#endif // CLANG_VERSION_MAJOR > 3 + case CXCursor_OverloadCandidate: + return stringref("OverloadCandidate"); + case CXCursor_TypeAliasTemplateDecl: + return stringref("TypeAliasTemplateDecl"); +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + case CXCursor_StaticAssert: + return stringref("StaticAssert"); +#endif +#if CLANG_VERSION_MAJOR > 8 + case CXCursor_ConvergentAttr: + return stringref("attribute(convergent)"); + case CXCursor_WarnUnusedAttr: + return stringref("attribute(warn_unused)"); + case CXCursor_WarnUnusedResultAttr: + return stringref("attribute(warn_unused_result)"); + case CXCursor_AlignedAttr: + return stringref("attribute(aligned)"); +#endif // CLANG_VERSION_MAJOR > 8 + } + + llvm_unreachable("Unhandled CXCursorKind"); +} + +// Adapted from clang_getTypeKindSpelling in CXType.cpp +BindgenStringRef TypeKind_getSpelling(CXTypeKind K) { + const char *s = nullptr; +#define TKIND(X) case CXType_##X: s = "" #X ""; break + switch (K) { + TKIND(Invalid); + TKIND(Unexposed); + TKIND(Void); + TKIND(Bool); + TKIND(Char_U); + TKIND(UChar); + TKIND(Char16); + TKIND(Char32); + TKIND(UShort); + TKIND(UInt); + TKIND(ULong); + TKIND(ULongLong); + TKIND(UInt128); + TKIND(Char_S); + TKIND(SChar); + case CXType_WChar: s = "WChar"; break; + TKIND(Short); + TKIND(Int); + TKIND(Long); + TKIND(LongLong); + TKIND(Int128); + TKIND(Float); + TKIND(Double); + TKIND(LongDouble); +#if CLANG_VERSION_MAJOR > 6 + TKIND(ShortAccum); + TKIND(Accum); + TKIND(LongAccum); + TKIND(UShortAccum); + TKIND(UAccum); + TKIND(ULongAccum); +#endif // CLANG_VERSION_MAJOR > 6 +#if CLANG_VERSION_MAJOR > 5 + TKIND(Float16); +#endif // CLANG_VERSION_MAJOR > 5 + TKIND(NullPtr); + TKIND(Overload); + TKIND(Dependent); + TKIND(ObjCId); + TKIND(ObjCClass); + TKIND(ObjCSel); + TKIND(Complex); + TKIND(Pointer); + TKIND(BlockPointer); + TKIND(LValueReference); + TKIND(RValueReference); + TKIND(Record); + TKIND(Enum); + TKIND(Typedef); + TKIND(ObjCInterface); + TKIND(ObjCObjectPointer); + TKIND(FunctionNoProto); + TKIND(FunctionProto); + TKIND(ConstantArray); + TKIND(IncompleteArray); + TKIND(VariableArray); + TKIND(DependentSizedArray); + TKIND(Vector); + TKIND(MemberPointer); + TKIND(Auto); +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + TKIND(Float128); + TKIND(Elaborated); +#endif +#if CLANG_VERSION_MAJOR > 7 + TKIND(Attributed); + TKIND(ObjCObject); + TKIND(ObjCTypeParam); +#define EXT_OPAQUE_TYPE(ExtTYpe, Id, Ext) TKIND(Id); +#include "clang/Basic/OpenCLExtensionTypes.def" +#endif // CLANG_VERSION_MAJOR > 7 +#if CLANG_VERSION_MAJOR > 8 + TKIND(ExtVector); +#endif // CLANG_VERSION_MAJOR > 8 +#if CLANG_VERSION_MAJOR > 4 +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) TKIND(Id); +#include "clang/Basic/OpenCLImageTypes.def" +#undef IMAGE_TYPE + TKIND(Half); + TKIND(Pipe); + TKIND(OCLSampler); + TKIND(OCLEvent); + TKIND(OCLQueue); + TKIND(OCLReserveID); +#endif // CLANG_VERSION_MAJOR > 4 + } +#undef TKIND + return stringref(s); +} + +// From GetCursorKind in CXCursor.cpp +CXCursorKind Attr_getCXCursorKind(const Attr *A) { + assert(A && "Invalid arguments!"); + switch (A->getKind()) { + default: break; + case attr::IBAction: return CXCursor_IBActionAttr; + case attr::IBOutlet: return CXCursor_IBOutletAttr; + case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr; + case attr::Final: return CXCursor_CXXFinalAttr; + case attr::Override: return CXCursor_CXXOverrideAttr; + case attr::Annotate: return CXCursor_AnnotateAttr; + case attr::AsmLabel: return CXCursor_AsmLabelAttr; + case attr::Packed: return CXCursor_PackedAttr; + case attr::Pure: return CXCursor_PureAttr; + case attr::Const: return CXCursor_ConstAttr; + case attr::NoDuplicate: return CXCursor_NoDuplicateAttr; + case attr::CUDAConstant: return CXCursor_CUDAConstantAttr; + case attr::CUDADevice: return CXCursor_CUDADeviceAttr; + case attr::CUDAGlobal: return CXCursor_CUDAGlobalAttr; + case attr::CUDAHost: return CXCursor_CUDAHostAttr; + case attr::CUDAShared: return CXCursor_CUDASharedAttr; + case attr::Visibility: return CXCursor_VisibilityAttr; + case attr::DLLExport: return CXCursor_DLLExport; + case attr::DLLImport: return CXCursor_DLLImport; +#if CLANG_VERSION_MAJOR > 7 + case attr::NSReturnsRetained: return CXCursor_NSReturnsRetained; + case attr::NSReturnsNotRetained: return CXCursor_NSReturnsNotRetained; + case attr::NSReturnsAutoreleased: return CXCursor_NSReturnsAutoreleased; + case attr::NSConsumesSelf: return CXCursor_NSConsumesSelf; + case attr::NSConsumed: return CXCursor_NSConsumed; + case attr::ObjCException: return CXCursor_ObjCException; + case attr::ObjCNSObject: return CXCursor_ObjCNSObject; + case attr::ObjCIndependentClass: return CXCursor_ObjCIndependentClass; + case attr::ObjCPreciseLifetime: return CXCursor_ObjCPreciseLifetime; + case attr::ObjCReturnsInnerPointer: return CXCursor_ObjCReturnsInnerPointer; + case attr::ObjCRequiresSuper: return CXCursor_ObjCRequiresSuper; + case attr::ObjCRootClass: return CXCursor_ObjCRootClass; + case attr::ObjCSubclassingRestricted: return CXCursor_ObjCSubclassingRestricted; + case attr::ObjCExplicitProtocolImpl: return CXCursor_ObjCExplicitProtocolImpl; + case attr::ObjCDesignatedInitializer: return CXCursor_ObjCDesignatedInitializer; + case attr::ObjCRuntimeVisible: return CXCursor_ObjCRuntimeVisible; + case attr::ObjCBoxable: return CXCursor_ObjCBoxable; + case attr::FlagEnum: return CXCursor_FlagEnum; +#endif // CLANG_VERSION_MAJOR > 7 +#if CLANG_VERSION_MAJOR > 8 + case attr::Convergent: return CXCursor_ConvergentAttr; + case attr::WarnUnused: return CXCursor_WarnUnusedAttr; + case attr::WarnUnusedResult: return CXCursor_WarnUnusedResultAttr; + case attr::Aligned: return CXCursor_AlignedAttr; +#endif // CLANG_VERSION_MAJOR > 8 + } + + return CXCursor_UnexposedAttr; +} + +// Adapted from clang_Comment_getKind in CXComment.cpp +CXCommentKind Comment_getKind(const comments::Comment *C) { + using namespace comments; + if (!C) + return CXComment_Null; + + switch (C->getCommentKind()) { + case Comment::NoCommentKind: + return CXComment_Null; + + case Comment::TextCommentKind: + return CXComment_Text; + + case Comment::InlineCommandCommentKind: + return CXComment_InlineCommand; + + case Comment::HTMLStartTagCommentKind: + return CXComment_HTMLStartTag; + + case Comment::HTMLEndTagCommentKind: + return CXComment_HTMLEndTag; + + case Comment::ParagraphCommentKind: + return CXComment_Paragraph; + + case Comment::BlockCommandCommentKind: + return CXComment_BlockCommand; + + case Comment::ParamCommandCommentKind: + return CXComment_ParamCommand; + + case Comment::TParamCommandCommentKind: + return CXComment_TParamCommand; + + case Comment::VerbatimBlockCommentKind: + return CXComment_VerbatimBlockCommand; + + case Comment::VerbatimBlockLineCommentKind: + return CXComment_VerbatimBlockLine; + + case Comment::VerbatimLineCommentKind: + return CXComment_VerbatimLine; + + case Comment::FullCommentKind: + return CXComment_FullComment; + } + llvm_unreachable("unknown CommentKind"); +} + +// Adapted from clang_parseTranslationUnit_Impl in CIndex.cpp +ASTUnit *parseTranslationUnit(const char *source_filename, + const char *const *command_line_args, + int num_command_line_args, unsigned int options, + struct CXUnsavedFile *unsaved_files, + unsigned num_unsaved_files) { + SmallVector Args; + Args.push_back("clang"); + Args.append(command_line_args, command_line_args + num_command_line_args); + + std::unique_ptr> RemappedFiles( + new std::vector()); + // Recover resources if we crash before exiting this function. + llvm::CrashRecoveryContextCleanupRegistrar< + std::vector > RemappedCleanup(RemappedFiles.get()); + + for (auto &UF : llvm::makeArrayRef(unsaved_files, num_unsaved_files)) { + std::unique_ptr MB = + llvm::MemoryBuffer::getMemBufferCopy(StringRef(UF.Contents, UF.Length), UF.Filename); + RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release())); + } + + // Configure the diagnostics. + IntrusiveRefCntPtr + Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions)); + +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + if (options & CXTranslationUnit_KeepGoing) { +#if CLANG_VERSION_MAJOR > 8 + Diags->setFatalsAsError(true); +#elif CLANG_VERSION_MAJOR > 4 + Diags->setSuppressAfterFatalError(false); +#else // CLANG_VERSION_MAJOR <= 4 + Diags->setFatalsAsError(true); +#endif + } +#endif // CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + +#if CLANG_VERSION_MAJOR > 8 + CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::All; + if (options & CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles) + CaptureDiagnostics = CaptureDiagsKind::AllWithoutNonErrorsFromIncludes; +#endif // CLANG_VERSION_MAJOR > 8 + + if (options & CXTranslationUnit_DetailedPreprocessingRecord) { + // Tell the preprocessor to save a detailed preprocessing record + Args.push_back("-Xclang"); + Args.push_back("-detailed-preprocessing-record"); + } + + return ASTUnit::LoadFromCommandLine( + Args.data(), Args.data() + Args.size(), + std::make_shared(), Diags, + /*ResourceFilePath*/ StringRef(), + /*OnlyLocalDecls*/ false, +#if CLANG_VERSION_MAJOR > 8 + CaptureDiagnostics, +#else + /*CaptureDiagnostics*/true, +#endif // CLANG_VERSION_MAJOR > 8 + *RemappedFiles.get(), + /*RemappedFilesKeepOriginalName*/ true); +} + +// Adapted from CXStoredDiagnostic::getSeverity in CXStoredDiagnostic.cpp +CXDiagnosticSeverity Diagnostic_getSeverity(const StoredDiagnostic *D) { + switch (D->getLevel()) { + case DiagnosticsEngine::Ignored: return CXDiagnostic_Ignored; + case DiagnosticsEngine::Note: return CXDiagnostic_Note; + case DiagnosticsEngine::Remark: + // The 'Remark' level isn't represented in the stable API. + case DiagnosticsEngine::Warning: return CXDiagnostic_Warning; + case DiagnosticsEngine::Error: return CXDiagnostic_Error; + case DiagnosticsEngine::Fatal: return CXDiagnostic_Fatal; + } + + llvm_unreachable("Invalid diagnostic level"); +} + +// Adapted from getCursorAvailabilityForDecl in CIndex.cpp +bool Decl_isDeleted(const Decl *D) +{ + return isa(D) && cast(D)->isDeleted(); +} + +// Adapted from clang_getCursorDefinition in CIndex.cpp +const Decl *Decl_getDefinition(const Decl *D, bool isReference) { + if (!D) + return nullptr; + + switch (D->getKind()) { + // Declaration kinds that don't really separate the notions of + // declaration and definition. + case Decl::Namespace: + case Decl::Typedef: + case Decl::TypeAlias: + case Decl::TypeAliasTemplate: + case Decl::TemplateTypeParm: + case Decl::EnumConstant: + case Decl::Field: + case Decl::MSProperty: + case Decl::IndirectField: + case Decl::ObjCIvar: + case Decl::ObjCAtDefsField: + case Decl::ImplicitParam: + case Decl::ParmVar: + case Decl::NonTypeTemplateParm: + case Decl::TemplateTemplateParm: + case Decl::ObjCCategoryImpl: + case Decl::ObjCImplementation: + case Decl::AccessSpec: + case Decl::LinkageSpec: + case Decl::ObjCPropertyImpl: + case Decl::FileScopeAsm: + case Decl::StaticAssert: + case Decl::Block: + case Decl::Captured: + case Decl::Label: // FIXME: Is this right?? + case Decl::ClassScopeFunctionSpecialization: +#if CLANG_VERSION_MAJOR > 3 + case Decl::Binding: + case Decl::Export: + case Decl::UsingPack: +#endif // CLANG_VERSION_MAJOR > 3 +#if CLANG_VERSION_MAJOR > 4 + case Decl::CXXDeductionGuide: +#endif // CLANG_VERSION_MAJOR > 4 + case Decl::Import: + case Decl::OMPThreadPrivate: +#if CLANG_VERSION_MAJOR > 8 + case Decl::OMPAllocate: + case Decl::OMPDeclareMapper: + case Decl::Concept: +#endif // CLANG_VERSION_MAJOR > 8 +#if CLANG_VERSION_MAJOR > 7 + case Decl::OMPRequires: +#endif // CLANG_VERSION_MAJOR > 7 + case Decl::ObjCTypeParam: + case Decl::BuiltinTemplate: +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + case Decl::OMPCapturedExpr: + case Decl::OMPDeclareReduction: + case Decl::PragmaComment: + case Decl::PragmaDetectMismatch: +#endif // CLANG_VERSION > 3.8 + return D; + + // Declaration kinds that don't make any sense here, but are + // nonetheless harmless. + case Decl::Empty: + case Decl::TranslationUnit: + case Decl::ExternCContext: + break; + + // Declaration kinds for which the definition is not resolvable. + case Decl::UnresolvedUsingTypename: + case Decl::UnresolvedUsingValue: + break; + + case Decl::UsingDirective: + return cast(&*D)->getNominatedNamespace(); + + case Decl::NamespaceAlias: + return cast(&*D)->getNamespace(); + + case Decl::Enum: + case Decl::Record: + case Decl::CXXRecord: + case Decl::ClassTemplateSpecialization: + case Decl::ClassTemplatePartialSpecialization: + if (TagDecl *Def = cast(&*D)->getDefinition()) + return Def; + break; + + case Decl::Function: + case Decl::CXXMethod: + case Decl::CXXConstructor: + case Decl::CXXDestructor: + case Decl::CXXConversion: { + const FunctionDecl *Def = nullptr; + if (cast(&*D)->getBody(Def)) + return Def; + break; + } + + case Decl::Var: + case Decl::VarTemplateSpecialization: + case Decl::VarTemplatePartialSpecialization: +#if CLANG_VERSION_MAJOR > 3 + case Decl::Decomposition: +#endif // CLANG_VERSION_MAJOR > 3 + { + // Ask the variable if it has a definition. + if (const VarDecl *Def = cast(&*D)->getDefinition()) + return Def; + break; + } + + case Decl::FunctionTemplate: { + const FunctionDecl *Def = nullptr; + if (cast(&*D)->getTemplatedDecl()->getBody(Def)) + return Def->getDescribedFunctionTemplate(); + break; + } + + case Decl::ClassTemplate: { + if (RecordDecl *Def = + cast(&*D)->getTemplatedDecl()->getDefinition()) + return cast(Def)->getDescribedClassTemplate(); + break; + } + + case Decl::VarTemplate: { + if (VarDecl *Def = + cast(&*D)->getTemplatedDecl()->getDefinition()) + return cast(Def)->getDescribedVarTemplate(); + break; + } + + case Decl::Using: + return cast(&*D); + + case Decl::UsingShadow: +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + case Decl::ConstructorUsingShadow: +#endif // CLANG_VERSION > 3.8 + return Decl_getDefinition( + cast(&*D)->getTargetDecl(), isReference); + + case Decl::ObjCMethod: { + const ObjCMethodDecl *Method = cast(D); + if (Method->isThisDeclarationADefinition()) + return D; + + // Dig out the method definition in the associated + // @implementation, if we have it. + // FIXME: The ASTs should make finding the definition easier. + if (const ObjCInterfaceDecl *Class + = dyn_cast(Method->getDeclContext())) + if (ObjCImplementationDecl *ClassImpl = Class->getImplementation()) + if (ObjCMethodDecl *Def = ClassImpl->getMethod(Method->getSelector(), + Method->isInstanceMethod())) + if (Def->isThisDeclarationADefinition()) + return Def; + + break; + } + + case Decl::ObjCCategory: + if (ObjCCategoryImplDecl *Impl = cast(D)->getImplementation()) + return Impl; + break; + + case Decl::ObjCProtocol: + if (const ObjCProtocolDecl *Def = cast(D)->getDefinition()) + return Def; + break; + + case Decl::ObjCInterface: { + // There are two notions of a "definition" for an Objective-C + // class: the interface and its implementation. When we resolved a + // reference to an Objective-C class, produce the @interface as + // the definition; when we were provided with the interface, + // produce the @implementation as the definition. + const ObjCInterfaceDecl *IFace = cast(D); + if (isReference) { + if (const ObjCInterfaceDecl *Def = IFace->getDefinition()) + return Def; + } else if (ObjCImplementationDecl *Impl = IFace->getImplementation()) + return Impl; + break; + } + + case Decl::ObjCProperty: + // FIXME: We don't really know where to find the + // ObjCPropertyImplDecls that implement this property. + break; + + case Decl::ObjCCompatibleAlias: + if (const ObjCInterfaceDecl *Class + = cast(D)->getClassInterface()) + if (const ObjCInterfaceDecl *Def = Class->getDefinition()) + return Def; + + break; + + case Decl::Friend: + if (NamedDecl *Friend = cast(&*D)->getFriendDecl()) + return Decl_getDefinition(Friend, isReference); + break; + + case Decl::FriendTemplate: + if (NamedDecl *Friend = cast(&*D)->getFriendDecl()) + return Decl_getDefinition(Friend, isReference); + break; + } + + return nullptr; +} + +// Adapted from clang_getSpecializedCursorTemplate in CIndexCXX.cpp +const Decl *Decl_getSpecializedTemplate(const Decl *D) { + if (!D) + return nullptr; + + Decl *Template = nullptr; + if (const CXXRecordDecl *CXXRecord = dyn_cast(&*D)) { + if (const ClassTemplatePartialSpecializationDecl *PartialSpec + = dyn_cast(CXXRecord)) + Template = PartialSpec->getSpecializedTemplate(); + else if (const ClassTemplateSpecializationDecl *ClassSpec + = dyn_cast(CXXRecord)) { + llvm::PointerUnion Result + = ClassSpec->getSpecializedTemplateOrPartial(); + if (Result.is()) + Template = Result.get(); + else + Template = Result.get(); + + } else + Template = CXXRecord->getInstantiatedFromMemberClass(); + } else if (const FunctionDecl *Function = dyn_cast(&*D)) { + Template = Function->getPrimaryTemplate(); + if (!Template) + Template = Function->getInstantiatedFromMemberFunction(); + } else if (const VarDecl *Var = dyn_cast(&*D)) { + if (Var->isStaticDataMember()) + Template = Var->getInstantiatedFromStaticDataMember(); + } else if (const RedeclarableTemplateDecl *Tmpl + = dyn_cast(&*D)) + Template = Tmpl->getInstantiatedFromMemberTemplate(); + + return Template; +} + +// Adapted from clang_getTemplateCursorKind in CIndexCXX.cpp +CXCursorKind Decl_getTemplateCursorKind(const Decl *D) { + if (!D) + return CXCursor_NoDeclFound; + + switch (D->getKind()) { + case Decl::ClassTemplate: + case Decl::FunctionTemplate: + if (const TemplateDecl *Template = dyn_cast_or_null(&*D)) + return getCursorKindForDecl(Template->getTemplatedDecl()); + break; + + case Decl::ClassTemplatePartialSpecialization: + if (const ClassTemplateSpecializationDecl *PartialSpec + = dyn_cast_or_null(&*D)) { + switch (PartialSpec->getTagKind()) { + case TTK_Interface: + case TTK_Struct: return CXCursor_StructDecl; + case TTK_Class: return CXCursor_ClassDecl; + case TTK_Union: return CXCursor_UnionDecl; + case TTK_Enum: return CXCursor_NoDeclFound; + } + } + break; + + default: + break; + } + + return CXCursor_NoDeclFound; +} + +// Adapted from getDeclSpelling in CIndex.cpp +BindgenStringRef Decl_getSpelling(const Decl *D) { + if (!D) + return stringref(); + + const NamedDecl *ND = dyn_cast_or_null(&*D); + if (!ND) { + if (const ObjCPropertyImplDecl *PropImpl = + dyn_cast(D)) + if (ObjCPropertyDecl *Property = PropImpl->getPropertyDecl()) + return stringref(Property->getIdentifier()->getName()); + + if (const ImportDecl *ImportD = dyn_cast(D)) + if (Module *Mod = ImportD->getImportedModule()) + return stringref(Mod->getFullModuleName()); + + return stringref(); + } + + if (const ObjCMethodDecl *OMD = dyn_cast(ND)) + return stringref(OMD->getSelector().getAsString()); + + if (const ObjCCategoryImplDecl *CIMP = dyn_cast(ND)) + // No, this isn't the same as the code below. getIdentifier() is non-virtual + // and returns different names. NamedDecl returns the class name and + // ObjCCategoryImplDecl returns the category name. + return stringref(CIMP->getIdentifier()->getNameStart()); + + if (isa(D)) + return stringref(); + + SmallString<1024> S; + llvm::raw_svector_ostream os(S); + ND->printName(os); + return stringref(S.str()); +} + +// Adapted from clang_Cursor_getNumTemplateArguments in CXCursor.cpp +int Decl_getNumTemplateArguments(const Decl *D) { + const FunctionDecl *FD = llvm::dyn_cast_or_null(&*D); + if (!FD) + return -1; + + const FunctionTemplateSpecializationInfo* SpecInfo = + FD->getTemplateSpecializationInfo(); + if (!SpecInfo) { + return -1; + } + + return SpecInfo->TemplateArguments->size(); +} + +// Adapted from clang_getCursorLinkage in CIndex.cpp +CXLinkageKind Decl_getLinkage(const Decl *D) { + if (auto *ND = dyn_cast_or_null(&*D)) + switch (ND->getLinkageInternal()) { + case NoLinkage: + case VisibleNoLinkage: + return CXLinkage_NoLinkage; +#if CLANG_VERSION_MAJOR > 4 + case ModuleInternalLinkage: +#endif // CLANG_VERSION_MAJOR > 4 + case InternalLinkage: + return CXLinkage_Internal; + case UniqueExternalLinkage: + return CXLinkage_UniqueExternal; +#if CLANG_VERSION_MAJOR > 4 + case ModuleLinkage: +#endif // CLANG_VERSION_MAJOR > 4 + case ExternalLinkage: + return CXLinkage_External; + }; + + return CXLinkage_Invalid; +} + +// Adapted from clang_getCursorVisibility in CIndex.cpp +CXVisibilityKind Decl_getVisibility(const Decl *D) { + if (auto *ND = dyn_cast_or_null(&*D)) + switch (ND->getVisibility()) { + case HiddenVisibility: + return CXVisibility_Hidden; + case ProtectedVisibility: + return CXVisibility_Protected; + case DefaultVisibility: + return CXVisibility_Default; + }; + + return CXVisibility_Invalid; +} + +// Adapted from clang_getCXXAccessSpecifier in CIndexCXX.cpp +CX_CXXAccessSpecifier TranslateCXXAccessSpecifier(AccessSpecifier spec) { + switch (spec) { + case AS_public: return CX_CXXPublic; + case AS_protected: return CX_CXXProtected; + case AS_private: return CX_CXXPrivate; + case AS_none: return CX_CXXInvalidAccessSpecifier; + } + + llvm_unreachable("Invalid AccessSpecifier!"); +} + +// Adapted from clang_Cursor_getArgument in CXCursor.cpp +const Expr *Expr_getArgument(const Expr *E, unsigned i) { + if (const CallExpr *CE = dyn_cast_or_null(&*E)) { + if (i < CE->getNumArgs()) { + return CE->getArg(i); + } + } + if (const CXXConstructExpr *CE = dyn_cast_or_null(&*E)) { + if (i < CE->getNumArgs()) { + return CE->getArg(i); + } + } + return nullptr; +} + +// Adapted from clang_Cursor_getNumArguments in CXCursor.cpp +int Expr_getNumArguments(const Expr *E) { + if (const CallExpr *CE = dyn_cast_or_null(&*E)) + return CE->getNumArgs(); + if (const CXXConstructExpr *CE = dyn_cast_or_null(&*E)) + return CE->getNumArgs(); + return -1; +} + +// Adapted from getLocationFromExpr in CIndex.cpp +SourceLocation *Expr_getLocation(const Expr *E) { + if (!E) + return nullptr; + if (const ImplicitCastExpr *CE = dyn_cast(&*E)) + return Expr_getLocation(CE->getSubExpr()); + + if (const ObjCMessageExpr *Msg = dyn_cast(&*E)) + return new SourceLocation(/*FIXME:*/Msg->getLeftLoc()); + if (const DeclRefExpr *DRE = dyn_cast(&*E)) + return new SourceLocation(DRE->getLocation()); + if (const MemberExpr *Member = dyn_cast(&*E)) + return new SourceLocation(Member->getMemberLoc()); + if (const ObjCIvarRefExpr *Ivar = dyn_cast(&*E)) + return new SourceLocation(Ivar->getLocation()); + if (const SizeOfPackExpr *SizeOfPack = dyn_cast(&*E)) + return new SourceLocation(SizeOfPack->getPackLoc()); + if (const ObjCPropertyRefExpr *PropRef = dyn_cast(&*E)) + return new SourceLocation(PropRef->getLocation()); + +#if CLANG_VERSION_MAJOR > 6 + return new SourceLocation(E->getBeginLoc()); +#else + return new SourceLocation(E->getLocStart()); +#endif +} + +// Adapted from clang_getTypeDeclaration in CXType.cpp +const Decl *Type_getDeclaration(BindgenQualType T) { + auto QT = QualType::getFromOpaquePtr(T); + const Type *TP = QT.getTypePtrOrNull(); + + if (!TP) + return nullptr; + + const Decl *D = nullptr; + +try_again: + switch (TP->getTypeClass()) { + case Type::Typedef: + D = cast(TP)->getDecl(); + break; + case Type::ObjCObject: + D = cast(TP)->getInterface(); + break; + case Type::ObjCInterface: + D = cast(TP)->getDecl(); + break; + case Type::Record: + case Type::Enum: + D = cast(TP)->getDecl(); + break; + case Type::TemplateSpecialization: + if (const RecordType *Record = TP->getAs()) + D = Record->getDecl(); + else + D = cast(TP)->getTemplateName() + .getAsTemplateDecl(); + break; + + case Type::Auto: +#if CLANG_VERSION_MAJOR > 4 + case Type::DeducedTemplateSpecialization: + TP = cast(TP)->getDeducedType().getTypePtrOrNull(); +#else // CLANG_VERSION_MAJOR <= 4 + TP = cast(TP)->getDeducedType().getTypePtrOrNull(); +#endif // CLANG_VERSION_MAJOR > 4 + if (TP) + goto try_again; + break; + + case Type::InjectedClassName: + D = cast(TP)->getDecl(); + break; + + // FIXME: Template type parameters! + + case Type::Elaborated: + TP = cast(TP)->getNamedType().getTypePtrOrNull(); + goto try_again; + + default: + break; + } + + if (!D) + return nullptr; + + return D; +} + +// Adapted from getTokens and others in CIndex.cpp +void tokenize(ASTUnit *TU, BindgenSourceRange Range, CXToken **Tokens, + unsigned *NumTokens) { + if (!Tokens || !NumTokens || !Range.B || !Range.E) + return; + + // Translate the Range end location to after the last token, instead of + // the beginning of the last token. + SourceManager &SourceMgr = TU->getSourceManager(); + SourceLocation EndLoc = *Range.E; + bool IsTokenRange = true; + if (EndLoc.isValid() && EndLoc.isMacroID() && !SourceMgr.isMacroArgExpansion(EndLoc)) { +#if CLANG_VERSION_MAJOR > 6 + CharSourceRange Expansion = SourceMgr.getExpansionRange(EndLoc); + EndLoc = Expansion.getEnd(); + IsTokenRange = Expansion.isTokenRange(); +#else + EndLoc = SourceMgr.getExpansionRange(EndLoc).second; +#endif + } + if (IsTokenRange && EndLoc.isValid()) { + unsigned Length = Lexer::MeasureTokenLength(SourceMgr.getSpellingLoc(EndLoc), + SourceMgr, TU->getLangOpts()); + EndLoc = EndLoc.getLocWithOffset(Length); + } + + SmallVector CXTokens; + std::pair BeginLocInfo = + SourceMgr.getDecomposedSpellingLoc(*Range.B); + std::pair EndLocInfo = + SourceMgr.getDecomposedSpellingLoc(EndLoc); + + // BindgenSourceRange elements need to be manually destructed because it is + // C-style struct shared with Rust. + delete Range.B; + delete Range.E; + + // Cannot tokenize across files. + if (BeginLocInfo.first != EndLocInfo.first) + return; + + // Create a lexer + bool Invalid = false; + StringRef Buffer + = SourceMgr.getBufferData(BeginLocInfo.first, &Invalid); + if (Invalid) + return; + + Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first), + TU->getASTContext().getLangOpts(), + Buffer.begin(), Buffer.data() + BeginLocInfo.second, Buffer.end()); + Lex.SetCommentRetentionState(true); + + // Lex tokens until we hit the end of the range. + const char *EffectiveBufferEnd = Buffer.data() + EndLocInfo.second; + Token Tok; + bool previousWasAt = false; + do { + // Lex the next token + Lex.LexFromRawLexer(Tok); + if (Tok.is(tok::eof)) + break; + + // Initialize the CXToken. + CXToken CXTok; + + // - Common fields + CXTok.int_data[1] = Tok.getLocation().getRawEncoding(); + CXTok.int_data[2] = Tok.getLength(); + CXTok.int_data[3] = 0; + + // - Kind-specific fields + if (Tok.isLiteral()) { + CXTok.int_data[0] = CXToken_Literal; + CXTok.ptr_data = const_cast(Tok.getLiteralData()); + } else if (Tok.is(tok::raw_identifier)) { + // Lookup the identifier to determine whether we have a keyword. + IdentifierInfo *II + = TU->getPreprocessor().LookUpIdentifierInfo(Tok); + + if ((II->getObjCKeywordID() != tok::objc_not_keyword) && previousWasAt) { + CXTok.int_data[0] = CXToken_Keyword; + } + else { + CXTok.int_data[0] = Tok.is(tok::identifier) + ? CXToken_Identifier + : CXToken_Keyword; + } + CXTok.ptr_data = II; + } else if (Tok.is(tok::comment)) { + CXTok.int_data[0] = CXToken_Comment; + CXTok.ptr_data = nullptr; + } else { + CXTok.int_data[0] = CXToken_Punctuation; + CXTok.ptr_data = nullptr; + } + CXTokens.push_back(CXTok); + previousWasAt = Tok.is(tok::at); + } while (Lex.getBufferLocation() < EffectiveBufferEnd); + + *Tokens = new CXToken[CXTokens.size()]; + memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size()); + *NumTokens = CXTokens.size(); +} + +// Adapted from CursorVisitor:visitPreprocessedEntities in CIndex.cpp +bool PreprocessedEntity_isFunctionMacroLike(ASTUnit *TU, + const PreprocessedEntity *ppe) { + return isa(ppe) && + TU->getPreprocessor() + .getMacroInfo(cast(ppe)->getName()) + ->isFunctionLike(); +} + +// Originally clang_getTokenKind in CIndex.cpp +CXTokenKind getTokenKind(CXToken token) { + return static_cast(token.int_data[0]); +} + +// Adapted from clang_getTokenSpelling in CIndex.cpp +BindgenStringRef getTokenSpelling(ASTUnit *CXXUnit, CXToken CXTok) { + if (!CXXUnit) + return stringref(); + + switch (getTokenKind(CXTok)) { + case CXToken_Identifier: + case CXToken_Keyword: + // We know we have an IdentifierInfo*, so use that. + return stringref(static_cast(CXTok.ptr_data) + ->getNameStart()); + + case CXToken_Literal: { + // We have stashed the starting pointer in the ptr_data field. Use it. + const char *Text = static_cast(CXTok.ptr_data); + return stringref(StringRef(Text, CXTok.int_data[2])); + } + + case CXToken_Punctuation: + case CXToken_Comment: + break; + } + + // We have to find the starting buffer pointer the hard way, by + // deconstructing the source location. + SourceLocation Loc = SourceLocation::getFromRawEncoding(CXTok.int_data[1]); + std::pair LocInfo + = CXXUnit->getSourceManager().getDecomposedSpellingLoc(Loc); + bool Invalid = false; + StringRef Buffer + = CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid); + if (Invalid) + return stringref(); + + return stringref(Buffer.substr(LocInfo.second, CXTok.int_data[2])); +} + +// Adapted from clang_Type_getSizeOf in CXType.cpp +long long Type_getSizeOf(BindgenQualType T, ASTContext *Context) { + auto QT = QualType::getFromOpaquePtr(T); + if (QT.isNull()) + return CXTypeLayoutError_Invalid; + // [expr.sizeof] p2: if reference type, return size of referenced type + if (QT->isReferenceType()) + QT = QT.getNonReferenceType(); + // [expr.sizeof] p1: return -1 on: func, incomplete, bitfield, incomplete + // enumeration + // Note: We get the cxtype, not the cxcursor, so we can't call + // FieldDecl->isBitField() + // [expr.sizeof] p3: pointer ok, function not ok. + // [gcc extension] lib/AST/ExprConstant.cpp:1372 HandleSizeof : vla == error + if (QT->isIncompleteType()) + return CXTypeLayoutError_Incomplete; + if (QT->isDependentType()) + return CXTypeLayoutError_Dependent; + if (!QT->isConstantSizeType()) + return CXTypeLayoutError_NotConstantSize; +#if CLANG_VERSION_MAJOR > 8 + if (const auto *Deduced = dyn_cast(QT)) + if (Deduced->getDeducedType().isNull()) + return CXTypeLayoutError_Undeduced; +#endif // CLANG_VERSION_MAJOR > 8 + // [gcc extension] lib/AST/ExprConstant.cpp:1372 + // HandleSizeof : {voidtype,functype} == 1 + // not handled by ASTContext.cpp:1313 getTypeInfoImpl + if (QT->isVoidType() || QT->isFunctionType()) + return 1; + return Context->getTypeSizeInChars(QT).getQuantity(); +} + +// Adapted from clang_Type_getAlignOf in CXType.cpp +long long Type_getAlignOf(BindgenQualType T, ASTContext *Context) { + auto QT = QualType::getFromOpaquePtr(T); + if (QT.isNull()) + return CXTypeLayoutError_Invalid; + // [expr.alignof] p1: return size_t value for complete object type, reference + // or array. + // [expr.alignof] p3: if reference type, return size of referenced type + if (QT->isReferenceType()) + QT = QT.getNonReferenceType(); + if (!(QT->isIncompleteArrayType() || !QT->isIncompleteType())) + return CXTypeLayoutError_Incomplete; + if (QT->isDependentType()) + return CXTypeLayoutError_Dependent; +#if CLANG_VERSION_MAJOR > 8 + if (const auto *Deduced = dyn_cast(QT)) + if (Deduced->getDeducedType().isNull()) + return CXTypeLayoutError_Undeduced; +#endif // CLANG_VERSION_MAJOR > 8 + // Exceptions by GCC extension - see ASTContext.cpp:1313 getTypeInfoImpl + // if (QT->isFunctionType()) return 4; // Bug #15511 - should be 1 + // if (QT->isVoidType()) return 1; + return Context->getTypeAlignInChars(QT).getQuantity(); +} + +// Adapted from clang_getPointeeType in CXType.cpp +BindgenQualType Type_getPointeeType(BindgenQualType T) { + auto QT = QualType::getFromOpaquePtr(T); + const Type *TP = QT.getTypePtrOrNull(); + + if (!TP) + return nullptr; + +try_again: + switch (TP->getTypeClass()) { + case Type::Pointer: + QT = cast(TP)->getPointeeType(); + break; + case Type::BlockPointer: + QT = cast(TP)->getPointeeType(); + break; + case Type::LValueReference: + case Type::RValueReference: + QT = cast(TP)->getPointeeType(); + break; + case Type::ObjCObjectPointer: + QT = cast(TP)->getPointeeType(); + break; + case Type::MemberPointer: + QT = cast(TP)->getPointeeType(); + break; + case Type::Auto: +#if CLANG_VERSION_MAJOR > 4 + case Type::DeducedTemplateSpecialization: + TP = cast(TP)->getDeducedType().getTypePtrOrNull(); +#else // CLANG_VERSION_MAJOR <= 4 + TP = cast(TP)->getDeducedType().getTypePtrOrNull(); +#endif // CLANG_VERSION_MAJOR > 4 + if (TP) + goto try_again; + break; + default: + QT = QualType(); + break; + } + return make_type_compatible(QT); +} + +// Adapted from clang_getElementType in CXType.cpp +BindgenQualType Type_getElementType(BindgenQualType T) { + auto QT = QualType::getFromOpaquePtr(T); + QualType ET = QualType(); + const Type *TP = QT.getTypePtrOrNull(); + + if (TP) { + switch (TP->getTypeClass()) { + case Type::ConstantArray: + ET = cast (TP)->getElementType(); + break; + case Type::IncompleteArray: + ET = cast (TP)->getElementType(); + break; + case Type::VariableArray: + ET = cast (TP)->getElementType(); + break; + case Type::DependentSizedArray: + ET = cast (TP)->getElementType(); + break; + case Type::Vector: + ET = cast (TP)->getElementType(); + break; + case Type::ExtVector: + ET = cast(TP)->getElementType(); + break; + case Type::Complex: + ET = cast (TP)->getElementType(); + break; + default: + break; + } + } + return make_type_compatible(ET); +} + +// Adapted from clang_getNumElements in CXType.cpp +int Type_getNumElements(BindgenQualType T) { + auto QT = QualType::getFromOpaquePtr(T); + long long result = -1; + const Type *TP = QT.getTypePtrOrNull(); + + if (TP) { + switch (TP->getTypeClass()) { + case Type::ConstantArray: + result = cast (TP)->getSize().getSExtValue(); + break; + case Type::Vector: + result = cast (TP)->getNumElements(); + break; + case Type::ExtVector: + result = cast(TP)->getNumElements(); + break; + default: + break; + } + } + return result; +} + +// Adapted from clang_getFunctionTypeCallingConv in CXType.cpp +CXCallingConv Type_getFunctionTypeCallingConv(BindgenQualType T) { + auto QT = QualType::getFromOpaquePtr(T); + if (QT.isNull()) + return CXCallingConv_Invalid; + + if (const FunctionType *FD = QT->getAs()) { +#define TCALLINGCONV(X) case CC_##X: return CXCallingConv_##X + switch (FD->getCallConv()) { + TCALLINGCONV(C); + TCALLINGCONV(X86StdCall); + TCALLINGCONV(X86FastCall); + TCALLINGCONV(X86ThisCall); + TCALLINGCONV(X86Pascal); +#if CLANG_VERSION_MAJOR > 3 + TCALLINGCONV(X86RegCall); +#endif // CLANG_VERSION_MAJOR > 3 + TCALLINGCONV(X86VectorCall); +#if CLANG_VERSION_MAJOR > 7 + TCALLINGCONV(AArch64VectorCall); +#endif // CLANG_VERSION_MAJOR > 7 +#if CLANG_VERSION_MAJOR > 4 + TCALLINGCONV(Win64); +#else + TCALLINGCONV(X86_64Win64); +#endif // CLANG_VERSION_MAJOR > 4 + TCALLINGCONV(X86_64SysV); + TCALLINGCONV(AAPCS); + TCALLINGCONV(AAPCS_VFP); + TCALLINGCONV(IntelOclBicc); +#if CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + TCALLINGCONV(Swift); + TCALLINGCONV(PreserveMost); + TCALLINGCONV(PreserveAll); + case CC_OpenCLKernel: return CXCallingConv_Unexposed; +#else // CLANG_VERSION <= 3.8 + case CC_SpirKernel: return CXCallingConv_Unexposed; +#endif // CLANG_VERSION > 3.8 + case CC_SpirFunction: return CXCallingConv_Unexposed; + break; + } +#undef TCALLINGCONV + } + + return CXCallingConv_Invalid; +} + +// Adapted from clang_getSpellingLocation in CXSourceLocation.cpp +void getSpellingLocation(ASTUnit *AST, const SourceLocation *location, FileEntry **file, int *line, int *column, int *offset) { + if (!location) + return createNullLocation(file, line, column, offset); + + const SourceManager &SM = AST->getSourceManager(); + // FIXME: This should call SourceManager::getSpellingLoc(). + SourceLocation SpellLoc = SM.getFileLoc(*location); + std::pair LocInfo = SM.getDecomposedLoc(SpellLoc); + FileID FID = LocInfo.first; + unsigned FileOffset = LocInfo.second; + + if (FID.isInvalid()) + return createNullLocation(file, line, column, offset); + + if (file) + *file = const_cast(SM.getFileEntryForID(FID)); + if (line) + *line = SM.getLineNumber(FID, FileOffset); + if (column) + *column = SM.getColumnNumber(FID, FileOffset); + if (offset) + *offset = FileOffset; +} + +// From CIndex.cpp +static std::string getMangledStructor(std::unique_ptr &M, + std::unique_ptr &DL, + const NamedDecl *ND, + unsigned StructorType) { + std::string FrontendBuf; + llvm::raw_string_ostream FOS(FrontendBuf); + +#if CLANG_VERSION_MAJOR >= 11 + auto ctorMangler = [&](auto&& x){ M->mangleName(GlobalDecl(x, static_cast(StructorType)), FOS); }; + auto dtorMangler = [&](auto&& x){ M->mangleName(GlobalDecl(x, static_cast(StructorType)), FOS); }; +#else + auto ctorMangler = [&](auto&& x){ M->mangleCXXCtor(x, static_cast(StructorType), FOS); }; + auto dtorMangler = [&](auto&& x){ M->mangleCXXDtor(x, static_cast(StructorType), FOS); }; + #endif + if (const auto *CD = dyn_cast_or_null(ND)) + ctorMangler(CD); + else if (const auto *DD = dyn_cast_or_null(ND)) + dtorMangler(DD); + + std::string BackendBuf; + llvm::raw_string_ostream BOS(BackendBuf); + + llvm::Mangler::getNameWithPrefix(BOS, llvm::Twine(FOS.str()), *DL); + + return BOS.str(); +} + +// Adapted from clang_Cursor_getMangling in CIndex.cpp +BindgenStringRef Decl_getMangling(const Decl *D, ASTContext *Ctx) { + if (!D || !(isa(&*D) || isa(&*D))) + return stringref(); + +#if CLANG_VERSION_MAJOR > 8 + ASTNameGenerator NameGen(*Ctx); + return stringref(NameGen.getName(&*D)); +#elif CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + index::CodegenNameGenerator NameGen(*Ctx); + return stringref(NameGen.getName(&*D)); +#else // CLANG_VERSION <= 3.8 + // First apply frontend mangling. + const NamedDecl *ND = cast(D); + std::unique_ptr MC(Ctx->createMangleContext()); + + std::string FrontendBuf; + llvm::raw_string_ostream FrontendBufOS(FrontendBuf); + if (MC->shouldMangleDeclName(ND)) { + MC->mangleName(ND, FrontendBufOS); + } else { + ND->printName(FrontendBufOS); + } + + // Now apply backend mangling. + std::unique_ptr DL( + new llvm::DataLayout(Ctx->getTargetInfo().getDataLayoutString())); + + std::string FinalBuf; + llvm::raw_string_ostream FinalBufOS(FinalBuf); + llvm::Mangler::getNameWithPrefix(FinalBufOS, llvm::Twine(FrontendBufOS.str()), + *DL); + return stringref(FinalBuf); +#endif // CLANG_VERSION_MAJOR > 8 +} + +// Adapted from clang_Cursor_getCXXManglings in CIndex.cpp +BindgenStringRefSet Decl_getCXXManglings(const Decl *D, ASTContext *Ctx) { + if (!D || !(isa(&*D) || isa(&*D))) + return BindgenStringRefSet(); + + std::vector Manglings; + +#if CLANG_VERSION_MAJOR > 8 + ASTNameGenerator NameGen(*Ctx); + Manglings = NameGen.getAllManglings(&*D); +#elif CLANG_VERSION_MAJOR > 3 || (CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR == 9) + index::CodegenNameGenerator NameGen(*Ctx); + Manglings = NameGen.getAllManglings(&*D); +#else // CLANG_VERSION <= 3.8 + const NamedDecl *ND = cast(D); + + std::unique_ptr M(Ctx->createMangleContext()); + std::unique_ptr DL( + new llvm::DataLayout(Ctx->getTargetInfo().getDataLayoutString())); + + auto hasDefaultCXXMethodCC = [](ASTContext &C, const CXXMethodDecl *MD) { + auto DefaultCC = C.getDefaultCallingConvention(/*IsVariadic=*/false, + /*IsCSSMethod=*/true); + auto CC = MD->getType()->getAs()->getCallConv(); + return CC == DefaultCC; + }; + + if (const auto *CD = dyn_cast_or_null(ND)) { + Manglings.emplace_back(getMangledStructor(M, DL, CD, Ctor_Base)); + + if (Ctx->getTargetInfo().getCXXABI().isItaniumFamily()) + if (!CD->getParent()->isAbstract()) + Manglings.emplace_back(getMangledStructor(M, DL, CD, Ctor_Complete)); + + if (Ctx->getTargetInfo().getCXXABI().isMicrosoft()) + if (CD->hasAttr() && CD->isDefaultConstructor()) + if (!(hasDefaultCXXMethodCC(*Ctx, CD) && CD->getNumParams() == 0)) + Manglings.emplace_back(getMangledStructor(M, DL, CD, + Ctor_DefaultClosure)); + } else if (const auto *DD = dyn_cast_or_null(ND)) { + Manglings.emplace_back(getMangledStructor(M, DL, DD, Dtor_Base)); + if (Ctx->getTargetInfo().getCXXABI().isItaniumFamily()) { + Manglings.emplace_back(getMangledStructor(M, DL, DD, Dtor_Complete)); + if (DD->isVirtual()) + Manglings.emplace_back(getMangledStructor(M, DL, DD, Dtor_Deleting)); + } + } +#endif // CLANG_VERSION_MAJOR > 8 + + return make_stringrefset(Manglings); +} diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs index 9bcda508ee..eadc3fe88d 100644 --- a/src/ir/annotations.rs +++ b/src/ir/annotations.rs @@ -164,7 +164,7 @@ impl Annotations { } fn parse(&mut self, comment: &clang::Comment, matched: &mut bool) { - use clang_sys::CXComment_HTMLStartTag; + use clang::CXComment_HTMLStartTag; if comment.kind() == CXComment_HTMLStartTag && comment.get_tag_name() == "div" && comment diff --git a/src/ir/comp.rs b/src/ir/comp.rs index a221e52074..58968cec3b 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -10,6 +10,7 @@ use super::template::TemplateParameters; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::RUST_DERIVE_IN_ARRAY_LIMIT; use crate::clang; +use crate::clang::*; use crate::codegen::struct_layout::{align_to, bytes_from_bits_pow2}; use crate::ir::derive::CanDeriveCopy; use crate::parse::{ClangItemParser, ParseError}; @@ -1245,7 +1246,6 @@ impl CompInfo { location: Option, ctx: &mut BindgenContext, ) -> Result { - use clang_sys::*; assert!( ty.template_args().is_none(), "We handle template instantiations elsewhere" @@ -1445,8 +1445,7 @@ impl CompInfo { ty: type_id, kind, field_name, - is_pub: cur.access_specifier() == - clang_sys::CX_CXXPublic, + is_pub: cur.access_specifier() == clang::CX_CXXPublic, }); } CXCursor_Constructor | CXCursor_Destructor | @@ -1574,7 +1573,6 @@ impl CompInfo { fn kind_from_cursor( cursor: &clang::Cursor, ) -> Result { - use clang_sys::*; Ok(match cursor.kind() { CXCursor_UnionDecl => CompKind::Union, CXCursor_ClassDecl | CXCursor_StructDecl => CompKind::Struct, diff --git a/src/ir/context.rs b/src/ir/context.rs index 3bfe549b28..2541313f61 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -25,7 +25,6 @@ use crate::parse::ClangItemParser; use crate::BindgenOptions; use crate::{Entry, HashMap, HashSet}; use cexpr; -use clang_sys; use proc_macro2::{Ident, Span}; use std::borrow::Cow; use std::cell::{Cell, RefCell}; @@ -511,17 +510,19 @@ impl BindgenContext { // TODO(emilio): Use the CXTargetInfo here when available. // // see: https://reviews.llvm.org/D32389 - let index = clang::Index::new(false, true); + // TODO(kulp): Use results of find_effective_target or else drop this check. + let (_effective_target, _explicit_target) = + crate::find_effective_target(&options.clang_args); let parse_options = - clang_sys::CXTranslationUnit_DetailedPreprocessingRecord; + clang::CXTranslationUnit_DetailedPreprocessingRecord; let translation_unit = { let _t = Timer::new("translation_unit").with_output(options.time_phases); clang::TranslationUnit::parse( - &index, + // &index, "", &options.clang_args, &options.input_unsaved_files, @@ -778,10 +779,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" item.expect_type().is_type_param(), "Should directly be a named type, not a resolved reference or anything" ); - assert_eq!( - definition.kind(), - clang_sys::CXCursor_TemplateTypeParameter - ); + assert_eq!(definition.kind(), clang::CXCursor_TemplateTypeParameter); self.add_item_to_module(&item); @@ -804,10 +802,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Get the named type defined at the given cursor location, if we've /// already added one. pub fn get_type_param(&self, definition: &clang::Cursor) -> Option { - assert_eq!( - definition.kind(), - clang_sys::CXCursor_TemplateTypeParameter - ); + assert_eq!(definition.kind(), clang::CXCursor_TemplateTypeParameter); self.type_params.get(definition).cloned() } @@ -1618,12 +1613,12 @@ If you encounter an error missing from this list, please file an issue or a PR!" // on accident. let idx = children .iter() - .position(|c| c.kind() == clang_sys::CXCursor_TemplateRef); + .position(|c| c.kind() == clang::CXCursor_TemplateRef); if let Some(idx) = idx { if children .iter() .take(idx) - .all(|c| c.kind() == clang_sys::CXCursor_NamespaceRef) + .all(|c| c.kind() == clang::CXCursor_NamespaceRef) { children = children.into_iter().skip(idx + 1).collect(); } @@ -1632,9 +1627,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" for child in children.iter().rev() { match child.kind() { - clang_sys::CXCursor_TypeRef | - clang_sys::CXCursor_TypedefDecl | - clang_sys::CXCursor_TypeAliasDecl => { + clang::CXCursor_TypeRef | + clang::CXCursor_TypedefDecl | + clang::CXCursor_TypeAliasDecl => { // The `with_id` id will potentially end up unused if we give up // on this type (for example, because it has const value // template args), so if we pass `with_id` as the parent, it is @@ -1649,7 +1644,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" ); args.push(ty); } - clang_sys::CXCursor_TemplateRef => { + clang::CXCursor_TemplateRef => { let ( template_decl_cursor, template_decl_id, @@ -1817,7 +1812,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" ty: &clang::Type, location: Option, ) -> Option { - use clang_sys::{CXCursor_TypeAliasTemplateDecl, CXCursor_TypeRef}; + use clang::{CXCursor_TypeAliasTemplateDecl, CXCursor_TypeRef}; debug!( "builtin_or_resolved_ty: {:?}, {:?}, {:?}, {:?}", ty, location, with_id, parent_id @@ -1938,40 +1933,43 @@ If you encounter an error missing from this list, please file an issue or a PR!" } fn build_builtin_ty(&mut self, ty: &clang::Type) -> Option { - use clang_sys::*; let type_kind = match ty.kind() { - CXType_NullPtr => TypeKind::NullPtr, - CXType_Void => TypeKind::Void, - CXType_Bool => TypeKind::Int(IntKind::Bool), - CXType_Int => TypeKind::Int(IntKind::Int), - CXType_UInt => TypeKind::Int(IntKind::UInt), - CXType_Char_S => TypeKind::Int(IntKind::Char { is_signed: true }), - CXType_Char_U => TypeKind::Int(IntKind::Char { is_signed: false }), - CXType_SChar => TypeKind::Int(IntKind::SChar), - CXType_UChar => TypeKind::Int(IntKind::UChar), - CXType_Short => TypeKind::Int(IntKind::Short), - CXType_UShort => TypeKind::Int(IntKind::UShort), - CXType_WChar => TypeKind::Int(IntKind::WChar), - CXType_Char16 => TypeKind::Int(IntKind::U16), - CXType_Char32 => TypeKind::Int(IntKind::U32), - CXType_Long => TypeKind::Int(IntKind::Long), - CXType_ULong => TypeKind::Int(IntKind::ULong), - CXType_LongLong => TypeKind::Int(IntKind::LongLong), - CXType_ULongLong => TypeKind::Int(IntKind::ULongLong), - CXType_Int128 => TypeKind::Int(IntKind::I128), - CXType_UInt128 => TypeKind::Int(IntKind::U128), - CXType_Float => TypeKind::Float(FloatKind::Float), - CXType_Double => TypeKind::Float(FloatKind::Double), - CXType_LongDouble => TypeKind::Float(FloatKind::LongDouble), - CXType_Float128 => TypeKind::Float(FloatKind::Float128), - CXType_Complex => { + clang::CXType_NullPtr => TypeKind::NullPtr, + clang::CXType_Void => TypeKind::Void, + clang::CXType_Bool => TypeKind::Int(IntKind::Bool), + clang::CXType_Int => TypeKind::Int(IntKind::Int), + clang::CXType_UInt => TypeKind::Int(IntKind::UInt), + clang::CXType_Char_S => { + TypeKind::Int(IntKind::Char { is_signed: true }) + } + clang::CXType_Char_U => { + TypeKind::Int(IntKind::Char { is_signed: false }) + } + clang::CXType_SChar => TypeKind::Int(IntKind::SChar), + clang::CXType_UChar => TypeKind::Int(IntKind::UChar), + clang::CXType_Short => TypeKind::Int(IntKind::Short), + clang::CXType_UShort => TypeKind::Int(IntKind::UShort), + clang::CXType_WChar => TypeKind::Int(IntKind::WChar), + clang::CXType_Char16 => TypeKind::Int(IntKind::U16), + clang::CXType_Char32 => TypeKind::Int(IntKind::U32), + clang::CXType_Long => TypeKind::Int(IntKind::Long), + clang::CXType_ULong => TypeKind::Int(IntKind::ULong), + clang::CXType_LongLong => TypeKind::Int(IntKind::LongLong), + clang::CXType_ULongLong => TypeKind::Int(IntKind::ULongLong), + clang::CXType_Int128 => TypeKind::Int(IntKind::I128), + clang::CXType_UInt128 => TypeKind::Int(IntKind::U128), + clang::CXType_Float => TypeKind::Float(FloatKind::Float), + clang::CXType_Double => TypeKind::Float(FloatKind::Double), + clang::CXType_LongDouble => TypeKind::Float(FloatKind::LongDouble), + clang::CXType_Float128 => TypeKind::Float(FloatKind::Float128), + clang::CXType_Complex => { let float_type = ty.elem_type().expect("Not able to resolve complex type?"); let float_kind = match float_type.kind() { - CXType_Float => FloatKind::Float, - CXType_Double => FloatKind::Double, - CXType_LongDouble => FloatKind::LongDouble, - CXType_Float128 => FloatKind::Float128, + clang::CXType_Float => FloatKind::Float, + clang::CXType_Double => FloatKind::Double, + clang::CXType_LongDouble => FloatKind::LongDouble, + clang::CXType_Float128 => FloatKind::Float128, _ => panic!( "Non floating-type complex? {:?}, {:?}", ty, float_type, @@ -2091,7 +2089,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" ) -> (Option, ModuleKind) { assert_eq!( cursor.kind(), - ::clang_sys::CXCursor_Namespace, + clang::CXCursor_Namespace, "Be a nice person" ); @@ -2166,7 +2164,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Given a CXCursor_Namespace cursor, return the item id of the /// corresponding module, or create one on the fly. pub fn module(&mut self, cursor: clang::Cursor) -> ModuleId { - use clang_sys::*; + use clang::*; assert_eq!(cursor.kind(), CXCursor_Namespace, "Be a nice person"); let cursor = cursor.canonical(); if let Some(id) = self.modules.get(&cursor) { @@ -2813,20 +2811,20 @@ impl TemplateParameters for PartialType { // Wouldn't it be nice if libclang would reliably give us this // information‽ match self.decl().kind() { - clang_sys::CXCursor_ClassTemplate | - clang_sys::CXCursor_FunctionTemplate | - clang_sys::CXCursor_TypeAliasTemplateDecl => { + clang::CXCursor_ClassTemplate | + clang::CXCursor_FunctionTemplate | + clang::CXCursor_TypeAliasTemplateDecl => { let mut num_params = 0; self.decl().visit(|c| { match c.kind() { - clang_sys::CXCursor_TemplateTypeParameter | - clang_sys::CXCursor_TemplateTemplateParameter | - clang_sys::CXCursor_NonTypeTemplateParameter => { + clang::CXCursor_TemplateTypeParameter | + clang::CXCursor_TemplateTemplateParameter | + clang::CXCursor_NonTypeTemplateParameter => { num_params += 1; } _ => {} }; - clang_sys::CXChildVisit_Continue + clang::CXChildVisit_Continue }); num_params } diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 97455c9123..0e969b6330 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -3,7 +3,7 @@ use super::super::codegen::EnumVariation; use super::context::{BindgenContext, TypeId}; use super::item::Item; -use super::ty::{Type, TypeKind}; +use super::ty::TypeKind; use crate::clang; use crate::ir::annotations::Annotations; use crate::parse::{ClangItemParser, ParseError}; @@ -55,7 +55,7 @@ impl Enum { ty: &clang::Type, ctx: &mut BindgenContext, ) -> Result { - use clang_sys::*; + use clang::*; debug!("Enum::from_ty {:?}", ty); if ty.kind() != CXType_Enum { @@ -70,7 +70,7 @@ impl Enum { let variant_ty = repr.and_then(|r| ctx.resolve_type(r).safe_canonical_type(ctx)); - let is_bool = variant_ty.map_or(false, Type::is_bool); + let is_bool = variant_ty.map_or(false, super::ty::Type::is_bool); // Assume signedness since the default type by the C standard is an int. let is_signed = variant_ty.map_or(true, |ty| match *ty.kind() { diff --git a/src/ir/function.rs b/src/ir/function.rs index e8e2c2dfed..6f25a401fe 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -10,7 +10,6 @@ use crate::clang; use crate::parse::{ ClangItemParser, ClangSubItemParser, ParseError, ParseResult, }; -use clang_sys::{self, CXCallingConv}; use proc_macro2; use quote; use quote::TokenStreamExt; @@ -33,11 +32,11 @@ impl FunctionKind { pub fn from_cursor(cursor: &clang::Cursor) -> Option { // FIXME(emilio): Deduplicate logic with `ir::comp`. Some(match cursor.kind() { - clang_sys::CXCursor_FunctionDecl => FunctionKind::Function, - clang_sys::CXCursor_Constructor => { + clang::CXCursor_FunctionDecl => FunctionKind::Function, + clang::CXCursor_Constructor => { FunctionKind::Method(MethodKind::Constructor) } - clang_sys::CXCursor_Destructor => { + clang::CXCursor_Destructor => { FunctionKind::Method(if cursor.method_is_virtual() { MethodKind::VirtualDestructor { pure_virtual: cursor.method_is_pure_virtual(), @@ -46,7 +45,7 @@ impl FunctionKind { MethodKind::Destructor }) } - clang_sys::CXCursor_CXXMethod => { + clang::CXCursor_CXXMethod => { if cursor.method_is_virtual() { FunctionKind::Method(MethodKind::Virtual { pure_virtual: cursor.method_is_pure_virtual(), @@ -188,7 +187,7 @@ pub enum Abi { /// The "win64" ABI. Win64, /// An unknown or invalid ABI. - Unknown(CXCallingConv), + Unknown(clang::CXCallingConv), } impl Abi { @@ -236,8 +235,8 @@ pub struct FunctionSig { abi: Abi, } -fn get_abi(cc: CXCallingConv) -> Abi { - use clang_sys::*; +fn get_abi(cc: clang::CXCallingConv) -> Abi { + use clang::*; match cc { CXCallingConv_Default => Abi::C, CXCallingConv_C => Abi::C, @@ -267,7 +266,7 @@ pub fn cursor_mangling( return None; } - let is_destructor = cursor.kind() == clang_sys::CXCursor_Destructor; + let is_destructor = cursor.kind() == clang::CXCursor_Destructor; if let Ok(mut manglings) = cursor.cxx_manglings() { while let Some(m) = manglings.pop() { // Only generate the destructor group 1, see below. @@ -376,7 +375,7 @@ impl FunctionSig { cursor: &clang::Cursor, ctx: &mut BindgenContext, ) -> Result { - use clang_sys::*; + use clang::*; debug!("FunctionSig::from_ty {:?} {:?}", ty, cursor); // Skip function templates @@ -582,7 +581,7 @@ impl ClangSubItemParser for Function { cursor: clang::Cursor, context: &mut BindgenContext, ) -> Result, ParseError> { - use clang_sys::*; + use clang::*; let kind = match FunctionKind::from_cursor(&cursor) { None => return Err(ParseError::Continue), diff --git a/src/ir/item.rs b/src/ir/item.rs index 3b15cd6ed6..0f91ffd86e 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -22,7 +22,6 @@ use crate::clang; use crate::parse::{ ClangItemParser, ClangSubItemParser, ParseError, ParseResult, }; -use clang_sys; use lazycell::LazyCell; use regex; use std::cell::Cell; @@ -1290,8 +1289,8 @@ fn visit_child( parent_id: Option, ctx: &mut BindgenContext, result: &mut Result, -) -> clang_sys::CXChildVisitResult { - use clang_sys::*; +) -> clang::CXChildVisitResult { + use clang::*; if result.is_ok() { return CXChildVisit_Break; } @@ -1340,7 +1339,7 @@ impl ClangItemParser for Item { ctx: &mut BindgenContext, ) -> Result { use crate::ir::var::Var; - use clang_sys::*; + use clang::*; if !cursor.is_valid() { return Err(ParseError::Continue); @@ -1580,8 +1579,6 @@ impl ClangItemParser for Item { parent_id: Option, ctx: &mut BindgenContext, ) -> Result { - use clang_sys::*; - debug!( "Item::from_ty_with_id: {:?}\n\ \tty = {:?},\n\ @@ -1589,8 +1586,8 @@ impl ClangItemParser for Item { id, ty, location ); - if ty.kind() == clang_sys::CXType_Unexposed || - location.cur_type().kind() == clang_sys::CXType_Unexposed + if ty.kind() == clang::CXType_Unexposed || + location.cur_type().kind() == clang::CXType_Unexposed { if ty.is_associated_type() || location.cur_type().is_associated_type() @@ -1637,10 +1634,10 @@ impl ClangItemParser for Item { } // First, check we're not recursing. - let mut valid_decl = decl.kind() != CXCursor_NoDeclFound; + let mut valid_decl = decl.kind() != clang::CXCursor_NoDeclFound; let declaration_to_look_for = if valid_decl { decl.canonical() - } else if location.kind() == CXCursor_ClassTemplate { + } else if location.kind() == clang::CXCursor_ClassTemplate { valid_decl = true; location } else { @@ -1761,7 +1758,7 @@ impl ClangItemParser for Item { location ); - if ty.kind() != clang_sys::CXType_Unexposed { + if ty.kind() != clang::CXType_Unexposed { // If the given cursor's type's kind is not Unexposed, then we // aren't looking at a template parameter. This check may need to be // updated in the future if they start properly exposing template @@ -1825,7 +1822,7 @@ impl ClangItemParser for Item { regex::Regex::new(r"^type\-parameter\-\d+\-\d+$").unwrap(); } - if refd.kind() != clang_sys::CXCursor_TemplateTypeParameter { + if refd.kind() != clang::CXCursor_TemplateTypeParameter { return false; } @@ -1838,7 +1835,7 @@ impl ClangItemParser for Item { let definition = if is_template_with_spelling(&location, &ty_spelling) { // Situation (1) location - } else if location.kind() == clang_sys::CXCursor_TypeRef { + } else if location.kind() == clang::CXCursor_TypeRef { // Situation (2) match location.referenced() { Some(refd) @@ -1854,7 +1851,7 @@ impl ClangItemParser for Item { location.visit(|child| { let child_ty = child.cur_type(); - if child_ty.kind() == clang_sys::CXCursor_TypeRef && + if child_ty.kind() == clang::CXCursor_TypeRef && child_ty.spelling() == ty_spelling { match child.referenced() { @@ -1865,13 +1862,13 @@ impl ClangItemParser for Item { ) => { definition = Some(refd); - return clang_sys::CXChildVisit_Break; + return clang::CXChildVisit_Break; } _ => {} } } - clang_sys::CXChildVisit_Continue + clang::CXChildVisit_Continue }); definition? diff --git a/src/ir/module.rs b/src/ir/module.rs index d5aca94a6e..80b855ca9c 100644 --- a/src/ir/module.rs +++ b/src/ir/module.rs @@ -77,7 +77,7 @@ impl ClangSubItemParser for Module { cursor: clang::Cursor, ctx: &mut BindgenContext, ) -> Result, ParseError> { - use clang_sys::*; + use clang::*; match cursor.kind() { CXCursor_Namespace => { let module_id = ctx.module(cursor); diff --git a/src/ir/objc.rs b/src/ir/objc.rs index 0845ad0fde..eedc8bb40a 100644 --- a/src/ir/objc.rs +++ b/src/ir/objc.rs @@ -6,16 +6,16 @@ use super::item::Item; use super::traversal::{Trace, Tracer}; use super::ty::TypeKind; use crate::clang; +use crate::clang::CXChildVisit_Continue; +use crate::clang::CXCursor_ObjCCategoryDecl; +use crate::clang::CXCursor_ObjCClassMethodDecl; +use crate::clang::CXCursor_ObjCClassRef; +use crate::clang::CXCursor_ObjCInstanceMethodDecl; +use crate::clang::CXCursor_ObjCProtocolDecl; +use crate::clang::CXCursor_ObjCProtocolRef; +use crate::clang::CXCursor_ObjCSuperClassRef; +use crate::clang::CXCursor_TemplateTypeParameter; use crate::parse::ClangItemParser; -use clang_sys::CXChildVisit_Continue; -use clang_sys::CXCursor_ObjCCategoryDecl; -use clang_sys::CXCursor_ObjCClassMethodDecl; -use clang_sys::CXCursor_ObjCClassRef; -use clang_sys::CXCursor_ObjCInstanceMethodDecl; -use clang_sys::CXCursor_ObjCProtocolDecl; -use clang_sys::CXCursor_ObjCProtocolRef; -use clang_sys::CXCursor_ObjCSuperClassRef; -use clang_sys::CXCursor_TemplateTypeParameter; use proc_macro2::{Ident, Span, TokenStream}; /// Objective C interface as used in TypeKind diff --git a/src/ir/template.rs b/src/ir/template.rs index 8b06748e2c..35add15187 100644 --- a/src/ir/template.rs +++ b/src/ir/template.rs @@ -222,7 +222,7 @@ impl TemplateInstantiation { ty: &clang::Type, ctx: &mut BindgenContext, ) -> Option { - use clang_sys::*; + use clang::*; let template_args = ty.template_args().map_or(vec![], |args| match ty .canonical_type() diff --git a/src/ir/ty.rs b/src/ir/ty.rs index d573408c3b..8b22d5258d 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -682,7 +682,6 @@ impl Type { parent_id: Option, ctx: &mut BindgenContext, ) -> Result, ParseError> { - use clang_sys::*; { let already_resolved = ctx.builtin_or_resolved_ty( potential_id, @@ -711,8 +710,9 @@ impl Type { // Parse objc protocols as if they were interfaces let mut ty_kind = ty.kind(); match location.kind() { - CXCursor_ObjCProtocolDecl | CXCursor_ObjCCategoryDecl => { - ty_kind = CXType_ObjCInterface + clang::CXCursor_ObjCProtocolDecl | + clang::CXCursor_ObjCCategoryDecl => { + ty_kind = clang::CXType_ObjCInterface } _ => {} } @@ -722,11 +722,11 @@ impl Type { // objc template params, which seem to manifest as a typedef. // We are rewriting them as id to suppress multiple conflicting // typedefs at root level - if ty_kind == CXType_Typedef { - let is_template_type_param = - ty.declaration().kind() == CXCursor_TemplateTypeParameter; + if ty_kind == clang::CXType_Typedef { + let is_template_type_param = ty.declaration().kind() == + clang::CXCursor_TemplateTypeParameter; let is_canonical_objcpointer = - canonical_ty.kind() == CXType_ObjCObjectPointer; + canonical_ty.kind() == clang::CXType_ObjCObjectPointer; // We have found a template type for objc interface if is_canonical_objcpointer && is_template_type_param { @@ -736,7 +736,8 @@ impl Type { } } - if location.kind() == CXCursor_ClassTemplatePartialSpecialization { + if location.kind() == clang::CXCursor_ClassTemplatePartialSpecialization + { // Sorry! (Not sorry) warn!( "Found a partial template specialization; bindgen does not \ @@ -749,8 +750,9 @@ impl Type { )); } - let kind = if location.kind() == CXCursor_TemplateRef || - (ty.template_args().is_some() && ty_kind != CXType_Typedef) + let kind = if location.kind() == clang::CXCursor_TemplateRef || + (ty.template_args().is_some() && + ty_kind != clang::CXType_Typedef) { // This is a template instantiation. match TemplateInstantiation::from_ty(ty, ctx) { @@ -759,9 +761,9 @@ impl Type { } } else { match ty_kind { - CXType_Unexposed + clang::CXType_Unexposed if *ty != canonical_ty && - canonical_ty.kind() != CXType_Invalid && + canonical_ty.kind() != clang::CXType_Invalid && ty.ret_type().is_none() && // Sometime clang desugars some types more than // what we need, specially with function @@ -786,7 +788,7 @@ impl Type { ctx, ); } - CXType_Unexposed | CXType_Invalid => { + clang::CXType_Unexposed | clang::CXType_Invalid => { // For some reason Clang doesn't give us any hint in some // situations where we should generate a function pointer (see // tests/headers/func_ptr_in_struct.h), so we do a guess here @@ -812,9 +814,10 @@ impl Type { TypeKind::Comp(complex) } else { match location.kind() { - CXCursor_CXXBaseSpecifier | - CXCursor_ClassTemplate => { - if location.kind() == CXCursor_CXXBaseSpecifier + clang::CXCursor_CXXBaseSpecifier | + clang::CXCursor_ClassTemplate => { + if location.kind() == + clang::CXCursor_CXXBaseSpecifier { // In the case we're parsing a base specifier // inside an unexposed or invalid type, it means @@ -886,7 +889,7 @@ impl Type { } } } - CXCursor_TypeAliasTemplateDecl => { + clang::CXCursor_TypeAliasTemplateDecl => { debug!("TypeAliasTemplateDecl"); // We need to manually unwind this one. @@ -895,12 +898,12 @@ impl Type { location.visit(|cur| { match cur.kind() { - CXCursor_TypeAliasDecl => { + clang::CXCursor_TypeAliasDecl => { let current = cur.cur_type(); debug_assert_eq!( current.kind(), - CXType_Typedef + clang::CXType_Typedef ); name = current.spelling(); @@ -915,7 +918,7 @@ impl Type { ctx, )); } - CXCursor_TemplateTypeParameter => { + clang::CXCursor_TemplateTypeParameter => { let param = Item::type_param( None, cur, ctx, ) @@ -928,7 +931,7 @@ impl Type { } _ => {} } - CXChildVisit_Continue + clang::CXChildVisit_Continue }); let inner_type = match inner { @@ -945,7 +948,7 @@ impl Type { TypeKind::TemplateAlias(inner_type, args) } - CXCursor_TemplateRef => { + clang::CXCursor_TemplateRef => { let referenced = location.referenced().unwrap(); let referenced_ty = referenced.cur_type(); @@ -965,7 +968,7 @@ impl Type { ctx, ); } - CXCursor_TypeRef => { + clang::CXCursor_TypeRef => { let referenced = location.referenced().unwrap(); let referenced_ty = referenced.cur_type(); let declaration = referenced_ty.declaration(); @@ -987,11 +990,11 @@ impl Type { id.into(), )); } - CXCursor_NamespaceRef => { + clang::CXCursor_NamespaceRef => { return Err(ParseError::Continue); } _ => { - if ty.kind() == CXType_Unexposed { + if ty.kind() == clang::CXType_Unexposed { warn!( "Unexposed type {:?}, recursing inside, \ loc: {:?}", @@ -1007,7 +1010,7 @@ impl Type { } } } - CXType_Auto => { + clang::CXType_Auto => { if canonical_ty == *ty { debug!("Couldn't find deduced type: {:?}", ty); return Err(ParseError::Continue); @@ -1028,15 +1031,15 @@ impl Type { // // We might need to, though, if the context is already in the // process of resolving them. - CXType_ObjCObjectPointer | - CXType_MemberPointer | - CXType_Pointer => { + clang::CXType_ObjCObjectPointer | + clang::CXType_MemberPointer | + clang::CXType_Pointer => { let pointee = ty.pointee_type().unwrap(); let inner = Item::from_ty_or_ref(pointee, location, None, ctx); TypeKind::Pointer(inner) } - CXType_BlockPointer => { + clang::CXType_BlockPointer => { let pointee = ty.pointee_type().expect("Not valid Type?"); let inner = Item::from_ty_or_ref(pointee, location, None, ctx); @@ -1044,7 +1047,8 @@ impl Type { } // XXX: RValueReference is most likely wrong, but I don't think we // can even add bindings for that, so huh. - CXType_RValueReference | CXType_LValueReference => { + clang::CXType_RValueReference | + clang::CXType_LValueReference => { let inner = Item::from_ty_or_ref( ty.pointee_type().unwrap(), location, @@ -1054,7 +1058,8 @@ impl Type { TypeKind::Reference(inner) } // XXX DependentSizedArray is wrong - CXType_VariableArray | CXType_DependentSizedArray => { + clang::CXType_VariableArray | + clang::CXType_DependentSizedArray => { let inner = Item::from_ty( ty.elem_type().as_ref().unwrap(), location, @@ -1064,7 +1069,7 @@ impl Type { .expect("Not able to resolve array element?"); TypeKind::Pointer(inner) } - CXType_IncompleteArray => { + clang::CXType_IncompleteArray => { let inner = Item::from_ty( ty.elem_type().as_ref().unwrap(), location, @@ -1074,11 +1079,11 @@ impl Type { .expect("Not able to resolve array element?"); TypeKind::Array(inner, 0) } - CXType_FunctionNoProto | CXType_FunctionProto => { + clang::CXType_FunctionNoProto | clang::CXType_FunctionProto => { let signature = FunctionSig::from_ty(ty, &location, ctx)?; TypeKind::Function(signature) } - CXType_Typedef => { + clang::CXType_Typedef => { let inner = cursor.typedef_type().expect("Not valid Type?"); let inner = Item::from_ty_or_ref(inner, location, None, ctx); @@ -1093,7 +1098,7 @@ impl Type { TypeKind::Alias(inner) } } - CXType_Enum => { + clang::CXType_Enum => { let enum_ = Enum::from_ty(ty, ctx).expect("Not an enum?"); if name.is_empty() { @@ -1105,7 +1110,7 @@ impl Type { TypeKind::Enum(enum_) } - CXType_Record => { + clang::CXType_Record => { let complex = CompInfo::from_ty( potential_id, ty, @@ -1125,7 +1130,7 @@ impl Type { TypeKind::Comp(complex) } - CXType_Vector => { + clang::CXType_Vector => { let inner = Item::from_ty( ty.elem_type().as_ref().unwrap(), location, @@ -1135,7 +1140,7 @@ impl Type { .expect("Not able to resolve vector element?"); TypeKind::Vector(inner, ty.num_elements().unwrap()) } - CXType_ConstantArray => { + clang::CXType_ConstantArray => { let inner = Item::from_ty( ty.elem_type().as_ref().unwrap(), location, @@ -1145,7 +1150,7 @@ impl Type { .expect("Not able to resolve array element?"); TypeKind::Array(inner, ty.num_elements().unwrap()) } - CXType_Elaborated => { + clang::CXType_Elaborated => { return Self::from_clang_ty( potential_id, &ty.named(), @@ -1154,15 +1159,15 @@ impl Type { ctx, ); } - CXType_ObjCId => TypeKind::ObjCId, - CXType_ObjCSel => TypeKind::ObjCSel, - CXType_ObjCClass | CXType_ObjCInterface => { + clang::CXType_ObjCId => TypeKind::ObjCId, + clang::CXType_ObjCSel => TypeKind::ObjCSel, + clang::CXType_ObjCClass | clang::CXType_ObjCInterface => { let interface = ObjCInterface::from_ty(&location, ctx) .expect("Not a valid objc interface?"); name = interface.rust_name(); TypeKind::ObjCInterface(interface) } - CXType_Dependent => { + clang::CXType_Dependent => { return Err(ParseError::Continue); } _ => { @@ -1180,7 +1185,7 @@ impl Type { let name = if name.is_empty() { None } else { Some(name) }; let is_const = ty.is_const() || - (ty.kind() == CXType_ConstantArray && + (ty.kind() == clang::CXType_ConstantArray && ty.elem_type() .map_or(false, |element| element.is_const())); diff --git a/src/ir/var.rs b/src/ir/var.rs index e44d57afe4..bd2157a574 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -157,7 +157,7 @@ fn handle_function_macro( ) { let is_closing_paren = |t: &ClangToken| { // Test cheap token kind before comparing exact spellings. - t.kind == clang_sys::CXToken_Punctuation && t.spelling() == b")" + t.kind == clang::CXToken_Punctuation && t.spelling() == b")" }; let tokens: Vec<_> = cursor.tokens().iter().collect(); if let Some(boundary) = tokens.iter().position(is_closing_paren) { @@ -179,7 +179,7 @@ impl ClangSubItemParser for Var { ) -> Result, ParseError> { use cexpr::expr::EvalResult; use cexpr::literal::CChar; - use clang_sys::*; + use clang::*; match cursor.kind() { CXCursor_MacroDefinition => { if let Some(callbacks) = ctx.parse_callbacks() { @@ -395,7 +395,7 @@ fn get_integer_literal_from_cursor( cursor: &clang::Cursor, unit: &clang::TranslationUnit, ) -> Option { - use clang_sys::*; + use clang::*; let mut value = None; cursor.visit(|c| { match c.kind() { diff --git a/src/lib.rs b/src/lib.rs index 3d09ab71f1..35c666dff2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2157,32 +2157,6 @@ impl Default for BindgenOptions { } } -#[cfg(feature = "runtime")] -fn ensure_libclang_is_loaded() { - if clang_sys::is_loaded() { - return; - } - - // XXX (issue #350): Ensure that our dynamically loaded `libclang` - // doesn't get dropped prematurely, nor is loaded multiple times - // across different threads. - - lazy_static! { - static ref LIBCLANG: std::sync::Arc = { - clang_sys::load().expect("Unable to find libclang"); - clang_sys::get_library().expect( - "We just loaded libclang and it had better still be \ - here!", - ) - }; - } - - clang_sys::set_library(Some(LIBCLANG.clone())); -} - -#[cfg(not(feature = "runtime"))] -fn ensure_libclang_is_loaded() {} - /// Error type for rust-bindgen. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] @@ -2275,8 +2249,6 @@ impl Bindings { pub(crate) fn generate( mut options: BindgenOptions, ) -> Result { - ensure_libclang_is_loaded(); - #[cfg(feature = "runtime")] debug!( "Generating bindings, libclang at {}", @@ -2608,12 +2580,12 @@ fn parse_one( ctx: &mut BindgenContext, cursor: clang::Cursor, parent: Option, -) -> clang_sys::CXChildVisitResult { +) -> clang::CXChildVisitResult { if !filter_builtins(ctx, &cursor) { return CXChildVisit_Continue; } - use clang_sys::CXChildVisit_Continue; + use clang::CXChildVisit_Continue; match Item::parse(cursor, parent, ctx) { Ok(..) => {} Err(ParseError::Continue) => {} @@ -2626,7 +2598,7 @@ fn parse_one( /// Parse the Clang AST into our `Item` internal representation. fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> { - use clang_sys::*; + use clang::*; let mut error = None; for d in context.translation_unit().diags().iter() { @@ -2648,11 +2620,13 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> { let cursor = context.translation_unit().cursor(); if context.options().emit_ast { - fn dump_if_not_builtin(cur: &clang::Cursor) -> CXChildVisitResult { + fn dump_if_not_builtin( + cur: &clang::Cursor, + ) -> clang::CXChildVisitResult { if !cur.is_builtin() { clang::ast_dump(cur, 0) } else { - CXChildVisit_Continue + clang::CXChildVisit_Continue } } cursor.visit(|cur| dump_if_not_builtin(&cur)); @@ -2681,9 +2655,6 @@ pub struct ClangVersion { /// Get the major and the minor semver numbers of Clang's version pub fn clang_version() -> ClangVersion { - ensure_libclang_is_loaded(); - - //Debian clang version 11.0.1-2 let raw_v: String = clang::extract_clang_version(); let split_v: Option> = raw_v .split_whitespace() diff --git a/tests/expectations/tests/canonical-types.rs b/tests/expectations/tests/canonical-types.rs index a68e14244a..94630fdcb8 100644 --- a/tests/expectations/tests/canonical-types.rs +++ b/tests/expectations/tests/canonical-types.rs @@ -64,19 +64,10 @@ impl Default for ClassC_ClassCInnerA { } } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct ClassC_ClassCInnerCRTP { pub _address: u8, } -impl Default for ClassC_ClassCInnerCRTP { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ClassD { diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index 8542135b07..49dabd4a1e 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -212,6 +212,45 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).a as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).big_array + as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).incomplete_array + as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -240,6 +279,32 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).a as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())) + .incomplete_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -266,6 +331,66 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(C_with_zero_length_array_and_incomplete_array) ) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .a as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .big_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .zero_length_array as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .incomplete_array as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -303,6 +428,51 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(C_with_zero_length_array_and_incomplete_array_2) ) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array_2, + >())) + .a as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array_2, + >())) + .zero_length_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array_2, + >())) + .incomplete_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] #[derive(Debug, Default, Hash, PartialOrd, Ord, PartialEq, Eq)] @@ -352,6 +522,32 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).whatever + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())) + .incomplete_array as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { diff --git a/tests/expectations/tests/class_1_0.rs b/tests/expectations/tests/class_1_0.rs index f6c3021eb3..493393aedd 100644 --- a/tests/expectations/tests/class_1_0.rs +++ b/tests/expectations/tests/class_1_0.rs @@ -265,6 +265,45 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).a as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).big_array + as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).incomplete_array + as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -293,6 +332,32 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).a as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())) + .incomplete_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -319,6 +384,66 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(C_with_zero_length_array_and_incomplete_array) ) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .a as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .big_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .zero_length_array as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .incomplete_array as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -356,6 +481,51 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(C_with_zero_length_array_and_incomplete_array_2) ) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array_2, + >())) + .a as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array_2, + >())) + .zero_length_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array_2, + >())) + .incomplete_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] #[derive(Debug, Default, Hash, PartialEq, Eq)] @@ -405,6 +575,32 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).whatever + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())) + .incomplete_array as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { diff --git a/tests/expectations/tests/deleted-function.rs b/tests/expectations/tests/deleted-function.rs index 96967bb461..530422372f 100644 --- a/tests/expectations/tests/deleted-function.rs +++ b/tests/expectations/tests/deleted-function.rs @@ -31,6 +31,10 @@ extern "C" { #[link_name = "\u{1}_ZN1A22out_of_line_definitionEv"] pub fn A_out_of_line_definition(this: *mut A); } +extern "C" { + #[link_name = "\u{1}_ZN1A25inline_without_definitionEv"] + pub fn A_inline_without_definition(this: *mut A); +} impl A { #[inline] pub unsafe fn inline_definition(&mut self) { @@ -40,6 +44,10 @@ impl A { pub unsafe fn out_of_line_definition(&mut self) { A_out_of_line_definition(self) } + #[inline] + pub unsafe fn inline_without_definition(&mut self) { + A_inline_without_definition(self) + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 06c8da1bad..b132d9c3b0 100644 --- a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -93,6 +93,24 @@ fn bindgen_test_layout_test2() { 4usize, concat!("Alignment of ", stringify!(test2)) ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).incomplete_array as *const _ + as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] #[derive(Debug, Default)] @@ -113,4 +131,35 @@ fn bindgen_test_layout_test3() { 4usize, concat!("Alignment of ", stringify!(test3)) ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).zero_length_array as *const _ + as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).incomplete_array as *const _ + as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(incomplete_array) + ) + ); } diff --git a/tests/expectations/tests/incomplete-array-padding.rs b/tests/expectations/tests/incomplete-array-padding.rs index 18061ea12a..382195dbb9 100644 --- a/tests/expectations/tests/incomplete-array-padding.rs +++ b/tests/expectations/tests/incomplete-array-padding.rs @@ -140,6 +140,11 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs index b69aa16ef3..97f3d77f2b 100644 --- a/tests/expectations/tests/issue-643-inner-struct.rs +++ b/tests/expectations/tests/issue-643-inner-struct.rs @@ -121,6 +121,54 @@ fn bindgen_test_layout_rte_ring() { 8usize, concat!("Alignment of ", stringify!(rte_ring)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).memzone as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(memzone) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).prod as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(prod) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).cons as *const _ as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(cons) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).ring as *const _ as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(ring) + ) + ); } impl Default for rte_ring { fn default() -> Self { diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index 466e76862c..a3705446cb 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -147,6 +147,67 @@ fn bindgen_test_layout_rte_kni_fifo() { 8usize, concat!("Alignment of ", stringify!(rte_kni_fifo)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).write as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(write) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).read as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(read) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).len as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).elem_size as *const _ + as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(elem_size) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).buffer as *const _ as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(buffer) + ) + ); } impl Default for rte_kni_fifo { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-9/template-fun-ty.rs b/tests/expectations/tests/libclang-9/template-fun-ty.rs new file mode 100644 index 0000000000..a7132cf04c --- /dev/null +++ b/tests/expectations/tests/libclang-9/template-fun-ty.rs @@ -0,0 +1,27 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +pub struct Foo { + pub _address: u8, +} +pub type Foo_FunctionPtr = + ::std::option::Option T>; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +pub struct RefPtr { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +pub struct RefPtr_Proxy { + pub _address: u8, +} +pub type RefPtr_Proxy_member_function = + ::std::option::Option R>; +pub type Returner = ::std::option::Option T>; diff --git a/tests/expectations/tests/template-fun-ty.rs b/tests/expectations/tests/template-fun-ty.rs index a7132cf04c..4a9bc9459c 100644 --- a/tests/expectations/tests/template-fun-ty.rs +++ b/tests/expectations/tests/template-fun-ty.rs @@ -22,6 +22,6 @@ pub struct RefPtr { pub struct RefPtr_Proxy { pub _address: u8, } -pub type RefPtr_Proxy_member_function = - ::std::option::Option R>; +pub type RefPtr_Proxy_member_function = + ::std::option::Option T>; pub type Returner = ::std::option::Option T>; diff --git a/tests/expectations/tests/template_instantiation_with_fn_local_type.rs b/tests/expectations/tests/template_instantiation_with_fn_local_type.rs index d968e71bae..5bb385e654 100644 --- a/tests/expectations/tests/template_instantiation_with_fn_local_type.rs +++ b/tests/expectations/tests/template_instantiation_with_fn_local_type.rs @@ -10,6 +10,9 @@ pub struct Foo { pub _address: u8, } +extern "C" { + pub static mut foo: Foo; +} extern "C" { #[link_name = "\u{1}_Z1fv"] pub fn f(); diff --git a/tests/expectations/tests/zero-sized-array.rs b/tests/expectations/tests/zero-sized-array.rs index 4ba52498c4..578fc4fbe7 100644 --- a/tests/expectations/tests/zero-sized-array.rs +++ b/tests/expectations/tests/zero-sized-array.rs @@ -137,6 +137,19 @@ fn bindgen_test_layout_DynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(DynamicallySizedArray)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).arr as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(DynamicallySizedArray), + "::", + stringify!(arr) + ) + ); } /// No `_address` field here either. #[repr(C)] @@ -156,4 +169,17 @@ fn bindgen_test_layout_ContainsDynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).dsa + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsDynamicallySizedArray), + "::", + stringify!(dsa) + ) + ); }