p≡p engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.1 KiB

4 years ago
4 years ago
2 years ago
2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
4 years ago
2 years ago
4 years ago
  1. // p≡p API C data types mapping
  2. // Copyleft (c) 2019, p≡p foundation
  3. // this file is under GNU General Public License 3.0
  4. // see LICENSE.txt
  5. // written by Volker Birk
  6. template "*", mode=name {
  7. param "abbr", "false()";
  8. if ".!=/*" {
  9. apply "..", 0, mode=name;
  10. if "@name!='basic' and @name != string(../@name)"
  11. > _
  12. }
  13. if "@name!='basic' and @name != string(../@name)"
  14. > «@name»
  15. }
  16. function "name" {
  17. param "abbr", "false()";
  18. apply ".", mode=name with "abbr", "$abbr";
  19. }
  20. def "func:name" {
  21. param "abbr", "false()";
  22. result call "name" with "abbr", "$abbr";
  23. }
  24. def "func:basetype" {
  25. param "type";
  26. const "definition", "//type[@name=$type]";
  27. choose {
  28. when "$definition/extends"
  29. result "func:c-type($definition/extends/@type)";
  30. otherwise
  31. result "func:c-type($type)";
  32. }
  33. }
  34. def "func:c-type" {
  35. param "dsltype";
  36. choose {
  37. // base types
  38. when "$dsltype = 'string'"
  39. result > char *
  40. when "$dsltype = 'binary'"
  41. result > char *
  42. when "$dsltype = 'int'"
  43. result > int
  44. when "$dsltype = 'unsigned'"
  45. result > unsigned int
  46. when "$dsltype = 'size_t'"
  47. result > size_t
  48. when "$dsltype = 'bool'"
  49. result > bool
  50. when "$dsltype = 'timestamp'"
  51. result > timestamp
  52. when "$dsltype = 'any'"
  53. result > void *
  54. // basic type definitions
  55. when "/package/package[@name='basic']/type[@name=$dsltype]"
  56. result > «$dsltype»
  57. when "/package/package[@name='basic']/struct[@name=$dsltype]"
  58. result > pEp_«$dsltype»
  59. when "/package/package[@name='basic']/enum[@name=$dsltype]"
  60. result > pEp_«$dsltype»
  61. // definitions in local module
  62. when "../../type[@name=$dsltype]"
  63. for "../../type[@name=$dsltype]"
  64. result > «$dsltype»
  65. when "../../struct[@name=$dsltype]"
  66. for "../../struct[@name=$dsltype]"
  67. result > «func:name()»
  68. when "../../enum[@name=$dsltype]"
  69. for "../../enum[@name=$dsltype]"
  70. result > «func:name()»
  71. // definitions in other module
  72. when "/package/package/type[@name=$dsltype]"
  73. for "/package/package/type[@name=$dsltype]" {
  74. warning value "concat('WARNING: type ', $dsltype, ' found in non-local module')";
  75. result > «$dsltype»
  76. }
  77. when "/package/package/struct[@name=$dsltype]"
  78. for "/package/package/struct[@name=$dsltype]" {
  79. warning value "concat('WARNING: type ', $dsltype, ' found in non-local module')";
  80. result > «func:name()»
  81. }
  82. when "/package/package/enum[@name=$dsltype]"
  83. for "/package/package/enum[@name=$dsltype]" {
  84. warning value "concat('WARNING: type ', $dsltype, ' found in non-local module')";
  85. result > «func:name()»
  86. }
  87. // other
  88. otherwise
  89. error value "concat('type “', $dsltype, '” not found')";
  90. }
  91. }