Skip to content

Commit 2fb013d

Browse files
committed
create synthetic AST nodes to enable looking up Rust fixed-size types
1 parent 588740f commit 2fb013d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

c2rust-transpile/src/c_ast/conversion.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,14 @@ impl ConversionContext {
437437
self.typed_context.comments.push(comment);
438438
}
439439

440+
// Add Rust fixed-size types.
441+
for rust_type_kind in CTypeKind::PULLBACK_KINDS {
442+
let new_id = self.id_mapper.fresh_id();
443+
self.add_type(new_id, not_located(rust_type_kind));
444+
self.processed_nodes
445+
.insert(new_id, self::node_types::OTHER_TYPE);
446+
}
447+
440448
// Continue popping Clang nodes off of the stack of nodes we have promised to visit
441449
while let Some((node_id, expected_ty)) = self.visit_as.pop() {
442450
// Check if we've already processed this node. If so, ascertain that it has the right

c2rust-transpile/src/c_ast/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,12 @@ impl TypedAstContext {
464464
ty.map(|ty| (expr_id, ty))
465465
}
466466

467+
pub fn type_for_kind(&self, kind: CTypeKind) -> Option<CTypeId> {
468+
self.c_types
469+
.iter()
470+
.find_map(|(id, k)| if kind == k.kind { Some(*id) } else { None })
471+
}
472+
467473
pub fn resolve_type_id(&self, typ: CTypeId) -> CTypeId {
468474
use CTypeKind::*;
469475
let ty = match self.index(typ).kind {

0 commit comments

Comments
 (0)