Commit f00a02f2 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

ident: Cleanup.

parent fb45ad91
......@@ -8,17 +8,12 @@
* @brief Hash table to store names.
* @author Goetz Lindenmaier
*/
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include "hashptr.h"
#include "ident_t.h"
#include "set.h"
#include "xmalloc.h"
#include "hashptr.h"
static set *id_set;
......@@ -37,7 +32,6 @@ ident *new_id_from_chars(const char *str, size_t len)
ident *new_id_from_str(const char *str)
{
assert(str != NULL);
return new_id_from_chars(str, strlen(str));
}
......
......@@ -8,27 +8,12 @@
* @brief Methods to manipulate names.
* @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
*/
#include <stdio.h>
#include "ident_t.h"
#include "obst.h"
/* Make types visible to allow most efficient access */
#include "entity_t.h"
#include "type_t.h"
#include "tpop_t.h"
/** An obstack used for temporary space */
static struct obstack mangle_obst;
static void obstack_grow_ident(struct obstack *obst, ident *id)
{
const char *c = get_id_str(id);
for ( ; *c != '\0'; ++c) {
obstack_1grow(obst, *c);
}
}
static ident *new_ident_from_obst(struct obstack *obst)
{
size_t len = obstack_object_size(obst);
......@@ -38,12 +23,17 @@ static ident *new_ident_from_obst(struct obstack *obst)
return res;
}
static void grow_string(char const *const s)
{
obstack_grow(&mangle_obst, s, strlen(s));
}
/** Returns a new ident that represents 'prefixscndsuffix'. */
ident *id_mangle3(const char *prefix, ident *scnd, const char *suffix)
ident *id_mangle3(char const *const prefix, ident *const middle, char const *const suffix)
{
obstack_grow(&mangle_obst, prefix, strlen(prefix));
obstack_grow_ident(&mangle_obst, scnd);
obstack_grow(&mangle_obst, suffix, strlen(suffix));
grow_string(prefix);
grow_string(get_id_str(middle));
grow_string(suffix);
return new_ident_from_obst(&mangle_obst);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment