summaryrefslogtreecommitdiff
path: root/tools/gidlcompilercontext.h
blob: 5f861a3b3f6d6b4c3c19b37fab5673e651adf2be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

#ifndef __G_IDL_COMPILER_CONTEXT_H__
#define __G_IDL_COMPILER_CONTEXT_H__

#include <stdio.h>
#include <glib.h>

#include "gidlnode.h"

typedef struct _GIdlCompilerContext GIdlCompilerContext;

struct _GIdlCompilerContext
{
  gchar *namespace_name;
  gchar *struct_name;

  gchar *mdata_struct_fn;
  FILE *mdata_struct;

  gchar *mdata_init_fn;
  FILE *mdata_init;

  guint32 string_offset;
  gchar *mdata_string_fn;
  FILE *mdata_string;
  GHashTable *strings;

  guint32 directory_local_entries;
  guint32 directory_entries;
  gchar *mdata_directory_fn;
  FILE *mdata_directory;

  /* The entriesdb contains all the
   * types that have a directory entry.
   *
   * It must be filled in before beginning to write
   * out the data. This is because it is used
   * to decide whether a type is available or
   * needs an external reference
   */
  GHashTable *entriesdb;

  /* The typesdb is used to store type names to
   * entry ids, so that multiple similar type blobs are
   * not written out
   */
  GHashTable *typesdb;

  /* Type blobs are accessed in the middle of writing another
   * entry. Writing them needs to be deferred until after
   * that entry is finished.
   */
  GList *dtypelist;

  /* Signature blobs are accessed in the middle of writing
   * other entries, and so need to be deferred.
   *
   * There is no signature node, so the function / callback
   * nodes are stored instead.
   */
  GList *dsignaturelist;

  /* Constants have values that are of a variable size,
   * and have to be written out after the entry has finished,
   * so are stored as a variant in this list until the time comes.
   */
  GList *dconstantlist;
};

GIdlCompilerContext *g_idl_compiler_context_new (const gchar * namespace,
						 GError ** err);

void
g_idl_compiler_context_finalize (GIdlCompilerContext *ctx,
				 FILE *stream,
				 const gchar *shlib,
				 GError **err);

void g_idl_compiler_context_destroy (GIdlCompilerContext * ctx);

guint32 g_idl_compiler_write_string (GIdlCompilerContext * ctx,
				     const gchar * str);

gint32 g_idl_compiler_get_unique_id (void);

void g_idl_compiler_add_entry (GIdlCompilerContext *ctx,
			       GIdlNode *node);

guint g_idl_compiler_get_entry_id (GIdlCompilerContext * ctx,
				   const gchar * name);

guint g_idl_compiler_get_entry_dirid (GIdlCompilerContext * ctx,
				      const gchar * name);

void g_idl_compiler_push_deferred_type_node (GIdlCompilerContext * ctx,
					     GIdlNode * node,
					     guint entry_id);

GIdlNode *g_idl_compiler_pop_deferred_type_node (GIdlCompilerContext * ctx,
						 guint * entry_id);

void g_idl_compiler_push_deferred_signature_node (GIdlCompilerContext * ctx,
						  GIdlNode * node,
						  guint entry_id);

GIdlNode *g_idl_compiler_pop_deferred_signature_node (GIdlCompilerContext * ctx,
						      guint * entry_id);

void g_idl_compiler_push_deferred_constant (GIdlCompilerContext * ctx,
					    GIdlNode * node,
					    guint entry_id);

GIdlNode * g_idl_compiler_pop_deferred_constant (GIdlCompilerContext * ctx,
						 guint * entry_id);

#define SECTION(sEC) "info_" #sEC
#define ID_TO_ENTRY   "entry_%d"

/* Parameters (To the string)
 * Metadata struct name
 * Offset into string buffer - Given by g_idl_compiler_write_string()
 */
#define STRING_POINTER "G_STRUCT_OFFSET(%s," SECTION(strings) ") + %d"

/* Parameters(To the string)
 * Metatada struct name
 * Type name
 */
#define TYPE_POINTER   "G_STRUCT_OFFSET(%s,"ID_TO_ENTRY")"

#endif /*__G_IDL_COMPILER_CONTEXT_H__*/