rdmsr / cppdoc

C++ documentation generator
MIT License
44 stars 3 forks source link

panic on file with unnamed namespace #4

Open db48x opened 5 days ago

db48x commented 5 days ago
⠁ Parsing src/achievement.cpp                                                                                                                                                thread 'main' panicked at src/parser.rs:475:44:
called `Option::unwrap()` on a `None` value
stack backtrace:
   […]
   5: cppdoc::parser::Parser::parse_node
             at /home/db48x/src/cppdoc/src/parser.rs:475:28
   6: cppdoc::parser::Parser::parse
             at /home/db48x/src/cppdoc/src/parser.rs:577:17
   7: cppdoc::main
             at /home/db48x/src/cppdoc/src/main.rs:87:17

achievement.cpp has this near the top:

namespace
{

generic_factory<achievement> achievement_factory( "achievement" );

} // namespace

I honestly couldn’t tell you why though.

rdmsr commented 5 days ago

The problem is I don't handle unnamed/anonymous namespaces yet, this will be fixed soon.

db48x commented 5 days ago

No worries. For the moment I just did this to let it run for longer to see what it generates:

@@ -472,9 +472,9 @@ impl<'a> Parser<'a> {
             }

             clang::EntityKind::Namespace => {
-                let name = node.get_name().unwrap();
+                let name = node.get_name().unwrap_or_else(|| String::from("<anonymous namespace>"));
                 let mut real_ns = Namespace {
-                    name: node.get_name().unwrap(),
+                    name: name.clone(),
                     comment: node.get_comment().map(comment::parse_comment),
                     records: Vec::new(),
                     functions: Vec::new(),
rdmsr commented 5 days ago

Yes, this makes sense. I'm not sure how to handle anonymous namespaces yet, it should probably be done on a per-file basis.