33//
44// SPDX-License-Identifier: MIT OR Apache-2.0
55
6+ pub mod attribute;
67pub mod constructor;
78pub mod cxxqtdata;
89pub mod externcxxqt;
@@ -18,10 +19,8 @@ pub mod qobject;
1819pub mod signals;
1920pub mod trait_impl;
2021
21- use crate :: {
22- naming:: TypeNames ,
23- syntax:: { expr:: expr_to_string, path:: path_compare_str} ,
24- } ;
22+ use crate :: parser:: attribute:: ParsedAttribute ;
23+ use crate :: { naming:: TypeNames , syntax:: expr:: expr_to_string} ;
2524use convert_case:: Case ;
2625use cxxqtdata:: ParsedCxxQtData ;
2726use std:: collections:: BTreeMap ;
@@ -87,24 +86,6 @@ impl CaseConversion {
8786 }
8887}
8988
90- /// Iterate the attributes of the method to extract cfg attributes
91- pub fn extract_cfgs ( attrs : & [ Attribute ] ) -> Vec < Attribute > {
92- attrs
93- . iter ( )
94- . filter ( |attr| path_compare_str ( attr. meta . path ( ) , & [ "cfg" ] ) )
95- . cloned ( )
96- . collect ( )
97- }
98-
99- /// Iterate the attributes of the method to extract Doc attributes (doc comments are parsed as this)
100- pub fn extract_docs ( attrs : & [ Attribute ] ) -> Vec < Attribute > {
101- attrs
102- . iter ( )
103- . filter ( |attr| path_compare_str ( attr. meta . path ( ) , & [ "doc" ] ) )
104- . cloned ( )
105- . collect ( )
106- }
107-
10889/// Splits a path by :: separators e.g. "cxx_qt::bridge" becomes ["cxx_qt", "bridge"]
10990fn split_path ( path_str : & str ) -> Vec < & str > {
11091 let path = if path_str. contains ( "::" ) {
@@ -115,32 +96,6 @@ fn split_path(path_str: &str) -> Vec<&str> {
11596 path
11697}
11798
118- /// Collects a Map of all attributes found from the allowed list
119- /// Will error if an attribute which is not in the allowed list is found
120- pub fn require_attributes < ' a > (
121- attrs : & ' a [ Attribute ] ,
122- allowed : & ' a [ & str ] ,
123- ) -> Result < BTreeMap < & ' a str , & ' a Attribute > > {
124- let mut output = BTreeMap :: default ( ) ;
125- for attr in attrs {
126- let index = allowed
127- . iter ( )
128- . position ( |string| path_compare_str ( attr. meta . path ( ) , & split_path ( string) ) ) ;
129- if let Some ( index) = index {
130- output. insert ( allowed[ index] , attr) ; // Doesn't error on duplicates
131- } else {
132- return Err ( Error :: new (
133- attr. span ( ) ,
134- format ! (
135- "Unsupported attribute! The only attributes allowed on this item are\n {}" ,
136- allowed. join( ", " )
137- ) ,
138- ) ) ;
139- }
140- }
141- Ok ( output)
142- }
143-
14499// Extract base identifier from attribute
145100pub fn parse_base_type ( attributes : & BTreeMap < & str , & Attribute > ) -> Result < Option < Ident > > {
146101 attributes
@@ -174,7 +129,7 @@ impl PassthroughMod {
174129
175130 Self {
176131 items,
177- docs : extract_docs ( & module. attrs ) ,
132+ docs : attribute :: extract_docs ( & module. attrs ) ,
178133 module_ident : module. ident ,
179134 vis : module. vis ,
180135 }
@@ -196,7 +151,7 @@ pub struct Parser {
196151
197152impl Parser {
198153 fn parse_mod_attributes ( module : & mut ItemMod ) -> Result < Option < String > > {
199- let attrs = require_attributes ( & module. attrs , & [ "doc" , "cxx_qt::bridge" ] ) ?;
154+ let attrs = ParsedAttribute :: require_attributes ( & module. attrs , & [ "doc" , "cxx_qt::bridge" ] ) ?;
200155 let mut namespace = None ;
201156
202157 // Check for the cxx_qt::bridge attribute
0 commit comments