Skip to content

Commit

Permalink
Bump rustc to nightly 2019-04-08 (immunant#49)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rinon committed Apr 10, 2019
1 parent 75746ee commit 65d1aba
Show file tree
Hide file tree
Showing 128 changed files with 4,251 additions and 3,784 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"c2rust-ast-exporter",
"manual/preprocessors",
"c2rust-bitfields",
"c2rust-macros",
]
exclude = [
"cross-checks/pointer-tracer",
Expand Down
64 changes: 32 additions & 32 deletions c2rust-ast-builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use syntax::source_map::{DUMMY_SP, Spanned, Span, dummy_spanned};
use syntax::parse::token::{self, Token, DelimToken};
use syntax::attr::{mk_attr_inner};
use syntax::ptr::P;
use syntax::tokenstream::{TokenTree, TokenStream, TokenStreamBuilder, ThinTokenStream};
use syntax::tokenstream::{TokenTree, TokenStream, TokenStreamBuilder};
use syntax::symbol::keywords;
use std::rc::Rc;
use rustc_target::spec::abi::{self, Abi};
Expand Down Expand Up @@ -183,14 +183,14 @@ impl<S: Make<PathSegment>> Make<Path> for Vec<S> {
}


impl Make<ThinTokenStream> for TokenStream {
fn make(self, _mk: &Builder) -> ThinTokenStream {
self.into()
}
}
//impl Make<TokenStream> for TokenStream {
// fn make(self, _mk: &Builder) -> TokenStream {
// self.into()
// }
//}

impl Make<ThinTokenStream> for Vec<TokenTree> {
fn make(self, _mk: &Builder) -> ThinTokenStream {
impl Make<TokenStream> for Vec<TokenTree> {
fn make(self, _mk: &Builder) -> TokenStream {
self.into_iter().collect::<TokenStream>().into()
}
}
Expand All @@ -207,7 +207,7 @@ impl Make<GenericArgs> for AngleBracketedArgs {
}
}

impl Make<GenericArgs> for ParenthesisedArgs {
impl Make<GenericArgs> for ParenthesizedArgs {
fn make(self, _mk: &Builder) -> GenericArgs {
Parenthesized(self)
}
Expand All @@ -225,15 +225,15 @@ impl Make<GenericArg> for Lifetime {
}
}

impl Make<NestedMetaItemKind> for MetaItem {
fn make(self, _mk: &Builder) -> NestedMetaItemKind {
NestedMetaItemKind::MetaItem(self)
impl Make<NestedMetaItem> for MetaItem {
fn make(self, _mk: &Builder) -> NestedMetaItem {
NestedMetaItem::MetaItem(self)
}
}

impl Make<NestedMetaItemKind> for Lit {
fn make(self, _mk: &Builder) -> NestedMetaItemKind {
NestedMetaItemKind::Literal(self)
impl Make<NestedMetaItem> for Lit {
fn make(self, _mk: &Builder) -> NestedMetaItem {
NestedMetaItem::Literal(self)
}
}

Expand Down Expand Up @@ -448,11 +448,11 @@ impl Builder {
}
}

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

let tys = tys.make(&self);
ParenthesisedArgs {
ParenthesizedArgs {
span: self.span,
inputs: tys,
output: None,
Expand Down Expand Up @@ -495,8 +495,8 @@ impl Builder {
pub fn abs_path<Pa>(self, path: Pa) -> Path
where Pa: Make<Path> {
let mut p = path.make(&self);
if !p.segments.get(0).map_or(false, |s| s.ident.name == keywords::CrateRoot.name()) {
p.segments.insert(0, keywords::CrateRoot.ident().make(&self));
if !p.segments.get(0).map_or(false, |s| s.ident.name == keywords::PathRoot.name()) {
p.segments.insert(0, keywords::PathRoot.ident().make(&self));
}
p
}
Expand Down Expand Up @@ -1284,7 +1284,7 @@ impl Builder {
let block = block.make(&self);
let header = FnHeader {
unsafety: self.unsafety,
asyncness: IsAsync::NotAsync,
asyncness: dummy_spanned(IsAsync::NotAsync),
constness: dummy_spanned(self.constness),
abi: self.abi,
};
Expand All @@ -1295,28 +1295,28 @@ impl Builder {
block))
}

pub fn fn_decl(self, inputs: Vec<Arg>, output: FunctionRetTy, variadic: bool) -> P<FnDecl>
pub fn fn_decl(self, inputs: Vec<Arg>, output: FunctionRetTy, c_variadic: bool) -> P<FnDecl>
{
P(FnDecl {
inputs,
output,
variadic,
c_variadic,
})
}

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

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

Expand Down Expand Up @@ -1367,6 +1367,7 @@ impl Builder {
node: Variant_ {
ident: name,
attrs: self.attrs,
id: DUMMY_NODE_ID,
data: dat,
disr_expr: None,
},
Expand All @@ -1382,6 +1383,7 @@ impl Builder {
node: Variant_ {
ident: name,
attrs: self.attrs,
id: DUMMY_NODE_ID,
data: VariantData::Unit(self.id),
disr_expr: disc,
},
Expand Down Expand Up @@ -1577,7 +1579,6 @@ impl Builder {
Unsafety::Normal => BlockCheckMode::Default,
},
span: self.span,
recovered: false,
})
}

Expand Down Expand Up @@ -1637,7 +1638,7 @@ impl Builder {
}

pub fn attribute<Pa, Ts>(self, style: AttrStyle, path: Pa, tokens: Ts) -> Attribute
where Pa: Make<Path>, Ts: Make<ThinTokenStream>
where Pa: Make<Path>, Ts: Make<TokenStream>
{
let path = path.make(&self);
let tokens = tokens.make(&self).into();
Expand Down Expand Up @@ -1665,17 +1666,16 @@ impl Builder {
let path = path.make(&self);
let kind = kind.make(&self);
MetaItem {
ident: path,
path: path,
node: kind,
span: DUMMY_SP,
}
}

pub fn nested_meta_item<K>(self, kind: K) -> NestedMetaItem
where K: Make<NestedMetaItemKind>
{
let kind = kind.make(&self);
dummy_spanned(kind)
where K: Make<NestedMetaItem>
{
kind.make(&self)
}

// Convert the current internal list of outer attributes
Expand All @@ -1691,7 +1691,7 @@ impl Builder {
}

pub fn mac<Pa, Ts>(self, path: Pa, tts: Ts, delim: MacDelimiter) -> Mac
where Pa: Make<Path>, Ts: Make<ThinTokenStream> {
where Pa: Make<Path>, Ts: Make<TokenStream> {
let path = path.make(&self);
let tts = tts.make(&self);
Spanned {
Expand Down
6 changes: 3 additions & 3 deletions c2rust-ast-exporter/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ variable or make sure `llvm-config` is on $PATH then re-build. For example:
.or(invoke_command(llvm_config.as_ref(), &["--system-libs", "--link-static"]))
.unwrap_or(String::new())
.split_whitespace()
.map(|lib| String::from(lib.trim_left_matches("-l")))
.map(|lib| String::from(lib.trim_start_matches("-l")))
.collect();

let llvm_dylib = invoke_command(llvm_config.as_ref(), &["--libs", "--link-shared"]);
Expand All @@ -314,7 +314,7 @@ variable or make sure `llvm-config` is on $PATH then re-build. For example:
} // Windows is not supported
};
let mut dylib_file = String::from("lib");
dylib_file.push_str(llvm_dylib.trim_left_matches("-l"));
dylib_file.push_str(llvm_dylib.trim_start_matches("-l"));
dylib_file.push_str(dylib_suffix);
let sysroot = invoke_command(
env::var("RUSTC").ok().as_ref(),
Expand Down Expand Up @@ -353,7 +353,7 @@ variable or make sure `llvm-config` is on $PATH then re-build. For example:
])
.unwrap_or(String::new())
.split_whitespace()
.map(|lib| String::from(lib.trim_left_matches("-l")))
.map(|lib| String::from(lib.trim_start_matches("-l")))
.collect();

Self {
Expand Down
21 changes: 13 additions & 8 deletions c2rust-ast-exporter/src/AstExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,13 @@ class TranslateASTVisitor final
return true;
}

bool VisitIndirectGotoStmt(IndirectGotoStmt *IGS) {
std:: string msg = "the GNU C labels-as-values extension is not supported. Aborting.";

printError(msg, IGS);
abort();
}

bool VisitLabelStmt(LabelStmt *LS) {

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


bool VisitNullStmt(NullStmt *NS) {
std::vector<void*> childIds;
encode_entry(NS, TagNullStmt, childIds);
Expand Down Expand Up @@ -724,8 +730,7 @@ class TranslateASTVisitor final
Expr::EvalResult eval_result;
#endif // CLANG_VERSION_MAJOR
if (!expr->EvaluateAsInt(eval_result, *Context)) {
std:: string msg = "Aborting due to the expression in `CaseStmt`\
not being an integer.";
std:: string msg = "Expression in case statement is not an integer. Aborting.";
printError(msg, CS);
abort();
}
Expand Down Expand Up @@ -1218,10 +1223,10 @@ class TranslateASTVisitor final
if (!FD->isCanonicalDecl())
return true;

if (FD->hasBody() && FD->isVariadic()) {
// auto fname = FD->getNameString();
printWarning("variadic functions are not fully supported.", FD);
}
// if (FD->hasBody() && FD->isVariadic()) {
// // auto fname = FD->getNameString();
// printWarning("variadic functions are not fully supported.", FD);
// }

// Use the parameters from the function declaration
// the defines the body, if one exists.
Expand Down Expand Up @@ -1517,7 +1522,7 @@ class TranslateASTVisitor final
if (warnOnFlexibleArrayDecl(D)) {
printWarning("this may be an unsupported flexible array member with size of 1, "
"omit the size if this field is intended to be a flexible array member. "
"Note that you must be sure to fix any struct size calculations after "
"Note that you must fix any struct size calculations after "
"doing so or else it will likely be off (by one). "
"See section 6.7.2.1 of the C99 standard.", D);
}
Expand Down
13 changes: 13 additions & 0 deletions c2rust-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "c2rust-macros"
version = "0.9.0"
authors = ["Stephen Crane <sjc@immunant.com>", "The C2Rust Project Developers <c2rust@immunant.com>"]
edition = "2018"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = { version = "0.4", features = ["nightly"] }
quote = "0.6"
syn = { version = "0.15", features = ["full", "extra-traits", "visit"] }
Loading

0 comments on commit 65d1aba

Please sign in to comment.