fix #205 Negative literals (#323)

* fix #205

Signed-off-by: Axel Nennker <axel.nennker@telekom.de>

* remove comment

Signed-off-by: Axel Nennker <axel.nennker@telekom.de>
This commit is contained in:
Axel Nennker 2019-04-19 15:45:16 +02:00 committed by Emilio Cobos Álvarez
parent 3841c2c30e
commit 87007649c8
6 changed files with 32 additions and 1 deletions

View File

@ -19,6 +19,7 @@ use bindgen::ir::{
use bindgen::library::Library;
use bindgen::writer::{Source, SourceWriter};
use bindgen::Bindings;
use syn::UnOp;
#[derive(Debug, Clone)]
pub enum Literal {
@ -209,7 +210,18 @@ impl Literal {
fields: field_pairs,
})
}
_ => Err("Unsupported literal expression.".to_owned()),
syn::Expr::Unary(syn::ExprUnary {
attrs: _,
ref op,
ref expr,
}) => match *op {
UnOp::Neg(_) => {
let val = Self::load(expr)?;
Ok(Literal::Expr(format!("-{}", val)))
}
_ => Err(format!("Unsupported Unary expression. {:?}", *op)),
},
_ => Err(format!("Unsupported literal expression. {:?}", *expr)),
}
}
}

View File

@ -11,8 +11,12 @@
#define LEFTCURLY '{'
#define NEG_ONE -1
#define NEWLINE '\n'
#define POS_ONE 1
#define QUOTE '\''
#define TAB '\t'

View File

@ -11,8 +11,12 @@
#define LEFTCURLY '{'
#define NEG_ONE -1
#define NEWLINE '\n'
#define POS_ONE 1
#define QUOTE '\''
#define TAB '\t'

View File

@ -10,8 +10,12 @@ static const wchar_t HEART = L'\u2764';
static const wchar_t LEFTCURLY = '{';
static const int8_t NEG_ONE = -1;
static const wchar_t NEWLINE = '\n';
static const int8_t POS_ONE = 1;
static const wchar_t QUOTE = '\'';
static const wchar_t TAB = '\t';

View File

@ -11,8 +11,12 @@
#define LEFTCURLY '{'
#define NEG_ONE -1
#define NEWLINE '\n'
#define POS_ONE 1
#define QUOTE '\''
#define TAB '\t'

View File

@ -11,6 +11,9 @@ pub const ZOM: f32 = 3.14;
pub(crate) const DONT_EXPORT_CRATE: i32 = 20;
const DONT_EXPORT_PRIV: i32 = 30;
pub const POS_ONE: i8 = 1;
pub const NEG_ONE: i8 = -1;
#[repr(C)]
struct Foo {
x: [i32; FOO],