Skip to content

Commit

Permalink
fix function args on templated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Jul 9, 2024
1 parent d5f396d commit 136e4cc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 41 deletions.
8 changes: 4 additions & 4 deletions src/builder/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ use strfmt::strfmt;
use tokio::task::JoinHandle;

use crate::{
config::{Config},
config::Config,
html::{GenHtml, Html, process::{minify_js, minify_css, minify_html}},
url::UrlPath,
};

use super::{files::Root, namespace::{Namespace}, tutorial::TutorialFolder, traits::{OutputEntry, BuildResult, Entry}};
use super::{files::Root, namespace::Namespace, tutorial::TutorialFolder, traits::{OutputEntry, BuildResult, Entry}};

pub struct Builder<'e> {
pub config: Arc<Config>,
pub root: Namespace<'e>,
pub clang: &'e Clang,
pub _clang: &'e Clang,
pub index: &'e clang::Index<'e>,
pub args: &'e [String],
file_roots: Vec<Root>,
Expand All @@ -34,7 +34,7 @@ impl<'e> Builder<'e> {
Self {
config: config.clone(),
root: Namespace::new_root(root),
clang,
_clang: clang,
index,
args,
file_roots: Root::from_config(config.clone()),
Expand Down
10 changes: 5 additions & 5 deletions src/builder/shared.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::builder::Builder;
use super::traits::{ASTEntry, EntityMethods, Entry, get_member_functions, Include, Access};
use super::traits::{ASTEntry, Access, EntityMethods, Entry, Include};
use super::comment::JSDocComment;
use super::namespace::CppItem;
use crate::annotation::Annotations;
Expand Down Expand Up @@ -230,7 +230,7 @@ pub fn fmt_fun_decl(fun: &Entity, builder: &Builder) -> Html {
.with_child_opt(fmt_template_args(fun, builder))
.with_child(
HtmlElement::new("span").with_class("params").with_children(
fun.get_arguments()
fun.get_function_arguments()
.map(|args| {
args.iter()
.map(|arg| fmt_param(arg, builder))
Expand Down Expand Up @@ -418,7 +418,7 @@ pub fn output_classlike<'e, T: ASTEntry<'e>>(
"public_static_functions",
fmt_section(
"Public static methods",
get_member_functions(entry.entity(), Access::Public, Include::Statics)
entry.entity().get_member_functions(Access::Public, Include::Statics)
.into_iter()
.map(|e| fmt_fun_decl(&e, builder))
.collect::<Vec<_>>(),
Expand All @@ -428,7 +428,7 @@ pub fn output_classlike<'e, T: ASTEntry<'e>>(
"public_member_functions",
fmt_section(
"Public member functions",
get_member_functions(entry.entity(), Access::Public, Include::Members)
entry.entity().get_member_functions(Access::Public, Include::Members)
.into_iter()
.map(|e| fmt_fun_decl(&e, builder))
.collect::<Vec<_>>(),
Expand All @@ -439,7 +439,7 @@ pub fn output_classlike<'e, T: ASTEntry<'e>>(
"protected_member_functions",
fmt_section(
"Protected member functions",
get_member_functions(entry.entity(), Access::Protected, Include::Members)
entry.entity().get_member_functions(Access::Protected, Include::Members)
.into_iter()
.map(|e| fmt_fun_decl(&e, builder))
.collect::<Vec<_>>(),
Expand Down
76 changes: 48 additions & 28 deletions src/builder/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ pub trait EntityMethods<'e> {

/// Get the parents of this entity
fn ancestorage(&self) -> Vec<Entity<'e>>;

/// Gets all the member functions from this entity, assuming it is a class-like entity
fn get_member_functions(&self, visibility: Access, include_statics: Include) -> Vec<Entity<'e>>;

/// Gets the function arguments for this method, including templated ones
fn get_function_arguments(&self) -> Option<Vec<Entity<'e>>>;
}

impl<'e> EntityMethods<'e> for Entity<'e> {
Expand Down Expand Up @@ -141,6 +147,46 @@ impl<'e> EntityMethods<'e> for Entity<'e> {
ancestors.push(*self);
ancestors
}

fn get_member_functions(
&self,
visibility: Access,
include_statics: Include,
) -> Vec<Entity<'e>> {
self
.get_children()
.into_iter()
.filter(|child| {
(child.get_kind() == EntityKind::Method || child.get_kind() == EntityKind::FunctionTemplate)
&& match include_statics {
Include::Members => !child.is_static_method(),
Include::Statics => child.is_static_method(),
Include::All => true,
}
&& match child.get_accessibility() {
Some(Accessibility::Protected)
=> matches!(visibility, Access::All | Access::Protected),
Some(Accessibility::Public)
=> matches!(visibility, Access::All | Access::Public),
_ => false,
}
})
.collect()
}

fn get_function_arguments(&self) -> Option<Vec<Entity<'e>>> {
if !matches!(self.get_kind(), EntityKind::FunctionTemplate | EntityKind::FunctionDecl | EntityKind::Method) {
return None;
}
let mut args = vec![];
self.visit_children(|child, _| {
if child.get_kind() == EntityKind::ParmDecl {
args.push(child);
}
clang::EntityVisitResult::Continue
});
Some(args)
}
}

#[derive(Clone)]
Expand All @@ -157,7 +203,7 @@ impl SubItem {
};
match kind {
CppItemKind::Class | CppItemKind::Struct => {
get_member_functions(entity, Access::All, Include::All)
entity.get_member_functions(Access::All, Include::All)
.into_iter()
.filter_map(|e| Some(SubItem {
title: e.get_name()?,
Expand Down Expand Up @@ -336,30 +382,4 @@ pub enum Include {
All,
Members,
Statics,
}

pub fn get_member_functions<'e>(
entity: &Entity<'e>,
visibility: Access,
include_statics: Include,
) -> Vec<Entity<'e>> {
entity
.get_children()
.into_iter()
.filter(|child| {
(child.get_kind() == EntityKind::Method || child.get_kind() == EntityKind::FunctionTemplate)
&& match include_statics {
Include::Members => !child.is_static_method(),
Include::Statics => child.is_static_method(),
Include::All => true,
}
&& match child.get_accessibility() {
Some(Accessibility::Protected)
=> matches!(visibility, Access::All | Access::Protected),
Some(Accessibility::Public)
=> matches!(visibility, Access::All | Access::Public),
_ => false,
}
})
.collect()
}
}
3 changes: 0 additions & 3 deletions src/html/process.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

use std::sync::Arc;

use lightningcss::stylesheet::{ParserOptions, PrinterOptions};
// use swc::{try_with_handler, HandlerOpts, config::{JsMinifyOptions, Options}, BoolOrDataConfig};
// use swc_common::{SourceMap, GLOBALS, FileName};
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(let_chains)]
#![feature(result_option_inspect)]
#![feature(iter_advance_by)]
#![feature(iter_intersperse)]

Expand Down

0 comments on commit 136e4cc

Please sign in to comment.