mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-22 22:46:26 +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);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
/// 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
|
||||
|
@ -92,13 +92,11 @@ fn parse_method(item: FnItem, options: &BindgenOptions) -> Option<ExternMethod>
|
||||
}
|
||||
|
||||
// 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::<Vec<_>>();
|
||||
|
||||
if !method_name.is_empty() && (options.method_filter)(method_name.clone()) {
|
||||
return Some(ExternMethod {
|
||||
|
@ -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<String>,
|
||||
pub doc_comment: Vec<String>,
|
||||
pub parameters: Vec<Parameter>,
|
||||
pub return_type: Option<RustType>,
|
||||
}
|
||||
|
||||
impl ExternMethod {
|
||||
pub fn escape_doc_comment(&self) -> Option<String> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
8
dotnet-sandbox/NativeMethods.cs
vendored
8
dotnet-sandbox/NativeMethods.cs
vendored
@ -12,6 +12,14 @@ namespace CsBindgen
|
||||
{
|
||||
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)]
|
||||
public static extern void other_2(NfcCard _hoge);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user