typegen: expand function regex, support function overloads
This commit is contained in:
		
							parent
							
								
									2974ebeef8
								
							
						
					
					
						commit
						c1c349caaa
					
				
					 5 changed files with 36 additions and 9 deletions
				
			
		| 
						 | 
					@ -85,11 +85,11 @@
 | 
				
			||||||
{{- if $type.functions -}}
 | 
					{{- if $type.functions -}}
 | 
				
			||||||
<h4>Functions</h4>
 | 
					<h4>Functions</h4>
 | 
				
			||||||
<ul>
 | 
					<ul>
 | 
				
			||||||
	{{- range $funcname, $func := $type.functions -}}
 | 
						{{- range $func := $type.functions -}}
 | 
				
			||||||
	<li>
 | 
						<li>
 | 
				
			||||||
		<span class="typegray">
 | 
							<span class="typegray">
 | 
				
			||||||
			{{ partial "qmltype.html" $func.ret }}
 | 
								{{ partial "qmltype.html" $func.ret }}
 | 
				
			||||||
			<a href="#func.{{ $funcname }}">{{ $funcname }}</a>(
 | 
								<a href="#func.{{ $func.id }}">{{ $func.name }}</a>(
 | 
				
			||||||
				{{- partial "qmlparams.html" $func.params -}}
 | 
									{{- partial "qmlparams.html" $func.params -}}
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
		</span>
 | 
							</span>
 | 
				
			||||||
| 
						 | 
					@ -172,8 +172,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{{- if $type.functions -}}
 | 
					{{- if $type.functions -}}
 | 
				
			||||||
	<h3>Function Details</h3>
 | 
						<h3>Function Details</h3>
 | 
				
			||||||
	{{ range $funcname, $func := $type.functions }}
 | 
						{{ range $func := $type.functions }}
 | 
				
			||||||
		<div id="func.{{ $funcname }}" class = "qmlpropdef">
 | 
							<div id="func.{{ $func.id }}" class = "qmlpropdef">
 | 
				
			||||||
			{{- if $func.flags -}}
 | 
								{{- if $func.flags -}}
 | 
				
			||||||
				<span class="qmlprops typegray">
 | 
									<span class="qmlprops typegray">
 | 
				
			||||||
					{{ partial "qmltypeflags.html" $func.flags }}
 | 
										{{ partial "qmltypeflags.html" $func.flags }}
 | 
				
			||||||
| 
						 | 
					@ -184,7 +184,7 @@
 | 
				
			||||||
				<span class="typegray">
 | 
									<span class="typegray">
 | 
				
			||||||
					{{ partial "qmltype.html" $func.ret -}}
 | 
										{{ partial "qmltype.html" $func.ret -}}
 | 
				
			||||||
				</span>
 | 
									</span>
 | 
				
			||||||
				{{ $funcname -}}
 | 
									{{ $func.name -}}
 | 
				
			||||||
				<span class="typegray">(
 | 
									<span class="typegray">(
 | 
				
			||||||
					{{- partial "qmlparams.html" $func.params -}}
 | 
										{{- partial "qmlparams.html" $func.params -}}
 | 
				
			||||||
				)</span>
 | 
									)</span>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,7 +25,7 @@ pub struct ClassInfo {
 | 
				
			||||||
	#[serde(skip_serializing_if = "Vec::is_empty")]
 | 
						#[serde(skip_serializing_if = "Vec::is_empty")]
 | 
				
			||||||
	pub flags: Vec<Flag>,
 | 
						pub flags: Vec<Flag>,
 | 
				
			||||||
	pub properties: HashMap<String, Property>,
 | 
						pub properties: HashMap<String, Property>,
 | 
				
			||||||
	pub functions: HashMap<String, Function>,
 | 
						pub functions: Vec<Function>,
 | 
				
			||||||
	pub signals: HashMap<String, Signal>,
 | 
						pub signals: HashMap<String, Signal>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,6 +50,7 @@ pub enum PropertyType {
 | 
				
			||||||
pub struct Function {
 | 
					pub struct Function {
 | 
				
			||||||
	pub ret: Type,
 | 
						pub ret: Type,
 | 
				
			||||||
	pub name: String,
 | 
						pub name: String,
 | 
				
			||||||
 | 
						pub id: String,
 | 
				
			||||||
	pub details: Option<String>,
 | 
						pub details: Option<String>,
 | 
				
			||||||
	pub params: HashMap<String, Type>,
 | 
						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(),
 | 
								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(),
 | 
								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(),
 | 
								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(),
 | 
								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(),
 | 
								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(),
 | 
								signals_regex: Regex::new(r#"signals:(?<signals>(\s*(\s*///.*\s*)*void .*;)*)"#).unwrap(),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -146,6 +146,22 @@ pub fn resolve_types(
 | 
				
			||||||
			outform::Function {
 | 
								outform::Function {
 | 
				
			||||||
				ret: qmlparamtype(&func.ret, typespec),
 | 
									ret: qmlparamtype(&func.ret, typespec),
 | 
				
			||||||
				name: func.name.clone(),
 | 
									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(),
 | 
									details: func.details.clone(),
 | 
				
			||||||
				params: func
 | 
									params: func
 | 
				
			||||||
					.params
 | 
										.params
 | 
				
			||||||
| 
						 | 
					@ -183,8 +199,8 @@ pub fn resolve_types(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		let functions = functions
 | 
							let functions = functions
 | 
				
			||||||
			.iter()
 | 
								.iter()
 | 
				
			||||||
			.map(|func| (func.name.clone(), solvefunc(func, &typespec)))
 | 
								.map(|func| solvefunc(func, &typespec))
 | 
				
			||||||
			.collect::<HashMap<_, _>>();
 | 
								.collect::<Vec<_>>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		let signals = signals
 | 
							let signals = signals
 | 
				
			||||||
			.iter()
 | 
								.iter()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,6 +25,16 @@
 | 
				
			||||||
			"cname": "qreal",
 | 
								"cname": "qreal",
 | 
				
			||||||
			"module": null
 | 
								"module": null
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								"name": "point",
 | 
				
			||||||
 | 
								"cname": "QPointF",
 | 
				
			||||||
 | 
								"module": null
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								"name": "rect",
 | 
				
			||||||
 | 
								"cname": "QRectF",
 | 
				
			||||||
 | 
								"module": null
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			"name": "string",
 | 
								"name": "string",
 | 
				
			||||||
			"cname": "QString",
 | 
								"cname": "QString",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue