summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-09-22 05:40:45 -0500
committerGitHub <noreply@github.com>2016-09-22 05:40:45 -0500
commit33debb35bfcd568a570e7d3c702d8643eff1a7a4 (patch)
tree152a7e645972110900ea5c270f8f92a30018c40e /src/codegen/mod.rs
parentf318b638a81cf0602ece84fc412f87c7ab3a0b4e (diff)
parentcc8ed879bc99449146539ed41042b5c8f07545f6 (diff)
Auto merge of #58 - emilio:funcs, r=nox
Some function pointers, typedefs, and OSX's stdlib. r? @nox The change from indexing cursors to index USRs was because in the `inner_template_self` test, the `next` pointer pointed to a clang-generated class declaration that caused us to not catch the type as already resolved. Also, that's the recommended way to check against same symbols from different translation units, though now we don't use it yet.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r--src/codegen/mod.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 62cebf46..36f20689 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -311,6 +311,7 @@ impl CodeGenerator for Type {
TypeKind::Float(..) |
TypeKind::Array(..) |
TypeKind::Pointer(..) |
+ TypeKind::BlockPointer |
TypeKind::Reference(..) |
TypeKind::TemplateRef(..) |
TypeKind::Function(..) |
@@ -1306,6 +1307,11 @@ impl ToRustTy for Type {
IntKind::ULongLong => raw!(c_ulonglong),
IntKind::U16 => aster::ty::TyBuilder::new().u16(),
IntKind::U32 => aster::ty::TyBuilder::new().u32(),
+ // FIXME: This doesn't generate the proper alignment, but we
+ // can't do better right now. We should be able to use
+ // i128/u128 when they're available.
+ IntKind::U128 |
+ IntKind::I128 => ArrayTyBuilder::new().with_len(2).build(aster::ty::TyBuilder::new().u64()),
}
}
TypeKind::Float(fk) => {
@@ -1377,10 +1383,23 @@ impl ToRustTy for Type {
utils::build_templated_path(item, ctx, false)
}
+ TypeKind::BlockPointer => {
+ let void = raw!(c_void);
+ void.to_ptr(/* is_const = */ false, ctx.span())
+ }
TypeKind::Pointer(inner) |
TypeKind::Reference(inner) => {
let inner = ctx.resolve_item(inner);
- inner.to_rust_ty(ctx).to_ptr(inner.expect_type().is_const(), ctx.span())
+ let inner_ty = inner.expect_type();
+ let ty = inner.to_rust_ty(ctx);
+
+ // Avoid the first function pointer level, since it's already
+ // represented in Rust.
+ if inner_ty.canonical_type(ctx).is_function() {
+ ty
+ } else {
+ ty.to_ptr(inner.expect_type().is_const(), ctx.span())
+ }
}
TypeKind::Named(..) => {
let name = item.canonical_name(ctx);