diff --git a/csbindgen-tests/src/lib.rs b/csbindgen-tests/src/lib.rs index def85cd..40baa59 100644 --- a/csbindgen-tests/src/lib.rs +++ b/csbindgen-tests/src/lib.rs @@ -73,6 +73,26 @@ mod lz4_ffi; // 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)] pub struct NfcCard { pub delegate: unsafe extern "C" fn(ByteArray) -> ByteArray diff --git a/csbindgen/src/parser.rs b/csbindgen/src/parser.rs index bdc8755..19758a8 100644 --- a/csbindgen/src/parser.rs +++ b/csbindgen/src/parser.rs @@ -92,13 +92,11 @@ fn parse_method(item: FnItem, options: &BindgenOptions) -> Option } // doc - let mut doc_comment = None; - for attr in attrs { - let last_segment = attr.path.segments.last().unwrap(); - if last_segment.ident == "doc" { - doc_comment = Some(attr.tokens.to_string()); - } - } + let doc_comment = attrs + .iter() + .filter(|x| x.path.segments.last().unwrap().ident == "doc") + .map(|x| x.tokens.to_string()) + .collect::>(); if !method_name.is_empty() && (options.method_filter)(method_name.clone()) { return Some(ExternMethod { diff --git a/csbindgen/src/type_meta.rs b/csbindgen/src/type_meta.rs index f6e7450..394c546 100644 --- a/csbindgen/src/type_meta.rs +++ b/csbindgen/src/type_meta.rs @@ -12,9 +12,7 @@ pub fn escape_name(str: &str) -> String { | "protected" | "public" | "readonly" | "ref" | "return" | "sbyte" | "sealed" | "short" | "sizeof" | "stackalloc" | "static" | "string" | "struct" | "switch" | "this" | "throw" | "true" | "try" | "typeof" | "uint" | "ulong" | "unchecked" | "unsafe" - | "ushort" | "using" | "virtual" | "void" | "volatile" | "while" => { - "@".to_string() + str - } + | "ushort" | "using" | "virtual" | "void" | "volatile" | "while" => "@".to_string() + str, x => x.to_string(), } } @@ -34,24 +32,31 @@ pub struct FieldMember { #[derive(Clone, Debug)] pub struct ExternMethod { pub method_name: String, - pub doc_comment: Option, + pub doc_comment: Vec, pub parameters: Vec, pub return_type: Option, } impl ExternMethod { pub fn escape_doc_comment(&self) -> Option { - match &self.doc_comment { - Some(x) => { - let s = x - .trim_matches(&['=', ' ', '\"'] as &[_]) - .replace("\\n", "") - .replace("<", "<") - .replace(">", ">"); - Some(s) - } - None => None, + if self.doc_comment.is_empty() { + return None; } + + 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 &[_]) + .replace("\\n", "") + .replace("<", "<") + .replace(">", ">"); + s.push_str(ss.as_str()); + } + + Some(s) } } diff --git a/dotnet-sandbox/NativeMethods.cs b/dotnet-sandbox/NativeMethods.cs index f3ba96c..79663f1 100644 --- a/dotnet-sandbox/NativeMethods.cs +++ b/dotnet-sandbox/NativeMethods.cs @@ -12,6 +12,14 @@ namespace CsBindgen { const string __DllName = "csbindgen_tests"; + /// my comment! + [DllImport(__DllName, EntryPoint = "comment_one", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void comment_one(); + + /// Multiline Comments # GOTO Here Foo Bar TO ZZZ + [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)] public static extern void other_2(NfcCard _hoge);