Skip to content

Commit c18e9ee

Browse files
authored
Merge pull request #127 from immunant/feature/nightly-2019-06-20
Roll nightly version to 2019-06-22 to support va_copy
2 parents 0899913 + d27ee65 commit c18e9ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+944
-873
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[azure]: https://dev.azure.com/immunant/c2rust/_build/latest?definitionId=1&branchName=master
77
[Latest Version]: https://img.shields.io/crates/v/c2rust.svg
88
[crates.io]: https://crates.io/crates/c2rust
9-
[Rustc Version]: https://img.shields.io/badge/rustc-nightly--2019--04--12-lightgrey.svg "Rustc nightly-2019-04-12"
9+
[Rustc Version]: https://img.shields.io/badge/rustc-nightly--2019--04--12-lightgrey.svg "Rustc nightly-2019-06-20"
1010

1111
C2Rust helps you migrate C99-compliant code to Rust. The [translator](c2rust-transpile) (or transpiler) produces unsafe code Rust code that closely mirrors the input C code. The primary goal of the translator is to preserve functionality; test suites should continue to pass after translation. Generating safe and idiomatic Rust code from C ultimately requires manual effort. However, we are building a scriptable [refactoring tool](c2rust-refactor) that reduces the tedium of doing so. You can also [cross-check](cross-checks) the translated code against the original ([tutorial](docs/cross-check-tutorial.md)).
1212

@@ -51,22 +51,22 @@ Finally, a rust installation with [Rustup](https://rustup.rs/) is required on al
5151

5252
### Installing from crates.io
5353

54-
cargo +nightly-2019-04-12 install c2rust
54+
cargo +nightly-2019-06-20 install c2rust
5555

5656
On OS X with Homebrew LLVM, you need to point the build system at the LLVM installation as follows:
5757

58-
LLVM_CONFIG_PATH=/usr/local/opt/llvm/bin/llvm-config cargo +nightly-2019-04-12 install c2rust
58+
LLVM_CONFIG_PATH=/usr/local/opt/llvm/bin/llvm-config cargo +nightly-2019-06-20 install c2rust
5959

6060
On Linux with Linuxbrew LLVM, you need to point the build system at the LLVM installation as follows:
6161

62-
LLVM_CONFIG_PATH=/home/linuxbrew/.linuxbrew/opt/llvm/bin/llvm-config cargo +nightly-2019-04-12 install c2rust
62+
LLVM_CONFIG_PATH=/home/linuxbrew/.linuxbrew/opt/llvm/bin/llvm-config cargo +nightly-2019-06-20 install c2rust
6363

6464
Note: adjust `LLVM_CONFIG_PATH` accordingly if Linuxbrew was installed to your home directory.
6565

6666
On Gentoo, you need to point the build system to the location of `libclang.so`
6767
and `llvm-config` as follows:
6868

69-
LLVM_CONFIG_PATH=/path/to/llvm-config LIBCLANG_PATH=/path/to/libclang.so cargo +nightly-2019-04-12 install c2rust
69+
LLVM_CONFIG_PATH=/path/to/llvm-config LIBCLANG_PATH=/path/to/libclang.so cargo +nightly-2019-06-20 install c2rust
7070

7171

7272
If you have trouble with building and installing, or want to build from the latest master, the [developer docs](docs/README-developers.md#building-with-system-llvm-libraries) provide more details on the build system.

c2rust-ast-builder/src/builder.rs

+84-68
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
use rustc::hir;
33
use rustc_target::spec::abi::{self, Abi};
44
use std::rc::Rc;
5+
use std::str;
56
use syntax::ast::*;
67
use syntax::attr::mk_attr_inner;
7-
use syntax::parse::token::{self, DelimToken, Token};
8+
use syntax::parse::token::{self, DelimToken, TokenKind, Token};
89
use syntax::ptr::P;
910
use syntax::source_map::{dummy_spanned, Span, Spanned, DUMMY_SP};
10-
use syntax::symbol::keywords;
1111
use syntax::tokenstream::{TokenStream, TokenStreamBuilder, TokenTree};
1212
use syntax::ThinVec;
1313

@@ -167,6 +167,16 @@ impl<'a> Make<LitIntType> for UintTy {
167167
}
168168
}
169169

