~taiite/protodump

29b3000acef6394a3de99557a2f48fe4e69db911 — Hubert Hirtz 1 year, 5 months ago 0e4535f
Error out on void-typed parameters

I'd be interested if you reader are reading an object with a function of
this kind:

    int my_func(void param1, void param2);

Something that is not allow in C.

This is also not possible to achieve in other languages, as far as I
have tested:

- zig defines anyopaque and void but doesn't allow any to appear as-is
  in a function signature,
- Rust defined std::ffi::c_void as an enum with two variants, and () and
  ! as a u0 with a typedef.
- C++, idk
- Pascal neither
- Fortran?
1 files changed, 19 insertions(+), 15 deletions(-)

M src/dwarf.rs
M src/dwarf.rs => src/dwarf.rs +19 -15
@@ 1,4 1,5 @@
use crate::types;
use anyhow::Context;
use anyhow::Result;
use std::collections::BTreeMap;
use std::collections::HashMap;


@@ 259,7 260,7 @@ where
                    continue;
                }

                let name = match entry_name(dwarf, &unit, entry)? {
                let sp_name = match entry_name(dwarf, &unit, entry)? {
                    Some(v) => v,
                    None => continue,
                };


@@ 267,7 268,7 @@ where
                    Some(v) => v,
                    None => continue,
                };
                let typ = entry_type(&mut type_cache, &unit, entry)?;
                let return_type = entry_type(&mut type_cache, &unit, entry)?;
                let mut parameters = Vec::new();

                let prototyped = matches!(


@@ 282,30 283,33 @@ where
                            entries.next_sibling()?;
                            continue;
                        }

                        let name = entry_name(dwarf, &unit, entry)?;
                        let type_ = entry_type(&mut type_cache, &unit, entry)?;
                        if let Some(type_) = type_ {
                            parameters.push(Parameter { name, type_ });
                        }
                        let type_ =
                            entry_type(&mut type_cache, &unit, entry)?.with_context(|| {
                                // The C calling convention does not allow
                                // zero-sized types.
                                format!(
                                    "function {:?} parameter {:?} has type \"void\"?",
                                    sp_name, name,
                                )
                            })?;
                        parameters.push(Parameter { name, type_ });

                        entries.next_sibling()?;
                    }
                }

                let parameters = if parameters.is_empty() {
                    if prototyped {
                        Some(parameters)
                    } else {
                        None
                    }
                } else {
                let parameters = if !parameters.is_empty() || prototyped {
                    Some(parameters)
                } else {
                    None
                };

                subprograms.insert(
                    name,
                    sp_name,
                    Subprogram {
                        return_type: typ,
                        return_type,
                        parameters,
                        address,
                    },