mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-23 06:56:27 +00:00
generate multilined comment
This commit is contained in:
parent
a1db7165c7
commit
8ab40dd96c
20
csbindgen-tests/src/lib.rs
vendored
20
csbindgen-tests/src/lib.rs
vendored
@ -73,6 +73,26 @@ mod lz4_ffi;
|
|||||||
// println!("{}", str);
|
// println!("{}", str);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// my comment!
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn comment_one() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Multiline Comments
|
||||||
|
/// # GOTO
|
||||||
|
/// Here
|
||||||
|
/// Foo
|
||||||
|
/// Bar
|
||||||
|
///
|
||||||
|
/// TO
|
||||||
|
///
|
||||||
|
/// ZZZ
|
||||||
|
pub extern "C" fn long_jpn_comment() {
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct NfcCard {
|
pub struct NfcCard {
|
||||||
pub delegate: unsafe extern "C" fn(ByteArray) -> ByteArray
|
pub delegate: unsafe extern "C" fn(ByteArray) -> ByteArray
|
||||||
|
@ -92,13 +92,11 @@ fn parse_method(item: FnItem, options: &BindgenOptions) -> Option<ExternMethod>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// doc
|
// doc
|
||||||
let mut doc_comment = None;
|
let doc_comment = attrs
|
||||||
for attr in attrs {
|
.iter()
|
||||||
let last_segment = attr.path.segments.last().unwrap();
|
.filter(|x| x.path.segments.last().unwrap().ident == "doc")
|
||||||
if last_segment.ident == "doc" {
|
.map(|x| x.tokens.to_string())
|
||||||
doc_comment = Some(attr.tokens.to_string());
|
.collect::<Vec<_>>();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !method_name.is_empty() && (options.method_filter)(method_name.clone()) {
|
if !method_name.is_empty() && (options.method_filter)(method_name.clone()) {
|
||||||
return Some(ExternMethod {
|
return Some(ExternMethod {
|
||||||
|
@ -12,9 +12,7 @@ pub fn escape_name(str: &str) -> String {
|
|||||||
| "protected" | "public" | "readonly" | "ref" | "return" | "sbyte" | "sealed" | "short"
|
| "protected" | "public" | "readonly" | "ref" | "return" | "sbyte" | "sealed" | "short"
|
||||||
| "sizeof" | "stackalloc" | "static" | "string" | "struct" | "switch" | "this"
|
| "sizeof" | "stackalloc" | "static" | "string" | "struct" | "switch" | "this"
|
||||||
| "throw" | "true" | "try" | "typeof" | "uint" | "ulong" | "unchecked" | "unsafe"
|
| "throw" | "true" | "try" | "typeof" | "uint" | "ulong" | "unchecked" | "unsafe"
|
||||||
| "ushort" | "using" | "virtual" | "void" | "volatile" | "while" => {
|
| "ushort" | "using" | "virtual" | "void" | "volatile" | "while" => "@".to_string() + str,
|
||||||
"@".to_string() + str
|
|
||||||
}
|
|
||||||
x => x.to_string(),
|
x => x.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,25 +32,32 @@ pub struct FieldMember {
|
|||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ExternMethod {
|
pub struct ExternMethod {
|
||||||
pub method_name: String,
|
pub method_name: String,
|
||||||
pub doc_comment: Option<String>,
|
pub doc_comment: Vec<String>,
|
||||||
pub parameters: Vec<Parameter>,
|
pub parameters: Vec<Parameter>,
|
||||||
pub return_type: Option<RustType>,
|
pub return_type: Option<RustType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExternMethod {
|
impl ExternMethod {
|
||||||
pub fn escape_doc_comment(&self) -> Option<String> {
|
pub fn escape_doc_comment(&self) -> Option<String> {
|
||||||
match &self.doc_comment {
|
if self.doc_comment.is_empty() {
|
||||||
Some(x) => {
|
return None;
|
||||||
let s = x
|
}
|
||||||
|
|
||||||
|
let mut s = String::new();
|
||||||
|
for (i, x) in self.doc_comment.iter().enumerate() {
|
||||||
|
if i != 0 {
|
||||||
|
s.push(' ');
|
||||||
|
}
|
||||||
|
let ss = x
|
||||||
.trim_matches(&['=', ' ', '\"'] as &[_])
|
.trim_matches(&['=', ' ', '\"'] as &[_])
|
||||||
.replace("\\n", "")
|
.replace("\\n", "")
|
||||||
.replace("<", "<")
|
.replace("<", "<")
|
||||||
.replace(">", ">");
|
.replace(">", ">");
|
||||||
|
s.push_str(ss.as_str());
|
||||||
|
}
|
||||||
|
|
||||||
Some(s)
|
Some(s)
|
||||||
}
|
}
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
8
dotnet-sandbox/NativeMethods.cs
vendored
8
dotnet-sandbox/NativeMethods.cs
vendored
@ -12,6 +12,14 @@ namespace CsBindgen
|
|||||||
{
|
{
|
||||||
const string __DllName = "csbindgen_tests";
|
const string __DllName = "csbindgen_tests";
|
||||||
|
|
||||||
|
/// <summary>my comment!</summary>
|
||||||
|
[DllImport(__DllName, EntryPoint = "comment_one", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern void comment_one();
|
||||||
|
|
||||||
|
/// <summary>Multiline Comments # GOTO Here Foo Bar TO ZZZ</summary>
|
||||||
|
[DllImport(__DllName, EntryPoint = "long_jpn_comment", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern void long_jpn_comment();
|
||||||
|
|
||||||
[DllImport(__DllName, EntryPoint = "other_2", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "other_2", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void other_2(NfcCard _hoge);
|
public static extern void other_2(NfcCard _hoge);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user