170+
impl Make<Lit> for hir::Lit {
171+
fn make(self, _mk: &Builder) -> Lit {
172+
Lit {
173+
token: self.node.to_lit_token(),
174+
node: self.node,
175+
span: self.span,
176+
}
177+
}
178+
}
179+
170180
impl<I: Make<Ident>> Make<PathSegment> for I {
171181
fn make(self, mk: &Builder) -> PathSegment {
172182
PathSegment {
@@ -200,7 +210,7 @@ impl Make<TokenStream> for Vec<TokenTree> {
200210

201211
impl Make<TokenTree> for Token {
202212
fn make(self, _mk: &Builder) -> TokenTree {
203-
TokenTree::Token(DUMMY_SP, self)
213+
TokenTree::Token(self)
204214
}
205215
}
206216

@@ -357,8 +367,11 @@ impl Builder {
357367
style: AttrStyle::Outer,
358368
path: key,
359369
tokens: vec![
360-
Token::Eq,
361-
Token::Literal(token::Lit::Str_(value.into_symbol()), None),
370+
TokenTree::token(token::Eq, DUMMY_SP),
371+
TokenTree::token(
372+
TokenKind::Literal(token::Lit::new(token::LitKind::Str, value.into_symbol(), None)),
373+
DUMMY_SP
374+
)
362375
]
363376
.into_iter()
364377
.collect(),
@@ -401,21 +414,22 @@ impl Builder {
401414

402415
let tokens: TokenStream = {
403416
let mut builder = TokenStreamBuilder::new();
404-
builder.push(Token::OpenDelim(DelimToken::Paren));
417+
builder.push(TokenTree::token(TokenKind::OpenDelim(DelimToken::Paren), DUMMY_SP));
405418

406419
let mut is_first = true;
407420
for argument in arguments {
408421
if is_first {
409422
is_first = false;
410423
} else {
411-
builder.push(Token::Comma);
424+
builder.push(TokenTree::token(TokenKind::Comma, DUMMY_SP));
412425
}
413426

414427
let argument: Ident = argument.make(&self);
415-
builder.push(Token::from_ast_ident(argument));
428+
let token_kind = TokenKind::Ident(argument.name, argument.is_raw_guess());
429+
builder.push(TokenTree::token(token_kind, DUMMY_SP));
416430
}
417431

418-
builder.push(Token::CloseDelim(DelimToken::Paren));
432+
builder.push(TokenTree::token(TokenKind::CloseDelim(DelimToken::Paren), DUMMY_SP));
419433
builder.build()
420434
};
421435

@@ -470,7 +484,7 @@ impl Builder {
470484
AngleBracketedArgs {
471485
span: self.span,
472486
args: args,
473-
bindings: vec![],
487+
constraints: vec![],
474488
}
475489
}
476490

@@ -504,20 +518,20 @@ impl Builder {
504518
path.make(&self)
505519
}
506520

507-
pub fn abs_path<Pa>(self, path: Pa) -> Path
508-
where
509-
Pa: Make<Path>,
510-
{
511-
let mut p = path.make(&self);
512-
if !p
513-
.segments
514-
.get(0)
515-
.map_or(false, |s| s.ident.name == keywords::Crate.name())
516-
{
517-
p.segments.insert(0, keywords::Crate.ident().make(&self));
518-
}
519-
p
520-
}
521+
// pub fn abs_path<Pa>(self, path: Pa) -> Path
522+
// where
523+
// Pa: Make<Path>,
524+
// {
525+
// let mut p = path.make(&self);
526+
// if !p
527+
// .segments
528+
// .get(0)
529+
// .map_or(false, |s| s.ident.name == kw::Crate)
530+
// {
531+
// p.segments.insert(0, kw::Crate.ident().make(&self));
532+
// }
533+
// p
534+
// }
521535

522536
pub fn anon_const<E>(self, expr: E) -> AnonConst
523537
where
@@ -941,55 +955,56 @@ impl Builder {
941955
let body = body.make(&self);
942956
Arm {
943957
attrs: self.attrs,
944-
pats: pats,
958+
pats,
945959
guard,
946960
body,
961+
span: DUMMY_SP,
947962
}
948963
}
949964

950965
// Literals
951966

952967
pub fn bytestr_lit(self, s: Vec<u8>) -> Lit {
953-
Lit {
954-
node: LitKind::ByteStr(Rc::new(s)),
955-
span: self.span,
956-
}
968+
Lit::from_lit_kind(
969+
LitKind::ByteStr(Rc::new(s)),
970+
self.span
971+
)
957972
}
958973

959974
pub fn str_lit<S>(self, s: S) -> Lit
960975
where
961976
S: IntoSymbol,
962977
{
963978
let s = s.into_symbol();
964-
Lit {
965-
node: LitKind::Str(s, StrStyle::Cooked),
966-
span: self.span,
967-
}
979+
Lit::from_lit_kind(
980+
LitKind::Str(s, StrStyle::Cooked),
981+
self.span
982+
)
968983
}
969984

970985
pub fn byte_lit(self, b: u8) -> Lit {
971-
Lit {
972-
node: LitKind::Byte(b),
973-
span: self.span,
974-
}
986+
Lit::from_lit_kind(
987+
LitKind::Byte(b),
988+
self.span
989+
)
975990
}
976991

977992
pub fn char_lit(self, c: char) -> Lit {
978-
Lit {
979-
node: LitKind::Char(c),
980-
span: self.span,
981-
}
993+
Lit::from_lit_kind(
994+
LitKind::Char(c),
995+
self.span
996+
)
982997
}
983998

984999
pub fn int_lit<T>(self, i: u128, ty: T) -> Lit
9851000
where
9861001
T: Make<LitIntType>,
9871002
{
9881003
let ty = ty.make(&self);
989-
Lit {
990-
node: LitKind::Int(i, ty),
991-
span: self.span,
992-
}
1004+
Lit::from_lit_kind(
1005+
LitKind::Int(i, ty),
1006+
self.span
1007+
)
9931008
}
9941009

9951010
pub fn float_lit<S, T>(self, s: S, ty: T) -> Lit
@@ -999,28 +1014,28 @@ impl Builder {
9991014
{
10001015
let s = s.into_symbol();
10011016
let ty = ty.make(&self);
1002-
Lit {
1003-
node: LitKind::Float(s, ty),
1004-
span: self.span,
1005-
}
1017+
Lit::from_lit_kind(
1018+
LitKind::Float(s, ty),
1019+
self.span
1020+
)
10061021
}
10071022

10081023
pub fn float_unsuffixed_lit<S>(self, s: S) -> Lit
10091024
where
10101025
S: IntoSymbol,
10111026
{
10121027
let s = s.into_symbol();
1013-
Lit {
1014-
node: LitKind::FloatUnsuffixed(s),
1015-
span: self.span,
1016-
}
1028+
Lit::from_lit_kind(
1029+
LitKind::FloatUnsuffixed(s),
1030+
self.span
1031+
)
10171032
}
10181033

10191034
pub fn bool_lit(self, b: bool) -> Lit {
1020-
Lit {
1021-
node: LitKind::Bool(b),
1022-
span: self.span,
1023-
}
1035+
Lit::from_lit_kind(
1036+
LitKind::Bool(b),
1037+
self.span
1038+
)
10241039
}
10251040

10261041
pub fn ifte_expr<C, T, E>(self, cond: C, then_case: T, else_case: Option<E>) -> P<Expr>
@@ -1605,7 +1620,7 @@ impl Builder {
16051620
let mac = mac.make(&self);
16061621
let kind = ItemKind::Mac(mac);
16071622
Self::item(
1608-
keywords::Invalid.ident(),
1623+
Ident::invalid(),
16091624
self.attrs,
16101625
self.vis,
16111626
self.span,
@@ -1659,7 +1674,7 @@ impl Builder {
16591674
{
16601675
let ty = ty.make(&self);
16611676
Self::item(
1662-
keywords::Invalid.ident(),
1677+
Ident::invalid(),
16631678
self.attrs,
16641679
self.vis,
16651680
self.span,
@@ -1709,7 +1724,7 @@ impl Builder {
17091724
kind: UseTreeKind::Simple(rename, DUMMY_NODE_ID, DUMMY_NODE_ID),
17101725
};
17111726
Self::item(
1712-
keywords::Invalid.ident(),
1727+
Ident::invalid(),
17131728
self.attrs,
17141729
self.vis,
17151730
self.span,
@@ -1743,7 +1758,7 @@ impl Builder {
17431758
kind: UseTreeKind::Nested(inner_trees),
17441759
};
17451760
Self::item(
1746-
keywords::Invalid.ident(),
1761+
Ident::invalid(),
17471762
self.attrs,
17481763
self.vis,
17491764
self.span,
@@ -1758,7 +1773,7 @@ impl Builder {
17581773
items,
17591774
};
17601775
Self::item(
1761-
keywords::Invalid.ident(),
1776+
Ident::invalid(),
17621777
self.attrs,
17631778
self.vis,
17641779
self.span,
@@ -1800,7 +1815,7 @@ impl Builder {
18001815
let mac = mac.make(&self);
18011816
let kind = ImplItemKind::Macro(mac);
18021817
Self::impl_item_(
1803-
keywords::Invalid.ident(),
1818+
Ident::invalid(),
18041819
self.attrs,
18051820
self.vis,
18061821
Defaultness::Final,
@@ -1840,7 +1855,7 @@ impl Builder {
18401855
let mac = mac.make(&self);
18411856
let kind = TraitItemKind::Macro(mac);
18421857
Self::trait_item_(
1843-
keywords::Invalid.ident(),
1858+
Ident::invalid(),
18441859
self.attrs,
18451860
self.generics,
18461861
self.span,
@@ -1893,14 +1908,13 @@ impl Builder {
18931908
{
18941909
let name = name.make(&self);
18951910
let ty = ty.make(&self);
1896-
let is_mut = self.mutbl == Mutability::Mutable;
18971911
Self::foreign_item(
18981912
name,
18991913
self.attrs,
19001914
self.vis,
19011915
self.span,
19021916
self.id,
1903-
ForeignItemKind::Static(ty, is_mut),
1917+
ForeignItemKind::Static(ty, self.mutbl),
19041918
)
19051919
}
19061920

@@ -1926,7 +1940,7 @@ impl Builder {
19261940
let mac = mac.make(&self);
19271941
let kind = ForeignItemKind::Macro(mac);
19281942
Self::foreign_item(
1929-
keywords::Invalid.ident(),
1943+
Ident::invalid(),
19301944
self.attrs,
19311945
self.vis,
19321946
self.span,
@@ -2017,6 +2031,7 @@ impl Builder {
20172031
let ty = ty.make(&self);
20182032
let pat = pat.make(&self);
20192033
Arg {
2034+
attrs: ThinVec::new(),
20202035
ty: ty,
20212036
pat: pat,
20222037
id: self.id,
@@ -2029,7 +2044,8 @@ impl Builder {
20292044
{
20302045
let eself = dummy_spanned(kind.make(&self));
20312046
let ident = "self".make(&self);
2032-
Arg::from_self(eself, ident)
2047+
let attrs = ThinVec::new();
2048+
Arg::from_self(attrs, eself, ident)
20332049
}
20342050

20352051
pub fn ty_param<I>(self, ident: I) -> GenericParam

0 commit comments

Comments
 (0)