Skip to content

Commit

Permalink
rewrite lifetime parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
aneksteind committed May 9, 2023
1 parent b980b0a commit 8d61604
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 66 deletions.
5 changes: 2 additions & 3 deletions c2rust-analyze/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::context::{
};
use crate::dataflow::DataflowConstraints;
use crate::equiv::{GlobalEquivSet, LocalEquivSet};
use crate::labeled_ty::LabeledTyCtxt;
use crate::log::init_logger;
use crate::util::Callee;
use context::AdtMetadataTable;
Expand All @@ -32,10 +33,8 @@ use rustc_middle::mir::{
AggregateKind, BindingForm, Body, Constant, LocalDecl, LocalInfo, LocalKind, Location, Operand,
Rvalue, StatementKind,
};
use rustc_middle::ty::tls;
use rustc_middle::ty::{GenericArgKind, Ty, TyCtxt, TyKind, WithOptConstParam};
use rustc_middle::ty::{Ty, TyCtxt, TyKind, WithOptConstParam};
use rustc_span::Span;
use rustc_type_ir::RegionKind::{ReEarlyBound, ReStatic};
use std::collections::{HashMap, HashSet};
use std::env;
use std::fmt::{Debug, Display};
Expand Down
15 changes: 14 additions & 1 deletion c2rust-analyze/src/rewrite/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ impl<'a, F: FnMut(&str)> Emitter<'a, F> {
Rewrite::PrintTy(ref s) => {
self.emit_str(s);
}
Rewrite::TyGenericParams(ref rws) => {
self.emit_str("<");
for (index, rw) in rws.iter().enumerate() {
self.emit_rewrite(rw, 0, emit_expr, emit_subexpr);
if index < rws.len() - 1 {
self.emit_str(",");
}
}
self.emit_str(">");
}
Rewrite::Call(ref func, ref arg_rws) => {
self.emit_str(func);
self.emit_parenthesized(true, |slf| {
Expand Down Expand Up @@ -342,8 +352,11 @@ impl<'a, F: FnMut(&str)> Emitter<'a, F> {
Rewrite::TyCtor(ref name, ref rws) => {
self.emit_str(name);
self.emit_str("<");
for rw in rws {
for (index, rw) in rws.iter().enumerate() {
self.emit_rewrite(rw, 0, emit_expr, emit_subexpr);
if index < rws.len() - 1 {
self.emit_str(",");
}
}
self.emit_str(">");
}
Expand Down
19 changes: 18 additions & 1 deletion c2rust-analyze/src/rewrite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ pub enum Rewrite<S = Span> {
TySlice(Box<Rewrite>),
/// `Foo<T1, T2>`
TyCtor(String, Vec<Rewrite>),
/// `<'a, 'b, ...>`
/// needed for cases when the span of the ADT name
/// is different from ADT generic params
TyGenericParams(Vec<Rewrite>),

// `static` builders
/// `static` mutability (`static` <-> `static mut`)
Expand Down Expand Up @@ -181,6 +185,16 @@ impl Rewrite {
Rewrite::PrintTy(ref s) => {
write!(f, "{}", s)
}
Rewrite::TyGenericParams(ref rws) => {
f.write_str("<")?;
for (index, rw) in rws.iter().enumerate() {
rw.pretty(f, 0)?;
if index < rws.len() - 1 {
f.write_str(",")?;
}
}
f.write_str(">")
}
Rewrite::Call(ref func, ref arg_rws) => {
f.write_str(func)?;
f.write_str("(")?;
Expand Down Expand Up @@ -230,8 +244,11 @@ impl Rewrite {
}
Rewrite::TyCtor(ref name, ref rws) => {
write!(f, "{}<", name)?;
for rw in rws {
for (idx, rw) in rws.iter().enumerate() {
rw.pretty(f, 0)?;
if idx < rws.len() - 1 {
write!(f, ",")?;
}
}
write!(f, ">")
}
Expand Down
Loading

0 comments on commit 8d61604

Please sign in to comment.