typegen: expand function regex, support function overloads
This commit is contained in:
parent
2974ebeef8
commit
c1c349caaa
|
@ -85,11 +85,11 @@
|
|||
{{- if $type.functions -}}
|
||||
<h4>Functions</h4>
|
||||
<ul>
|
||||
{{- range $funcname, $func := $type.functions -}}
|
||||
{{- range $func := $type.functions -}}
|
||||
<li>
|
||||
<span class="typegray">
|
||||
{{ partial "qmltype.html" $func.ret }}
|
||||
<a href="#func.{{ $funcname }}">{{ $funcname }}</a>(
|
||||
<a href="#func.{{ $func.id }}">{{ $func.name }}</a>(
|
||||
{{- partial "qmlparams.html" $func.params -}}
|
||||
)
|
||||
</span>
|
||||
|
@ -172,8 +172,8 @@
|
|||
|
||||
{{- if $type.functions -}}
|
||||
<h3>Function Details</h3>
|
||||
{{ range $funcname, $func := $type.functions }}
|
||||
<div id="func.{{ $funcname }}" class = "qmlpropdef">
|
||||
{{ range $func := $type.functions }}
|
||||
<div id="func.{{ $func.id }}" class = "qmlpropdef">
|
||||
{{- if $func.flags -}}
|
||||
<span class="qmlprops typegray">
|
||||
{{ partial "qmltypeflags.html" $func.flags }}
|
||||
|
@ -184,7 +184,7 @@
|
|||
<span class="typegray">
|
||||
{{ partial "qmltype.html" $func.ret -}}
|
||||
</span>
|
||||
{{ $funcname -}}
|
||||
{{ $func.name -}}
|
||||
<span class="typegray">(
|
||||
{{- partial "qmlparams.html" $func.params -}}
|
||||
)</span>
|
||||
|
|
|
@ -25,7 +25,7 @@ pub struct ClassInfo {
|
|||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub flags: Vec<Flag>,
|
||||
pub properties: HashMap<String, Property>,
|
||||
pub functions: HashMap<String, Function>,
|
||||
pub functions: Vec<Function>,
|
||||
pub signals: HashMap<String, Signal>,
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@ pub enum PropertyType {
|
|||
pub struct Function {
|
||||
pub ret: Type,
|
||||
pub name: String,
|
||||
pub id: String,
|
||||
pub details: Option<String>,
|
||||
pub params: HashMap<String, Type>,
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ impl Parser {
|
|||
class_regex: Regex::new(r#"(?<comment>(\s*\/\/\/.*\n)+)?\s*class\s+(?<name>\w+)(?:\s*:\s*public\s+(?<super>\w+)(\s*,(\s*\w+)*)*)?\s*\{(?<body>[\s\S]*?)};"#).unwrap(),
|
||||
macro_regex: Regex::new(r#"(?<comment>(\s*\/\/\/.*\n)+)?\s*(?<hide>QSDOC_HIDE\s)?(?<type>(Q|QML|QSDOC)_\w+)\s*(\(\s*(?<args>.*)\s*\))?;"#).unwrap(),
|
||||
property_regex: Regex::new(r#"^\s*(?<type>(\w|::|, |<|>)+)\*?\s+(?<name>\w+)(\s+(MEMBER\s+(?<member>\w+)|READ\s+(?<read>\w+)|WRITE\s+(?<write>\w+)|NOTIFY\s+(?<notify>\w+)|(?<const>CONSTANT)))+\s*$"#).unwrap(),
|
||||
fn_regex: Regex::new(r#"(?<comment>(\s*\/\/\/.*\n)+)?\s*Q_INVOKABLE\s+(?<type>(\w|::|<|>)+\*?)\s+(?<name>\w+)\((?<params>[\s\S]*?)\);"#).unwrap(),
|
||||
fn_regex: Regex::new(r#"(?<comment>(\s*\/\/\/.*\n)+)?\s*Q_INVOKABLE\s+(\[\[.*\]\]\s+)?(?<type>(\w|::|<|>)+\*?)\s+(?<name>\w+)\((?<params>[\s\S]*?)\)(\s*const);"#).unwrap(),
|
||||
signal_regex: Regex::new(r#"(?<comment>(\s*\/\/\/.*\n)+)?\s*void\s+(?<name>\w+)\((?<params>[\s\S]*?)\);"#).unwrap(),
|
||||
fn_param_regex: Regex::new(r#"(const\s+)?(?<type>(\w|::|<|>)+\*?)&?\s+(?<name>\w+)(,|$)"#).unwrap(),
|
||||
signals_regex: Regex::new(r#"signals:(?<signals>(\s*(\s*///.*\s*)*void .*;)*)"#).unwrap(),
|
||||
|
|
|
@ -146,6 +146,22 @@ pub fn resolve_types(
|
|||
outform::Function {
|
||||
ret: qmlparamtype(&func.ret, typespec),
|
||||
name: func.name.clone(),
|
||||
id: {
|
||||
let params = func.params
|
||||
.iter()
|
||||
.map(|FnParam { type_, .. }| qmlparamtype(type_, typespec).name);
|
||||
|
||||
let mut id = func.name.clone();
|
||||
id.push('(');
|
||||
for param in params {
|
||||
id.push_str(¶m);
|
||||
id.push('_')
|
||||
}
|
||||
id.truncate(id.len() - 1);
|
||||
id.push(')');
|
||||
|
||||
id
|
||||
},
|
||||
details: func.details.clone(),
|
||||
params: func
|
||||
.params
|
||||
|
@ -183,8 +199,8 @@ pub fn resolve_types(
|
|||
|
||||
let functions = functions
|
||||
.iter()
|
||||
.map(|func| (func.name.clone(), solvefunc(func, &typespec)))
|
||||
.collect::<HashMap<_, _>>();
|
||||
.map(|func| solvefunc(func, &typespec))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let signals = signals
|
||||
.iter()
|
||||
|
|
|
@ -25,6 +25,16 @@
|
|||
"cname": "qreal",
|
||||
"module": null
|
||||
},
|
||||
{
|
||||
"name": "point",
|
||||
"cname": "QPointF",
|
||||
"module": null
|
||||
},
|
||||
{
|
||||
"name": "rect",
|
||||
"cname": "QRectF",
|
||||
"module": null
|
||||
},
|
||||
{
|
||||
"name": "string",
|
||||
"cname": "QString",
|
||||
|
|
Loading…
Reference in a new issue