Commit a911a136 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Refactoring

parent 3bf8fc77
...@@ -433,6 +433,8 @@ void vcc_Duration(struct vcc *tl, double *); ...@@ -433,6 +433,8 @@ void vcc_Duration(struct vcc *tl, double *);
unsigned vcc_UintVal(struct vcc *tl); unsigned vcc_UintVal(struct vcc *tl);
int vcc_IsFlag(struct vcc *tl); int vcc_IsFlag(struct vcc *tl);
int vcc_IsFlagRaw(struct vcc *, const struct token *, const struct token *); int vcc_IsFlagRaw(struct vcc *, const struct token *, const struct token *);
char *vcc_Dup_be(const char *b, const char *e);
int vcc_Has_vcl_prefix(const char *b);
/* vcc_var.c */ /* vcc_var.c */
sym_wildcard_t vcc_Var_Wildcard; sym_wildcard_t vcc_Var_Wildcard;
......
...@@ -244,10 +244,7 @@ vcc_ParseFunction(struct vcc *tl) ...@@ -244,10 +244,7 @@ vcc_ParseFunction(struct vcc *tl)
p = sym->proc; p = sym->proc;
if (p == NULL) { if (p == NULL) {
if (vcc_builtin != NULL && bsym == NULL && if (vcc_builtin != NULL && bsym == NULL &&
(t->b[0] == 'v'|| t->b[0] == 'V') && vcc_Has_vcl_prefix(t->b)) {
(t->b[1] == 'c'|| t->b[1] == 'C') &&
(t->b[2] == 'l'|| t->b[2] == 'L') &&
(t->b[3] == '_')) {
VSB_printf(tl->sb,"The names 'vcl_*'" VSB_printf(tl->sb,"The names 'vcl_*'"
" are reserved for subroutines.\n"); " are reserved for subroutines.\n");
vcc_ErrWhere(tl, t); vcc_ErrWhere(tl, t);
......
...@@ -125,22 +125,6 @@ VCC_SymName(struct vsb *vsb, const struct symbol *sym) ...@@ -125,22 +125,6 @@ VCC_SymName(struct vsb *vsb, const struct symbol *sym)
vcc_symtabname(vsb, sym->symtab); vcc_symtabname(vsb, sym->symtab);
} }
static char *
vcc_dup_be(const char *b, const char *e)
{
char *p;
AN(b);
if (e == NULL)
e = strchr(b, '\0');
AN(e);
assert(e >= b);
p = strndup(b, e - b);
AN(p);
return (p);
}
static struct symtab * static struct symtab *
vcc_symtab_new(const char *name) vcc_symtab_new(const char *name)
{ {
...@@ -177,14 +161,14 @@ vcc_symtab_str(struct symtab *st, const char *b, const char *e) ...@@ -177,14 +161,14 @@ vcc_symtab_str(struct symtab *st, const char *b, const char *e)
continue; continue;
if (i == 0 && l == st2->nlen) if (i == 0 && l == st2->nlen)
break; break;
st3 = vcc_symtab_new(vcc_dup_be(b, q)); st3 = vcc_symtab_new(vcc_Dup_be(b, q));
st3->parent = st; st3->parent = st;
VTAILQ_INSERT_BEFORE(st2, st3, list); VTAILQ_INSERT_BEFORE(st2, st3, list);
st2 = st3; st2 = st3;
break; break;
} }
if (st2 == NULL) { if (st2 == NULL) {
st2 = vcc_symtab_new(vcc_dup_be(b, q)); st2 = vcc_symtab_new(vcc_Dup_be(b, q));
st2->parent = st; st2->parent = st;
VTAILQ_INSERT_TAIL(&st->children, st2, list); VTAILQ_INSERT_TAIL(&st->children, st2, list);
} }
...@@ -287,10 +271,7 @@ VCC_SymbolGet(struct vcc *tl, vcc_ns_t ns, vcc_kind_t kind, ...@@ -287,10 +271,7 @@ VCC_SymbolGet(struct vcc *tl, vcc_ns_t ns, vcc_kind_t kind,
AN(x); AN(x);
AN(x->name); AN(x->name);
if (tl->syntax >= VCL_41 && e == SYMTAB_CREATE && kind != SYM_SUB && if (tl->syntax >= VCL_41 && e == SYMTAB_CREATE && kind != SYM_SUB &&
(tl->t->b[0] == 'v'|| tl->t->b[0] == 'V') && vcc_Has_vcl_prefix(tl->t->b)) {
(tl->t->b[1] == 'c'|| tl->t->b[1] == 'C') &&
(tl->t->b[2] == 'l'|| tl->t->b[2] == 'L') &&
(tl->t->b[3] == '_')) {
VSB_cat(tl->sb, "Symbols named 'vcl_*' are reserved.\nAt:"); VSB_cat(tl->sb, "Symbols named 'vcl_*' are reserved.\nAt:");
vcc_ErrWhere(tl, tl->t); vcc_ErrWhere(tl, tl->t);
return (NULL); return (NULL);
......
...@@ -385,3 +385,30 @@ vcc_IsFlag(struct vcc *tl) ...@@ -385,3 +385,30 @@ vcc_IsFlag(struct vcc *tl)
vcc_NextToken(tl); vcc_NextToken(tl);
return (retval); return (retval);
} }
char *
vcc_Dup_be(const char *b, const char *e)
{
char *p;
AN(b);
if (e == NULL)
e = strchr(b, '\0');
AN(e);
assert(e >= b);
p = strndup(b, e - b);
AN(p);
return (p);
}
int
vcc_Has_vcl_prefix(const char *b)
{
return (
(b[0] == 'v' || b[0] == 'V') &&
(b[1] == 'c' || b[1] == 'C') &&
(b[2] == 'l' || b[2] == 'L') &&
(b[3] == '_')
);
}
Markdown is supported
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