Fixed missing prefix for named consts in [T; <Const>] types
This commit is contained in:
@@ -122,7 +122,8 @@ impl CDecl {
|
||||
self.build_type(t, false);
|
||||
}
|
||||
&Type::Array(ref t, ref constant) => {
|
||||
self.declarators.push(CDeclarator::Array(constant.clone()));
|
||||
let len = constant.as_str().to_owned();
|
||||
self.declarators.push(CDeclarator::Array(len));
|
||||
self.build_type(t, false);
|
||||
}
|
||||
&Type::FuncPtr(ref ret, ref args) => {
|
||||
|
||||
+26
-5
@@ -166,13 +166,28 @@ impl fmt::Display for PrimitiveType {
|
||||
}
|
||||
}
|
||||
|
||||
// The `U` part of `[T; U]`
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum ArrayLength {
|
||||
Name(String),
|
||||
Value(String),
|
||||
}
|
||||
|
||||
impl ArrayLength {
|
||||
pub fn as_str(&self) -> &str {
|
||||
match self {
|
||||
ArrayLength::Name(ref string) | ArrayLength::Value(ref string) => string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum Type {
|
||||
ConstPtr(Box<Type>),
|
||||
Ptr(Box<Type>),
|
||||
Path(GenericPath),
|
||||
Primitive(PrimitiveType),
|
||||
Array(Box<Type>, String),
|
||||
Array(Box<Type>, ArrayLength),
|
||||
FuncPtr(Box<Type>, Vec<Type>),
|
||||
}
|
||||
|
||||
@@ -242,8 +257,9 @@ impl Type {
|
||||
};
|
||||
|
||||
let path = GenericPath::load(&path.path)?;
|
||||
|
||||
Type::Array(Box::new(converted), path.name)
|
||||
let len = ArrayLength::Name(path.name);
|
||||
// panic!("panic -> name: {:?}", len);
|
||||
Type::Array(Box::new(converted), len)
|
||||
}
|
||||
&syn::Type::Array(syn::TypeArray {
|
||||
ref elem,
|
||||
@@ -261,7 +277,9 @@ impl Type {
|
||||
None => return Err("Cannot have an array of zero sized types.".to_owned()),
|
||||
};
|
||||
|
||||
Type::Array(Box::new(converted), format!("{}", len.value()))
|
||||
let len = ArrayLength::Value(format!("{}", len.value()));
|
||||
// panic!("panic -> value: {:?}", len);
|
||||
Type::Array(Box::new(converted), len)
|
||||
}
|
||||
&syn::Type::BareFn(ref function) => {
|
||||
let args = function.inputs.iter().try_skip_map(|x| Type::load(&x.ty))?;
|
||||
@@ -480,8 +498,11 @@ impl Type {
|
||||
config.export.rename(&mut path.name);
|
||||
}
|
||||
&mut Type::Primitive(_) => {}
|
||||
&mut Type::Array(ref mut ty, _) => {
|
||||
&mut Type::Array(ref mut ty, ref mut len) => {
|
||||
ty.rename_for_config(config);
|
||||
if let ArrayLength::Name(ref mut name) = len {
|
||||
config.export.rename(name);
|
||||
}
|
||||
}
|
||||
&mut Type::FuncPtr(ref mut ret, ref mut args) => {
|
||||
ret.rename_for_config(config);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define PREFIX_LEN 42
|
||||
|
||||
typedef int32_t PREFIX_NamedLenArray[PREFIX_LEN];
|
||||
|
||||
typedef int32_t PREFIX_ValuedLenArray[42];
|
||||
|
||||
void root(PREFIX_NamedLenArray x, PREFIX_ValuedLenArray y);
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define PREFIX_LEN 42
|
||||
|
||||
typedef int32_t PREFIX_NamedLenArray[PREFIX_LEN];
|
||||
|
||||
typedef int32_t PREFIX_ValuedLenArray[42];
|
||||
|
||||
void root(PREFIX_NamedLenArray x, PREFIX_ValuedLenArray y);
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
static const int32_t PREFIX_LEN = 42;
|
||||
|
||||
using PREFIX_NamedLenArray = int32_t[PREFIX_LEN];
|
||||
|
||||
using PREFIX_ValuedLenArray = int32_t[42];
|
||||
|
||||
extern "C" {
|
||||
|
||||
void root(PREFIX_NamedLenArray x, PREFIX_ValuedLenArray y);
|
||||
|
||||
} // extern "C"
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define PREFIX_LEN 42
|
||||
|
||||
typedef int32_t PREFIX_NamedLenArray[PREFIX_LEN];
|
||||
|
||||
typedef int32_t PREFIX_ValuedLenArray[42];
|
||||
|
||||
void root(PREFIX_NamedLenArray x, PREFIX_ValuedLenArray y);
|
||||
@@ -0,0 +1,7 @@
|
||||
const LEN: i32 = 42;
|
||||
|
||||
pub type NamedLenArray = [i32; LEN];
|
||||
pub type ValuedLenArray = [i32; 42];
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn root(x: NamedLenArray, y: ValuedLenArray) { }
|
||||
@@ -0,0 +1,2 @@
|
||||
[export]
|
||||
prefix = "PREFIX_"
|
||||
Reference in New Issue
Block a user