1- use std:: collections:: HashMap ;
1+ use std:: { collections:: HashMap , sync :: Arc } ;
22
33use clang:: { Entity , EntityKind } ;
44
5- use crate :: url:: UrlPath ;
5+ use crate :: { config :: Config , url:: UrlPath } ;
66
77use super :: {
8- traits:: { ASTEntry , BuildResult , EntityMethods , Entry , NavItem } ,
98 builder:: Builder ,
109 class:: Class ,
1110 function:: Function ,
1211 struct_:: Struct ,
12+ traits:: { ASTEntry , BuildResult , EntityMethods , Entry , NavItem } ,
1313} ;
1414
1515pub enum CppItemKind {
@@ -23,7 +23,9 @@ impl CppItemKind {
2323 pub fn from ( entity : & Entity ) -> Option < Self > {
2424 match entity. get_kind ( ) {
2525 EntityKind :: StructDecl => Some ( Self :: Struct ) ,
26- EntityKind :: ClassDecl | EntityKind :: ClassTemplate | EntityKind :: ClassTemplatePartialSpecialization => Some ( Self :: Class ) ,
26+ EntityKind :: ClassDecl
27+ | EntityKind :: ClassTemplate
28+ | EntityKind :: ClassTemplatePartialSpecialization => Some ( Self :: Class ) ,
2729 EntityKind :: FunctionDecl | EntityKind :: FunctionTemplate => Some ( Self :: Function ) ,
2830 EntityKind :: Namespace => Some ( Self :: Namespace ) ,
2931 _ => None ,
@@ -48,7 +50,11 @@ pub enum CppItem<'e> {
4850}
4951
5052impl < ' e > CppItem < ' e > {
51- fn get ( & ' e self , matcher : & dyn Fn ( & dyn ASTEntry < ' e > ) -> bool , out : & mut Vec < & ' e dyn ASTEntry < ' e > > ) {
53+ fn get (
54+ & ' e self ,
55+ matcher : & dyn Fn ( & dyn ASTEntry < ' e > ) -> bool ,
56+ out : & mut Vec < & ' e dyn ASTEntry < ' e > > ,
57+ ) {
5258 match self {
5359 CppItem :: Namespace ( ns) => {
5460 if matcher ( ns) {
@@ -57,22 +63,22 @@ impl<'e> CppItem<'e> {
5763 for entry in ns. entries . values ( ) {
5864 entry. get ( & matcher, out) ;
5965 }
60- } ,
66+ }
6167 CppItem :: Class ( cls) => {
6268 if matcher ( cls) {
6369 out. push ( cls) ;
6470 }
65- } ,
71+ }
6672 CppItem :: Struct ( cls) => {
6773 if matcher ( cls) {
6874 out. push ( cls) ;
6975 }
70- } ,
76+ }
7177 CppItem :: Function ( fun) => {
7278 if matcher ( fun) {
7379 out. push ( fun) ;
7480 }
75- } ,
81+ }
7682 }
7783 }
7884}
@@ -142,35 +148,50 @@ pub struct Namespace<'e> {
142148}
143149
144150impl < ' e > Namespace < ' e > {
145- pub fn new ( entity : Entity < ' e > ) -> Self {
151+ pub fn new ( entity : Entity < ' e > , config : Arc < Config > ) -> Self {
146152 let mut ret = Self {
147153 entity,
148154 is_root : false ,
149155 entries : HashMap :: new ( ) ,
150156 } ;
151- ret. load_entries ( ) ;
157+ ret. load_entries ( config ) ;
152158 ret
153159 }
154160
155- pub fn new_root ( entity : Entity < ' e > ) -> Self {
161+ pub fn new_root ( entity : Entity < ' e > , config : Arc < Config > ) -> Self {
156162 let mut ret = Self {
157163 entity,
158164 is_root : true ,
159165 entries : HashMap :: new ( ) ,
160166 } ;
161- ret. load_entries ( ) ;
167+ ret. load_entries ( config ) ;
162168 ret
163169 }
164170
165- fn load_entries ( & mut self ) {
171+ fn load_entries ( & mut self , config : Arc < Config > ) {
166172 for child in & self . entity . get_children ( ) {
167- if child. is_in_system_header ( ) || child. get_name ( ) . is_none ( ) {
173+ // skip unnamed items
174+ if child. get_name ( ) . is_none ( ) {
168175 continue ;
169176 }
177+
178+ // skip stuff from external headers
179+ if child. is_in_system_header ( ) && child. get_allowed_external_lib ( config. clone ( ) ) . is_none ( ) {
180+ continue ;
181+ }
182+
183+ // skips specialization of std stuff
184+ let is_parent_std = child
185+ . get_semantic_parent ( )
186+ . map_or ( false , |f| f. get_name ( ) . as_deref ( ) == Some ( "std" ) ) ;
187+ if is_parent_std {
188+ continue ;
189+ }
190+
170191 if let Some ( kind) = CppItemKind :: from ( child) {
171192 match kind {
172193 CppItemKind :: Namespace => {
173- let entry = Namespace :: new ( * child) ;
194+ let entry = Namespace :: new ( * child, config . clone ( ) ) ;
174195 // Merge existing entries of namespace
175196 if let Some ( key) = self . entries . get_mut ( & entry. name ( ) ) {
176197 if let CppItem :: Namespace ( ns) = key {
@@ -206,7 +227,7 @@ impl<'e> Namespace<'e> {
206227 }
207228 }
208229
209- // so apparently if you make this a <M: Fn(&dyn ASTEntry<'e>) -> bool>
230+ // so apparently if you make this a <M: Fn(&dyn ASTEntry<'e>) -> bool>
210231 // rustc crashes
211232 pub fn get ( & ' e self , matcher : & dyn Fn ( & dyn ASTEntry < ' e > ) -> bool ) -> Vec < & ' e dyn ASTEntry < ' e > > {
212233 let mut res = Vec :: new ( ) ;
@@ -252,9 +273,10 @@ impl<'e> Entry<'e> for Namespace<'e> {
252273 fn url ( & self ) -> UrlPath {
253274 if self . is_root {
254275 UrlPath :: new ( )
255- }
256- else {
257- self . entity . rel_docs_url ( ) . expect ( "Unable to get namespace URL" )
276+ } else {
277+ self . entity
278+ . rel_docs_url ( )
279+ . expect ( "Unable to get namespace URL" )
258280 }
259281 }
260282}
0 commit comments