sphophi decorating with types
This commit is contained in:
parent
17be15d7b5
commit
a22c9726cd
19 changed files with 1762 additions and 380 deletions
|
@ -9,13 +9,18 @@
|
|||
|
||||
static void spho_nom_term(struct spho_nom *);
|
||||
|
||||
static int spho_scope_nom_get_norec(struct spho_scope *, const char *, size_t ,
|
||||
struct spho_nom **);
|
||||
|
||||
int
|
||||
spho_scope_init(struct spho_scope *sc, struct spho_ctx *ctx,
|
||||
struct spho_scope *p)
|
||||
{
|
||||
SLIST_INIT(&sc->subs);
|
||||
SLIST_INIT(&sc->noms);
|
||||
TAILQ_INIT(&sc->tps);
|
||||
|
||||
sc->ctx = ctx;
|
||||
sc->parent = p;
|
||||
|
||||
return (0);
|
||||
|
@ -70,7 +75,6 @@ spho_nom_term(struct spho_nom *nom)
|
|||
void
|
||||
spho_scope_destroy(struct spho_scope *sc)
|
||||
{
|
||||
struct spho_scope *sub;
|
||||
struct spho_scope *p;
|
||||
|
||||
p = sc->parent;
|
||||
|
@ -90,12 +94,13 @@ spho_scope_nom_add(struct spho_scope *sc, const char *nomstr, size_t sz)
|
|||
#endif
|
||||
struct spho_nom *nom;
|
||||
|
||||
nom = NULL;
|
||||
|
||||
if (spho_scope_nom_get(sc, nomstr, sz, &nom) == -1)
|
||||
if (spho_scope_nom_get_norec(sc, nomstr, sz, &nom) == -1)
|
||||
return (NULL);
|
||||
|
||||
if (nom != NULL) {
|
||||
SPHO_SC_ERR(sc, SPHO_ERR_NAMEINUSE);
|
||||
SPHO_SC_ERR(sc, SPHO_ERR_NOM_INUSE);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
@ -144,7 +149,50 @@ spho_scope_nom_get(struct spho_scope *sc, const char *nomstr, size_t sz,
|
|||
return (-1);
|
||||
}
|
||||
|
||||
out = NULL;
|
||||
*out = NULL;
|
||||
while (*out == NULL && sc != NULL) {
|
||||
SLIST_FOREACH(nom, &sc->noms, next) {
|
||||
if (strncmp(nom->s, nomstr, sz) == 0) {
|
||||
*out = nom;
|
||||
break;
|
||||
}
|
||||
}
|
||||
sc = sc->parent;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
spho_scope_nom_lookup(struct spho_scope *sc, const char *nomstr, size_t sz,
|
||||
struct spho_nom **out)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (spho_scope_nom_get(sc, nomstr, sz, out) == -1)
|
||||
return (-1);
|
||||
|
||||
if (*out == NULL) {
|
||||
SPHO_SC_ERR(sc, SPHO_ERR_NOM_NOTINSCOPE);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
static int
|
||||
spho_scope_nom_get_norec(struct spho_scope *sc, const char *nomstr, size_t sz,
|
||||
struct spho_nom **out)
|
||||
{
|
||||
struct spho_nom *nom;
|
||||
|
||||
nom = NULL;
|
||||
|
||||
if (sz > sizeof(nom->s)) {
|
||||
SPHO_ERR(sc->ctx, SPHO_ERR_TOOBIG);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
*out = NULL;
|
||||
SLIST_FOREACH(nom, &sc->noms, next) {
|
||||
if (strncmp(nom->s, nomstr, sz) == 0) {
|
||||
*out = nom;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue