1
0

decl.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2023 Lain Bailey <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include "calldata.h"
  18. #include "../util/darray.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. struct decl_param {
  23. char *name;
  24. enum call_param_type type;
  25. uint32_t flags;
  26. };
  27. static inline void decl_param_free(struct decl_param *param)
  28. {
  29. if (param->name)
  30. bfree(param->name);
  31. memset(param, 0, sizeof(struct decl_param));
  32. }
  33. struct decl_info {
  34. char *name;
  35. const char *decl_string;
  36. DARRAY(struct decl_param) params;
  37. };
  38. static inline void decl_info_free(struct decl_info *decl)
  39. {
  40. if (decl) {
  41. for (size_t i = 0; i < decl->params.num; i++)
  42. decl_param_free(decl->params.array + i);
  43. da_free(decl->params);
  44. bfree(decl->name);
  45. memset(decl, 0, sizeof(struct decl_info));
  46. }
  47. }
  48. EXPORT bool parse_decl_string(struct decl_info *decl, const char *decl_string);
  49. #ifdef __cplusplus
  50. }
  51. #endif