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": {
"lastModified": 1716289830,
"narHash": "sha256-kPxodbNTnCLtJ6MFih9LPULXh5l3st63t9isWIwvYSQ=",
"lastModified": 1716510487,
"narHash": "sha256-kdQ4CjAl9H7VSfo+vWfQZynBpqCeNovIgnHg6iQ+3hs=",
"ref": "refs/heads/master",
"rev": "af45502913e0bb857755b2fa7e3ef991fff033ba",
"revCount": 179,
"rev": "5016dbf0d4c9e12f7e3d5f872b3063785d20b2bf",
"revCount": 184,
"type": "git",
"url": "https://git.outfoxxed.me/outfoxxed/quickshell"
},

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 {

View file

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