Skip to content

Commit 65d1aba

Browse files
authored
Bump rustc to nightly 2019-04-08 (#49)
Major updates to translator: - Remove ThinTokenStream - Update AST - Use libc crate instead of rustc internal version - Add support for varargs Major updates to the refactoring tool: - Remove ThinTokenStream - Update AST - Replace Folder with in-place mutable Visitor - Use new rustc driver interface Note: We need rust-lang/rust#59173 to be in our nightly for LLVM 8 builds against system libLLVM-8.so on linux.
1 parent 75746ee commit 65d1aba

File tree

128 files changed

+4251
-3784
lines changed

Some content is hidden

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

128 files changed

+4251
-3784
lines changed

Cargo.lock

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"c2rust-ast-exporter",
88
"manual/preprocessors",
99
"c2rust-bitfields",
10+
"c2rust-macros",
1011
]
1112
exclude = [
1213
"cross-checks/pointer-tracer",

c2rust-ast-builder/src/builder.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use syntax::source_map::{DUMMY_SP, Spanned, Span, dummy_spanned};
55
use syntax::parse::token::{self, Token, DelimToken};
66
use syntax::attr::{mk_attr_inner};
77
use syntax::ptr::P;
8-
use syntax::tokenstream::{TokenTree, TokenStream, TokenStreamBuilder, ThinTokenStream};
8+
use syntax::tokenstream::{TokenTree, TokenStream, TokenStreamBuilder};
99
use syntax::symbol::keywords;
1010
use std::rc::Rc;
1111
use rustc_target::spec::abi::{self, Abi};
@@ -183,14 +183,14 @@ impl<S: Make<PathSegment>> Make<Path> for Vec<S> {
183183
}
184184

185185

186-
impl Make<ThinTokenStream> for TokenStream {
187-
fn make(self, _mk: &Builder) -> ThinTokenStream {
188-
self.into()
189-
}
190-
}
186+
//impl Make<TokenStream> for TokenStream {
187+
// fn make(self, _mk: &Builder) -> TokenStream {
188+
// self.into()
189+
// }
190+
//}
191191

192-
impl Make<ThinTokenStream> for Vec<TokenTree> {
193-
fn make(self, _mk: &Builder) -> ThinTokenStream {
192+
impl Make<TokenStream> for Vec<TokenTree> {
193+
fn make(self, _mk: &Builder) -> TokenStream {
194194
self.into_iter().collect::<TokenStream>().into()
195195
}
196196
}
@@ -207,7 +207,7 @@ impl Make<GenericArgs> for AngleBracketedArgs {
207207
}
208208
}
209209

210-
impl Make<GenericArgs> for ParenthesisedArgs {
210+
impl Make<GenericArgs> for ParenthesizedArgs {
211211
fn make(self, _mk: &Builder) -> GenericArgs {
212212
Parenthesized(self)
213213
}
@@ -225,15 +225,15 @@ impl Make<GenericArg> for Lifetime {
225225
}
226226
}
227227

228-
impl Make<NestedMetaItemKind> for MetaItem {
229-
fn make(self, _mk: &Builder) -> NestedMetaItemKind {
230-
NestedMetaItemKind::MetaItem(self)
228+
impl Make<NestedMetaItem> for MetaItem {
229+
fn make(self, _mk: &Builder) -> NestedMetaItem {
230+
NestedMetaItem::MetaItem(self)
231231
}
232232
}
233233

234-
impl Make<NestedMetaItemKind> for Lit {
235-
fn make(self, _mk: &Builder) -> NestedMetaItemKind {
236-
NestedMetaItemKind::Literal(self)
234+
impl Make<NestedMetaItem> for Lit {
235+
fn make(self, _mk: &Builder) -> NestedMetaItem {
236+
NestedMetaItem::Literal(self)
237237
}
238238
}
239239

@@ -448,11 +448,11 @@ impl Builder {
448448
}
449449
}
450450

451-
pub fn parenthesized_args<Ts>(self, tys: Ts) -> ParenthesisedArgs
451+
pub fn parenthesized_args<Ts>(self, tys: Ts) -> ParenthesizedArgs
452452
where Ts: Make<Vec<P<Ty>>> {
453453

454454
let tys = tys.make(&self);
455-
ParenthesisedArgs {
455+
ParenthesizedArgs {
456456
span: self.span,
457457
inputs: tys,
458458
output: None,
@@ -495,8 +495,8 @@ impl Builder {
495495
pub fn abs_path<Pa>(self, path: Pa) -> Path
496496
where Pa: Make<Path> {
497497
let mut p = path.make(&self);
498-
if !p.segments.get(0).map_or(false, |s| s.ident.name == keywords::CrateRoot.name()) {
499-
p.segments.insert(0, keywords::CrateRoot.ident().make(&self));
498+
if !p.segments.get(0).map_or(false, |s| s.ident.name == keywords::PathRoot.name()) {
499+
p.segments.insert(0, keywords::PathRoot.ident().make(&self));
500500
}
501501
p
502502
}
@@ -1284,7 +1284,7 @@ impl Builder {
12841284
let block = block.make(&self);
12851285
let header = FnHeader {
12861286
unsafety: self.unsafety,
1287-
asyncness: IsAsync::NotAsync,
1287+
asyncness: dummy_spanned(IsAsync::NotAsync),
12881288
constness: dummy_spanned(self.constness),
12891289
abi: self.abi,
12901290
};
@@ -1295,28 +1295,28 @@ impl Builder {
12951295
block))
12961296
}
12971297

1298-
pub fn fn_decl(self, inputs: Vec<Arg>, output: FunctionRetTy, variadic: bool) -> P<FnDecl>
1298+
pub fn fn_decl(self, inputs: Vec<Arg>, output: FunctionRetTy, c_variadic: bool) -> P<FnDecl>
12991299
{
13001300
P(FnDecl {
13011301
inputs,
13021302
output,
1303-
variadic,
1303+
c_variadic,
13041304
})
13051305
}
13061306

13071307
pub fn struct_item<I>(self, name: I, fields: Vec<StructField>) -> P<Item>
13081308
where I: Make<Ident> {
13091309
let name = name.make(&self);
13101310
Self::item(name, self.attrs, self.vis, self.span, self.id,
1311-
ItemKind::Struct(VariantData::Struct(fields, DUMMY_NODE_ID),
1311+
ItemKind::Struct(VariantData::Struct(fields, false),
13121312
self.generics))
13131313
}
13141314

13151315
pub fn union_item<I>(self, name: I, fields: Vec<StructField>) -> P<Item>
13161316
where I: Make<Ident> {
13171317
let name = name.make(&self);
13181318
Self::item(name, self.attrs, self.vis, self.span, self.id,
1319-
ItemKind::Union(VariantData::Struct(fields, DUMMY_NODE_ID),
1319+
ItemKind::Union(VariantData::Struct(fields, false),
13201320
self.generics))
13211321
}
13221322

@@ -1367,6 +1367,7 @@ impl Builder {
13671367
node: Variant_ {
13681368
ident: name,
13691369
attrs: self.attrs,
1370+
id: DUMMY_NODE_ID,
13701371
data: dat,
13711372
disr_expr: None,
13721373
},
@@ -1382,6 +1383,7 @@ impl Builder {
13821383
node: Variant_ {
13831384
ident: name,
13841385
attrs: self.attrs,
1386+
id: DUMMY_NODE_ID,
13851387
data: VariantData::Unit(self.id),
13861388
disr_expr: disc,
13871389
},
@@ -1577,7 +1579,6 @@ impl Builder {
15771579
Unsafety::Normal => BlockCheckMode::Default,
15781580
},
15791581
span: self.span,
1580-
recovered: false,
15811582
})
15821583
}
15831584

@@ -1637,7 +1638,7 @@ impl Builder {
16371638
}
16381639

16391640
pub fn attribute<Pa, Ts>(self, style: AttrStyle, path: Pa, tokens: Ts) -> Attribute
1640-
where Pa: Make<Path>, Ts: Make<ThinTokenStream>
1641+
where Pa: Make<Path>, Ts: Make<TokenStream>
16411642
{
16421643
let path = path.make(&self);
16431644
let tokens = tokens.make(&self).into();
@@ -1665,17 +1666,16 @@ impl Builder {
16651666
let path = path.make(&self);
16661667
let kind = kind.make(&self);
16671668
MetaItem {
1668-
ident: path,
1669+
path: path,
16691670
node: kind,
16701671
span: DUMMY_SP,
16711672
}
16721673
}
16731674

16741675
pub fn nested_meta_item<K>(self, kind: K) -> NestedMetaItem
1675-
where K: Make<NestedMetaItemKind>
1676-
{
1677-
let kind = kind.make(&self);
1678-
dummy_spanned(kind)
1676+
where K: Make<NestedMetaItem>
1677+
{
1678+
kind.make(&self)
16791679
}
16801680

16811681
// Convert the current internal list of outer attributes
@@ -1691,7 +1691,7 @@ impl Builder {
16911691
}
16921692

16931693
pub fn mac<Pa, Ts>(self, path: Pa, tts: Ts, delim: MacDelimiter) -> Mac
1694-
where Pa: Make<Path>, Ts: Make<ThinTokenStream> {
1694+
where Pa: Make<Path>, Ts: Make<TokenStream> {
16951695
let path = path.make(&self);
16961696
let tts = tts.make(&self);
16971697
Spanned {

c2rust-ast-exporter/build.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ variable or make sure `llvm-config` is on $PATH then re-build. For example:
290290
.or(invoke_command(llvm_config.as_ref(), &["--system-libs", "--link-static"]))
291291
.unwrap_or(String::new())
292292
.split_whitespace()
293-
.map(|lib| String::from(lib.trim_left_matches("-l")))
293+
.map(|lib| String::from(lib.trim_start_matches("-l")))
294294
.collect();
295295

296296
let llvm_dylib = invoke_command(llvm_config.as_ref(), &["--libs", "--link-shared"]);
@@ -314,7 +314,7 @@ variable or make sure `llvm-config` is on $PATH then re-build. For example:
314314
} // Windows is not supported
315315
};
316316
let mut dylib_file = String::from("lib");
317-
dylib_file.push_str(llvm_dylib.trim_left_matches("-l"));
317+
dylib_file.push_str(llvm_dylib.trim_start_matches("-l"));
318318
dylib_file.push_str(dylib_suffix);
319319
let sysroot = invoke_command(
320320
env::var("RUSTC").ok().as_ref(),
@@ -353,7 +353,7 @@ variable or make sure `llvm-config` is on $PATH then re-build. For example:
353353
])
354354
.unwrap_or(String::new())
355355
.split_whitespace()
356-
.map(|lib| String::from(lib.trim_left_matches("-l")))
356+
.map(|lib| String::from(lib.trim_start_matches("-l")))
357357
.collect();
358358

359359
Self {

c2rust-ast-exporter/src/AstExporter.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,13 @@ class TranslateASTVisitor final
635635
return true;
636636
}
637637

638+
bool VisitIndirectGotoStmt(IndirectGotoStmt *IGS) {
639+
std:: string msg = "the GNU C labels-as-values extension is not supported. Aborting.";
640+
641+
printError(msg, IGS);
642+
abort();
643+
}
644+
638645
bool VisitLabelStmt(LabelStmt *LS) {
639646

640647
std::vector<void*> childIds = { LS->getSubStmt() };
@@ -645,7 +652,6 @@ class TranslateASTVisitor final
645652
return true;
646653
}
647654

648-
649655
bool VisitNullStmt(NullStmt *NS) {
650656
std::vector<void*> childIds;
651657
encode_entry(NS, TagNullStmt, childIds);
@@ -724,8 +730,7 @@ class TranslateASTVisitor final
724730
Expr::EvalResult eval_result;
725731
#endif // CLANG_VERSION_MAJOR
726732
if (!expr->EvaluateAsInt(eval_result, *Context)) {
727-
std:: string msg = "Aborting due to the expression in `CaseStmt`\
728-
not being an integer.";
733+
std:: string msg = "Expression in case statement is not an integer. Aborting.";
729734
printError(msg, CS);
730735
abort();
731736
}
@@ -1218,10 +1223,10 @@ class TranslateASTVisitor final
12181223
if (!FD->isCanonicalDecl())
12191224
return true;
12201225

1221-
if (FD->hasBody() && FD->isVariadic()) {
1222-
// auto fname = FD->getNameString();
1223-
printWarning("variadic functions are not fully supported.", FD);
1224-
}
1226+
// if (FD->hasBody() && FD->isVariadic()) {
1227+
// // auto fname = FD->getNameString();
1228+
// printWarning("variadic functions are not fully supported.", FD);
1229+
// }
12251230

12261231
// Use the parameters from the function declaration
12271232
// the defines the body, if one exists.
@@ -1517,7 +1522,7 @@ class TranslateASTVisitor final
15171522
if (warnOnFlexibleArrayDecl(D)) {
15181523
printWarning("this may be an unsupported flexible array member with size of 1, "
15191524
"omit the size if this field is intended to be a flexible array member. "
1520-
"Note that you must be sure to fix any struct size calculations after "
1525+
"Note that you must fix any struct size calculations after "
15211526
"doing so or else it will likely be off (by one). "
15221527
"See section 6.7.2.1 of the C99 standard.", D);
15231528
}

c2rust-macros/Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "c2rust-macros"
3+
version = "0.9.0"
4+
authors = ["Stephen Crane <[email protected]>", "The C2Rust Project Developers <[email protected]>"]
5+
edition = "2018"
6+
7+
[lib]
8+
proc-macro = true
9+
10+
[dependencies]
11+
proc-macro2 = { version = "0.4", features = ["nightly"] }
12+
quote = "0.6"
13+
syn = { version = "0.15", features = ["full", "extra-traits", "visit"] }

0 commit comments

Comments
 (0)