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

@ -22,11 +22,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1716289830, "lastModified": 1716510487,
"narHash": "sha256-kPxodbNTnCLtJ6MFih9LPULXh5l3st63t9isWIwvYSQ=", "narHash": "sha256-kdQ4CjAl9H7VSfo+vWfQZynBpqCeNovIgnHg6iQ+3hs=",
"ref": "refs/heads/master", "ref": "refs/heads/master",
"rev": "af45502913e0bb857755b2fa7e3ef991fff033ba", "rev": "5016dbf0d4c9e12f7e3d5f872b3063785d20b2bf",
"revCount": 179, "revCount": 184,
"type": "git", "type": "git",
"url": "https://git.outfoxxed.me/outfoxxed/quickshell" "url": "https://git.outfoxxed.me/outfoxxed/quickshell"
}, },

View file

@ -155,7 +155,7 @@ impl Parser {
let class = class?; let class = class?;
let comment = class.name("comment").map(|m| m.as_str()); 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 mut superclass = class.name("super").map(|m| m.as_str());
let body = class.name("body").unwrap().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_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_OBJECT" => classtype = Some(ClassType::Object),
"Q_GADGET" => classtype = Some(ClassType::Gadget), "Q_GADGET" => classtype = Some(ClassType::Gadget),
"QML_ELEMENT" | "QSDOC_ELEMENT" => qml_name = Some(name), "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 let qtype = typespec
.typemap .typemap
.iter() .iter()
@ -79,7 +83,7 @@ pub fn resolve_types(
} }
fn solveprop(prop: &Property, typespec: &TypeSpec) -> outform::Property { fn solveprop(prop: &Property, typespec: &TypeSpec) -> outform::Property {
let mut ctype = &prop.type_[..]; let ctype = &prop.type_[..];
let flags = { let flags = {
let mut flags = Vec::new(); let mut flags = Vec::new();
@ -112,32 +116,24 @@ pub fn resolve_types(
flags, flags,
}, },
None => { 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<") { // closing `>`
ctype = &ctype[17..ctype.len() - 1]; remaining = &remaining[0..remaining.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;
}
if ctype.ends_with('*') { (ctype, Some(remaining))
ctype = &ctype[0..ctype.len() - 1]; },
} };
let mut type_ = qmlparamtype(ctype, typespec); let mut type_ = qmlparamtype(ctype, typespec);
if list { if let Some(of) = of {
type_ = outform::Type { type_.of = Some(Box::new(qmlparamtype(of, typespec)));
type_: outform::TypeSource::Qt,
module: "qml".to_string(),
name: "list".to_string(),
of: Some(Box::new(type_)),
};
} }
outform::Property { outform::Property {

View file

@ -25,6 +25,11 @@
"cname": "quint32", "cname": "quint32",
"module": null "module": null
}, },
{
"name": "int",
"cname": "qsizetype",
"module": null
},
{ {
"name": "real", "name": "real",
"cname": "qreal", "cname": "qreal",
@ -60,6 +65,21 @@
"cname": "QObject", "cname": "QObject",
"module": "qml.QtQml" "module": "qml.QtQml"
}, },
{
"name": "list",
"cname": "QQmlListProperty",
"module": null
},
{
"name": "list",
"cname": "QList",
"module": null
},
{
"name": "list",
"cname": "QVector",
"module": null
},
{ {
"name": "Component", "name": "Component",
"cname": "QQmlComponent", "cname": "QQmlComponent",