Macro *glsl_macro_construct_undef(Token *name)
{
   Macro *macro = macro_alloc();
   
   macro->type = MACRO_UNDEF;
   macro->name = name;

   return macro;
}
Ejemplo n.º 2
0
struct macro *
macro_new_reference(void)
{
	struct macro *m = macro_alloc();
	m->next = 0;
	m->type = MACRO_REFERENCE;
	m->reference = 0;
	return m;
}
Ejemplo n.º 3
0
struct macro *
macro_new_str(struct str *str)
{
	struct macro *m = macro_alloc();
	m->next = 0;
	m->type = MACRO_STR;
	m->str = str;
	return m;
}
Ejemplo n.º 4
0
struct macro *
macro_new_atom(const char *atom)
{
	struct macro *m = macro_alloc();
	m->next = 0;
	m->type = MACRO_ATOM;
	m->atom = atom;
	return m;
}
Macro *glsl_macro_construct_function(Token *name, TokenList *args, TokenSeq *body)
{
   Macro *macro = macro_alloc();
   
   macro->type = MACRO_FUNCTION;
   macro->name = name;
   macro->args = args;
   macro->body = body;

   return macro;
}
Macro *glsl_macro_construct_object(Token *name, TokenSeq *body)
{
   Macro *macro = macro_alloc();
   
   macro->type = MACRO_OBJECT;
   macro->name = name;
   macro->args = NULL;
   macro->body = body;

   return macro;
}
Ejemplo n.º 7
0
/* Construct a definition for a macro in table T.  Cache all strings,
   and the macro_definition structure itself, in T's bcache.  */
static struct macro_definition *
new_macro_definition (struct macro_table *t,
                      enum macro_kind kind,
                      int argc, const char **argv,
                      const char *replacement)
{
  struct macro_definition *d
    = (struct macro_definition *) macro_alloc (sizeof (*d), t);

  memset (d, 0, sizeof (*d));
  d->table = t;
  d->kind = kind;
  d->replacement = macro_bcache_str (t, replacement);
  d->argc = argc;

  if (kind == macro_function_like)
    {
      int i;
      const char **cached_argv;
      int cached_argv_size = argc * sizeof (*cached_argv);

      /* Bcache all the arguments.  */
      cached_argv = (const char **) alloca (cached_argv_size);
      for (i = 0; i < argc; i++)
        cached_argv[i] = macro_bcache_str (t, argv[i]);

      /* Now bcache the array of argument pointers itself.  */
      d->argv = ((const char * const *)
		 macro_bcache (t, cached_argv, cached_argv_size));
    }

  /* We don't bcache the entire definition structure because it's got
     a pointer to the macro table in it; since each compilation unit
     has its own macro table, you'd only get bcache hits for identical
     definitions within a compilation unit, which seems unlikely.

     "So, why do macro definitions have pointers to their macro tables
     at all?"  Well, when the splay tree library wants to free a
     node's value, it calls the value freeing function with nothing
     but the value itself.  It makes the (apparently reasonable)
     assumption that the value carries enough information to free
     itself.  But not all macro tables have bcaches, so not all macro
     definitions would be bcached.  There's no way to tell whether a
     given definition is bcached without knowing which table the
     definition belongs to.  ...  blah.  The thing's only sixteen
     bytes anyway, and we can still bcache the name, args, and
     definition, so we just don't bother bcaching the definition
     structure itself.  */
  return d;
}
Ejemplo n.º 8
0
/* Allocate and initialize a new source file structure.  */
static struct macro_source_file *
new_source_file (struct macro_table *t,
                 const char *filename)
{
  /* Get space for the source file structure itself.  */
  struct macro_source_file *f = macro_alloc (sizeof (*f), t);

  memset (f, 0, sizeof (*f));
  f->table = t;
  f->filename = macro_bcache_str (t, filename);
  f->includes = 0;

  return f;
}
static Macro *glsl_macro_construct_builtin(MacroType type, char *s)
{
   Macro *macro = macro_alloc();

   TokenData data;

   data.s = s;

   macro->type = type;
   macro->name = glsl_token_construct(IDENTIFIER, data);
   macro->args = NULL;
   macro->body = NULL;

   return macro;
}
Ejemplo n.º 10
0
/* Construct a new macro key node for a macro in table T whose name is
   NAME, and whose scope starts at LINE in FILE; register the name in
   the bcache.  */
static struct macro_key *
new_macro_key (struct macro_table *t,
               const char *name,
               struct macro_source_file *file,
               int line)
{
  struct macro_key *k = (struct macro_key *) macro_alloc (sizeof (*k), t);

  memset (k, 0, sizeof (*k));
  k->table = t;
  k->name = macro_bcache_str (t, name);
  k->start_file = file;
  k->start_line = line;
  k->end_file = 0;

  return k;
}