diff options
author | Minijackson <minijackson@riseup.net> | 2019-11-23 19:27:21 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2019-11-23 19:31:58 +0100 |
commit | 860b73f1644ecd6548ae403ec483625fb7b625ea (patch) | |
tree | 1e0ab5ecf2a77a66e2a176364ecb151a58468426 /src/parsing.rs | |
parent | 304d9f220cc208dd78fce11b703354ecd8d2168c (diff) | |
download | poseidoc-860b73f1644ecd6548ae403ec483625fb7b625ea.tar.gz poseidoc-860b73f1644ecd6548ae403ec483625fb7b625ea.zip |
entities rework, allow "inline" documentation, merge config with cli
Diffstat (limited to 'src/parsing.rs')
-rw-r--r-- | src/parsing.rs | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/src/parsing.rs b/src/parsing.rs index 137b89d..d7aaa49 100644 --- a/src/parsing.rs +++ b/src/parsing.rs | |||
@@ -6,11 +6,13 @@ use codemap::CodeMap; | |||
6 | use std::collections::HashMap; | 6 | use std::collections::HashMap; |
7 | use std::path::{Path, PathBuf}; | 7 | use std::path::{Path, PathBuf}; |
8 | 8 | ||
9 | pub(crate) fn parse_file<T>(path: T, mut extra_args: Vec<&str>) -> EntitiesManager | 9 | pub(crate) fn parse_file<T, S>(path: T, extra_args: &[S]) -> EntitiesManager |
10 | where | 10 | where |
11 | T: Into<PathBuf>, | 11 | T: Into<PathBuf>, |
12 | T: AsRef<Path>, | 12 | T: AsRef<Path>, |
13 | T: ToString, | 13 | T: ToString, |
14 | S: AsRef<str>, | ||
15 | S: std::fmt::Debug, | ||
14 | { | 16 | { |
15 | let mut codemap = CodeMap::new(); | 17 | let mut codemap = CodeMap::new(); |
16 | let file_map = codemap.add_file(path.to_string(), std::fs::read_to_string(&path).unwrap()); | 18 | let file_map = codemap.add_file(path.to_string(), std::fs::read_to_string(&path).unwrap()); |
@@ -21,7 +23,6 @@ where | |||
21 | let mut parser = index.parser(path); | 23 | let mut parser = index.parser(path); |
22 | parser.skip_function_bodies(true); | 24 | parser.skip_function_bodies(true); |
23 | 25 | ||
24 | extra_args.push("-Werror=documentation"); | ||
25 | parser.arguments(&extra_args); | 26 | parser.arguments(&extra_args); |
26 | 27 | ||
27 | if log_enabled!(log::Level::Debug) { | 28 | if log_enabled!(log::Level::Debug) { |
@@ -70,7 +71,7 @@ where | |||
70 | let mut emitter = Emitter::stderr(ColorConfig::Auto, Some(&codemap)); | 71 | let mut emitter = Emitter::stderr(ColorConfig::Auto, Some(&codemap)); |
71 | 72 | ||
72 | for diagnostic in trans_unit.get_diagnostics().iter() { | 73 | for diagnostic in trans_unit.get_diagnostics().iter() { |
73 | let main_diag = match clang_diag_to_codemap_diag(&diagnostic, &file_span) { | 74 | let main_diag = match clang_diag_to_codemap_diag(&diagnostic, file_span) { |
74 | Some(diag) => diag, | 75 | Some(diag) => diag, |
75 | None => continue, | 76 | None => continue, |
76 | }; | 77 | }; |
@@ -78,12 +79,12 @@ where | |||
78 | let sub_diags = diagnostic | 79 | let sub_diags = diagnostic |
79 | .get_children() | 80 | .get_children() |
80 | .into_iter() | 81 | .into_iter() |
81 | .filter_map(|diagnostic| clang_diag_to_codemap_diag(&diagnostic, &file_span)); | 82 | .filter_map(|diagnostic| clang_diag_to_codemap_diag(&diagnostic, file_span)); |
82 | 83 | ||
83 | let fix_it_diags = diagnostic | 84 | let fix_it_diags = diagnostic |
84 | .get_fix_its() | 85 | .get_fix_its() |
85 | .into_iter() | 86 | .into_iter() |
86 | .map(|fix_it| clang_fix_it_to_codemap_diag(&fix_it, &file_span)); | 87 | .map(|fix_it| clang_fix_it_to_codemap_diag(&fix_it, file_span)); |
87 | 88 | ||
88 | emitter.emit( | 89 | emitter.emit( |
89 | &std::iter::once(main_diag) | 90 | &std::iter::once(main_diag) |
@@ -98,7 +99,7 @@ where | |||
98 | 99 | ||
99 | fn clang_diag_to_codemap_diag( | 100 | fn clang_diag_to_codemap_diag( |
100 | diagnostic: &clang::diagnostic::Diagnostic, | 101 | diagnostic: &clang::diagnostic::Diagnostic, |
101 | file_span: &codemap::Span, | 102 | file_span: codemap::Span, |
102 | ) -> Option<codemap_diagnostic::Diagnostic> { | 103 | ) -> Option<codemap_diagnostic::Diagnostic> { |
103 | use codemap_diagnostic::{Diagnostic, Level, SpanLabel, SpanStyle}; | 104 | use codemap_diagnostic::{Diagnostic, Level, SpanLabel, SpanStyle}; |
104 | 105 | ||
@@ -146,7 +147,7 @@ fn clang_diag_to_codemap_diag( | |||
146 | 147 | ||
147 | fn clang_fix_it_to_codemap_diag( | 148 | fn clang_fix_it_to_codemap_diag( |
148 | fix_it: &clang::diagnostic::FixIt, | 149 | fix_it: &clang::diagnostic::FixIt, |
149 | file_span: &codemap::Span, | 150 | file_span: codemap::Span, |
150 | ) -> codemap_diagnostic::Diagnostic { | 151 | ) -> codemap_diagnostic::Diagnostic { |
151 | use clang::diagnostic::FixIt; | 152 | use clang::diagnostic::FixIt; |
152 | use codemap_diagnostic::{Diagnostic, Level, SpanLabel, SpanStyle}; | 153 | use codemap_diagnostic::{Diagnostic, Level, SpanLabel, SpanStyle}; |
@@ -195,6 +196,7 @@ fn clang_fix_it_to_codemap_diag( | |||
195 | pub(crate) struct Comment(String); | 196 | pub(crate) struct Comment(String); |
196 | 197 | ||
197 | impl Comment { | 198 | impl Comment { |
199 | // TODO: weirdness with emojis and line returns? | ||
198 | pub fn from_raw(raw: String) -> Self { | 200 | pub fn from_raw(raw: String) -> Self { |
199 | #[derive(Debug)] | 201 | #[derive(Debug)] |
200 | enum CommentStyle { | 202 | enum CommentStyle { |
@@ -237,7 +239,7 @@ impl Comment { | |||
237 | break; | 239 | break; |
238 | } | 240 | } |
239 | Some(position) => { | 241 | Some(position) => { |
240 | result.push_str(&rest[..position + 1]); | 242 | result.push_str(&rest[..=position]); |
241 | chars.nth(position); | 243 | chars.nth(position); |
242 | } | 244 | } |
243 | } | 245 | } |
@@ -318,20 +320,20 @@ fn get_description(entity: &clang::Entity) -> Description { | |||
318 | } | 320 | } |
319 | } | 321 | } |
320 | 322 | ||
321 | impl FromClangEntity for Entity { | 323 | impl FromClangEntity for Box<DynEntity> { |
322 | fn from_clang_entity(entity: clang::Entity, manager: &mut EntitiesManager) -> Self { | 324 | fn from_clang_entity(entity: clang::Entity, manager: &mut EntitiesManager) -> Self { |
323 | use clang::EntityKind; | 325 | use clang::EntityKind; |
324 | 326 | ||
325 | match entity.get_kind() { | 327 | match entity.get_kind() { |
326 | EntityKind::Namespace => Self::NameSpace(entity.into_poseidoc_entity(manager)), | 328 | EntityKind::Namespace => Box::new(NameSpace::from_clang_entity(entity, manager)), |
327 | EntityKind::FieldDecl | EntityKind::VarDecl => { | 329 | EntityKind::FieldDecl | EntityKind::VarDecl => { |
328 | Self::Variable(entity.into_poseidoc_entity(manager)) | 330 | Box::new(Variable::from_clang_entity(entity, manager)) |
329 | } | 331 | } |
330 | EntityKind::FunctionDecl | EntityKind::Method | EntityKind::FunctionTemplate => { | 332 | EntityKind::FunctionDecl | EntityKind::Method | EntityKind::FunctionTemplate => { |
331 | Self::Function(entity.into_poseidoc_entity(manager)) | 333 | Box::new(Function::from_clang_entity(entity, manager)) |
332 | } | 334 | } |
333 | EntityKind::ClassDecl | EntityKind::StructDecl | EntityKind::ClassTemplate => { | 335 | EntityKind::ClassDecl | EntityKind::StructDecl | EntityKind::ClassTemplate => { |
334 | Self::Class(entity.into_poseidoc_entity(manager)) | 336 | Box::new(Class::from_clang_entity(entity, manager)) |
335 | } | 337 | } |
336 | _ => panic!("Unsupported entity: {:?}", entity), | 338 | _ => panic!("Unsupported entity: {:?}", entity), |
337 | } | 339 | } |
@@ -362,6 +364,28 @@ impl FromClangEntity for NameSpace { | |||
362 | } | 364 | } |
363 | } | 365 | } |
364 | 366 | ||
367 | impl FromClangEntity for NameSpaceChild { | ||
368 | fn from_clang_entity(entity: clang::Entity, manager: &mut EntitiesManager) -> Self { | ||
369 | use clang::EntityKind; | ||
370 | |||
371 | match entity.get_kind() { | ||
372 | EntityKind::Namespace => { | ||
373 | NameSpaceChild::NameSpace(NameSpace::from_clang_entity(entity, manager)) | ||
374 | } | ||
375 | EntityKind::FieldDecl | EntityKind::VarDecl => { | ||
376 | NameSpaceChild::Variable(Variable::from_clang_entity(entity, manager)) | ||
377 | } | ||
378 | EntityKind::FunctionDecl | EntityKind::Method | EntityKind::FunctionTemplate => { | ||
379 | NameSpaceChild::Function(Function::from_clang_entity(entity, manager)) | ||
380 | } | ||
381 | EntityKind::ClassDecl | EntityKind::StructDecl | EntityKind::ClassTemplate => { | ||
382 | NameSpaceChild::Class(Class::from_clang_entity(entity, manager)) | ||
383 | } | ||
384 | _ => panic!("Unsupported entity: {:?}", entity), | ||
385 | } | ||
386 | } | ||
387 | } | ||
388 | |||
365 | impl FromClangEntity for Variable { | 389 | impl FromClangEntity for Variable { |
366 | fn from_clang_entity(entity: clang::Entity, manager: &mut EntitiesManager) -> Self { | 390 | fn from_clang_entity(entity: clang::Entity, manager: &mut EntitiesManager) -> Self { |
367 | match entity.get_kind() { | 391 | match entity.get_kind() { |
@@ -383,6 +407,7 @@ impl FromClangEntity for Function { | |||
383 | fn from_clang_entity(entity: clang::Entity, manager: &mut EntitiesManager) -> Self { | 407 | fn from_clang_entity(entity: clang::Entity, manager: &mut EntitiesManager) -> Self { |
384 | match entity.get_kind() { | 408 | match entity.get_kind() { |
385 | clang::EntityKind::Method | 409 | clang::EntityKind::Method |
410 | | clang::EntityKind::Constructor | ||
386 | | clang::EntityKind::FunctionDecl | 411 | | clang::EntityKind::FunctionDecl |
387 | | clang::EntityKind::FunctionTemplate => {} | 412 | | clang::EntityKind::FunctionTemplate => {} |
388 | _ => panic!("Trying to parse a non-function into a function"), | 413 | _ => panic!("Trying to parse a non-function into a function"), |
@@ -436,7 +461,7 @@ impl FromClangEntity for Class { | |||
436 | EntityKind::ClassDecl | EntityKind::StructDecl | EntityKind::TypeAliasDecl => { | 461 | EntityKind::ClassDecl | EntityKind::StructDecl | EntityKind::TypeAliasDecl => { |
437 | member_types.push(child_usr); | 462 | member_types.push(child_usr); |
438 | } | 463 | } |
439 | EntityKind::Method => { | 464 | EntityKind::Method | EntityKind::Constructor | EntityKind::FunctionDecl => { |
440 | member_functions.insert(child_usr, child.into_poseidoc_entity(manager)); | 465 | member_functions.insert(child_usr, child.into_poseidoc_entity(manager)); |
441 | } | 466 | } |
442 | EntityKind::FieldDecl => { | 467 | EntityKind::FieldDecl => { |
@@ -449,7 +474,7 @@ impl FromClangEntity for Class { | |||
449 | manager.insert(entity.get_usr().unwrap().into(), get_description(&entity)); | 474 | manager.insert(entity.get_usr().unwrap().into(), get_description(&entity)); |
450 | 475 | ||
451 | Class { | 476 | Class { |
452 | member_types, | 477 | //member_types, |
453 | member_functions, | 478 | member_functions, |
454 | member_variables, | 479 | member_variables, |
455 | } | 480 | } |