/tools/fbusgen/coder.h

http://ftk.googlecode.com/ · C Header · 172 lines · 118 code · 25 blank · 29 comment · 24 complexity · 8201d1886283a669da01ed1f590bc06c MD5 · raw file

  1. /*
  2. * File: coder.h
  3. * Author: Li XianJing <xianjimli@hotmail.com>
  4. * Brief: interface for code generator.
  5. *
  6. * Copyright (c) 2009 - 2010 Li XianJing <xianjimli@hotmail.com>
  7. *
  8. * Licensed under the Academic Free License version 2.1
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. /*
  25. * History:
  26. * ================================================================
  27. * 2010-07-31 Li XianJing <xianjimli@hotmail.com> created
  28. *
  29. */
  30. #ifndef CODER_H
  31. #define CODER_H
  32. #include "glib.h"
  33. #include <stdio.h>
  34. #include <sys/stat.h>
  35. #include <sys/types.h>
  36. #include <ctype.h>
  37. #include <assert.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <libIDL/IDL.h>
  41. struct _Coder;
  42. typedef struct _Coder Coder;
  43. typedef gboolean (*CoderOnInterface)(Coder* thiz, const char* name, const char* parent);
  44. typedef gboolean (*CoderOnFunction)(Coder* thiz, struct _IDL_OP_DCL f);
  45. typedef gboolean (*CoderOnConst)(Coder* thiz, struct _IDL_CONST_DCL c);
  46. typedef gboolean (*CoderOnStruct)(Coder* thiz, struct _IDL_TYPE_STRUCT s);
  47. typedef gboolean (*CoderOnEnum)(Coder* thiz, struct _IDL_TYPE_ENUM e);
  48. typedef gboolean (*CoderOnUnion)(Coder* thiz, struct _IDL_TYPE_UNION u);
  49. typedef void (*CoderDestroy)(Coder* thiz);
  50. struct _Coder
  51. {
  52. CoderOnInterface on_interface;
  53. CoderOnFunction on_function;
  54. CoderOnStruct on_struct;
  55. CoderOnConst on_const;
  56. CoderOnUnion on_union;
  57. CoderOnEnum on_enum;
  58. CoderDestroy destroy;
  59. char priv[1];
  60. };
  61. static inline gboolean coder_on_interface(Coder* thiz, const char* name, const char* parent)
  62. {
  63. g_return_val_if_fail(thiz != NULL && name != NULL, FALSE);
  64. if(thiz->on_interface != NULL)
  65. {
  66. return thiz->on_interface(thiz, name, parent);
  67. }
  68. else
  69. {
  70. return FALSE;
  71. }
  72. }
  73. static inline gboolean coder_on_function(Coder* thiz, struct _IDL_OP_DCL f)
  74. {
  75. g_return_val_if_fail(thiz != NULL, FALSE);
  76. if(thiz->on_function != NULL)
  77. {
  78. return thiz->on_function(thiz, f);
  79. }
  80. else
  81. {
  82. return FALSE;
  83. }
  84. }
  85. static inline gboolean coder_on_const(Coder* thiz, struct _IDL_CONST_DCL c)
  86. {
  87. g_return_val_if_fail(thiz != NULL, FALSE);
  88. if(thiz->on_const != NULL)
  89. {
  90. return thiz->on_const(thiz, c);
  91. }
  92. else
  93. {
  94. return FALSE;
  95. }
  96. }
  97. static inline gboolean coder_on_struct(Coder* thiz, struct _IDL_TYPE_STRUCT s)
  98. {
  99. g_return_val_if_fail(thiz != NULL, FALSE);
  100. if(thiz->on_struct != NULL)
  101. {
  102. return thiz->on_struct(thiz, s);
  103. }
  104. else
  105. {
  106. return FALSE;
  107. }
  108. }
  109. static inline gboolean coder_on_enum(Coder* thiz, struct _IDL_TYPE_ENUM e)
  110. {
  111. g_return_val_if_fail(thiz != NULL, FALSE);
  112. if(thiz->on_enum != NULL)
  113. {
  114. return thiz->on_enum(thiz, e);
  115. }
  116. else
  117. {
  118. return FALSE;
  119. }
  120. }
  121. static inline gboolean coder_on_union(Coder* thiz, struct _IDL_TYPE_UNION u)
  122. {
  123. g_return_val_if_fail(thiz != NULL, FALSE);
  124. if(thiz->on_union != NULL)
  125. {
  126. return thiz->on_union(thiz, u);
  127. }
  128. else
  129. {
  130. return FALSE;
  131. }
  132. }
  133. static inline void coder_destroy(Coder* thiz)
  134. {
  135. if(thiz != NULL && thiz->destroy != NULL)
  136. {
  137. thiz->destroy(thiz);
  138. }
  139. return;
  140. }
  141. typedef Coder* (*CoderCreate)(const char* name);
  142. char* coder_name_to_upper(const char* src, char* dst, int skip);
  143. char* coder_name_to_lower(const char* src, char* dst);
  144. const char* coder_to_upper(char* src);
  145. const char* coder_to_lower(char* src);
  146. void coder_write_header(FILE* fp);
  147. #endif/*CODER_H*/