2
1
Fork 0

typegen: add support for generics

This commit is contained in:
outfoxxed 2024-05-23 17:32:51 -07:00
parent 4bedd19610
commit 768096e5cf
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 48 additions and 28 deletions

View file

@ -155,7 +155,7 @@ impl Parser {
let class = class?;
let comment = class.name("comment").map(|m| m.as_str());
let name = class.name("name").unwrap().as_str();
let mut name = class.name("name").unwrap().as_str();
let mut superclass = class.name("super").map(|m| m.as_str());
let body = class.name("body").unwrap().as_str();
@ -189,6 +189,10 @@ impl Parser {
"QSDOC_BASECLASS must have the base class as an argument",
))
},
"QSDOC_CNAME" => {
name = args
.expect("QSDOC_CNAME must specify the cname as an argument");
},
"Q_OBJECT" => classtype = Some(ClassType::Object),
"Q_GADGET" => classtype = Some(ClassType::Gadget),
"QML_ELEMENT" | "QSDOC_ELEMENT" => qml_name = Some(name),

View file

@ -56,7 +56,11 @@ pub fn resolve_types(
}
};
fn qmlparamtype(ctype: &str, typespec: &TypeSpec) -> outform::Type {
fn qmlparamtype(mut ctype: &str, typespec: &TypeSpec) -> outform::Type {
if ctype.ends_with('*') {
ctype = &ctype[0..ctype.len() - 1];
}
let qtype = typespec
.typemap
.iter()
@ -79,7 +83,7 @@ pub fn resolve_types(
}
fn solveprop(prop: &Property, typespec: &TypeSpec) -> outform::Property {
let mut ctype = &prop.type_[..];
let ctype = &prop.type_[..];
let flags = {
let mut flags = Vec::new();
@ -112,32 +116,24 @@ pub fn resolve_types(
flags,
},
None => {
let mut list = false;
let (ctype, of) = match ctype.split_once('<') {
None => (ctype, None),
Some((ctype, mut remaining)) => {
if remaining.ends_with('*') {
remaining = &remaining[0..remaining.len() - 1];
}
if ctype.starts_with("QQmlListProperty<") {
ctype = &ctype[17..ctype.len() - 1];
list = true;
} else if ctype.starts_with("QList<") {
ctype = &ctype[6..ctype.len() - 1];
list = true;
} else if ctype.starts_with("QVector<") {
ctype = &ctype[8..ctype.len() - 1];
list = true;
}
// closing `>`
remaining = &remaining[0..remaining.len() - 1];
if ctype.ends_with('*') {
ctype = &ctype[0..ctype.len() - 1];
}
(ctype, Some(remaining))
},
};
let mut type_ = qmlparamtype(ctype, typespec);
if list {
type_ = outform::Type {
type_: outform::TypeSource::Qt,
module: "qml".to_string(),
name: "list".to_string(),
of: Some(Box::new(type_)),
};
if let Some(of) = of {
type_.of = Some(Box::new(qmlparamtype(of, typespec)));
}
outform::Property {