summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Zakharevich <ilya@math.berkeley.edu>1999-05-05 21:21:05 -0400
committerGurusamy Sarathy <gsar@cpan.org>1999-05-10 10:57:49 +0000
commit9b155405e1006cdd8b8d8ffbf82a0cdd100aa3a4 (patch)
tree38467af2f8e77585658939bd07f237423b5161d1
parentfe4c6be141b0b356b13c8403bfd72e3f9e782a25 (diff)
downloadperl-9b155405e1006cdd8b8d8ffbf82a0cdd100aa3a4.tar.gz
Cosmetic: data-driven REx-dump
Message-Id: <199905060521.BAA03485@monk.mps.ohio-state.edu> p4raw-id: //depot/perl@3372
-rw-r--r--regcomp.c207
-rw-r--r--regcomp.pl25
2 files changed, 41 insertions, 191 deletions
diff --git a/regcomp.c b/regcomp.c
index cbb94479a8..34640b7b8e 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -2913,199 +2913,28 @@ regprop(SV *sv, regnode *o)
{
#ifdef DEBUGGING
dTHR;
- register char *p = 0;
+ register int k;
sv_setpvn(sv, "", 0);
- switch (OP(o)) {
- case BOL:
- p = "BOL";
- break;
- case MBOL:
- p = "MBOL";
- break;
- case SBOL:
- p = "SBOL";
- break;
- case EOL:
- p = "EOL";
- break;
- case EOS:
- p = "EOS";
- break;
- case MEOL:
- p = "MEOL";
- break;
- case SEOL:
- p = "SEOL";
- break;
- case REG_ANY:
- p = "ANY";
- break;
- case SANY:
- p = "SANY";
- break;
- case ANYUTF8:
- p = "ANYUTF8";
- break;
- case SANYUTF8:
- p = "SANYUTF8";
- break;
- case ANYOFUTF8:
- p = "ANYOFUTF8";
- break;
- case ANYOF:
- p = "ANYOF";
- break;
- case BRANCH:
- p = "BRANCH";
- break;
- case EXACT:
- sv_catpvf(sv, "EXACT <%s%s%s>", PL_colors[0], OPERAND(o) + 1, PL_colors[1]);
- break;
- case EXACTF:
- sv_catpvf(sv, "EXACTF <%s%s%s>", PL_colors[0], OPERAND(o) + 1, PL_colors[1]);
- break;
- case EXACTFL:
- sv_catpvf(sv, "EXACTFL <%s%s%s>", PL_colors[0], OPERAND(o) + 1, PL_colors[1]);
- break;
- case NOTHING:
- p = "NOTHING";
- break;
- case TAIL:
- p = "TAIL";
- break;
- case BACK:
- p = "BACK";
- break;
- case END:
- p = "END";
- break;
- case BOUND:
- p = "BOUND";
- break;
- case BOUNDL:
- p = "BOUNDL";
- break;
- case NBOUND:
- p = "NBOUND";
- break;
- case NBOUNDL:
- p = "NBOUNDL";
- break;
- case CURLY:
- sv_catpvf(sv, "CURLY {%d,%d}", ARG1(o), ARG2(o));
- break;
- case CURLYM:
- sv_catpvf(sv, "CURLYM[%d] {%d,%d}", o->flags, ARG1(o), ARG2(o));
- break;
- case CURLYN:
- sv_catpvf(sv, "CURLYN[%d] {%d,%d}", o->flags, ARG1(o), ARG2(o));
- break;
- case CURLYX:
- sv_catpvf(sv, "CURLYX {%d,%d}", ARG1(o), ARG2(o));
- break;
- case REF:
- sv_catpvf(sv, "REF%d", ARG(o));
- break;
- case REFF:
- sv_catpvf(sv, "REFF%d", ARG(o));
- break;
- case REFFL:
- sv_catpvf(sv, "REFFL%d", ARG(o));
- break;
- case OPEN:
- sv_catpvf(sv, "OPEN%d", ARG(o));
- break;
- case CLOSE:
- sv_catpvf(sv, "CLOSE%d", ARG(o));
- p = NULL;
- break;
- case STAR:
- p = "STAR";
- break;
- case PLUS:
- p = "PLUS";
- break;
- case MINMOD:
- p = "MINMOD";
- break;
- case GPOS:
- p = "GPOS";
- break;
- case UNLESSM:
- sv_catpvf(sv, "UNLESSM[-%d]", o->flags);
- break;
- case IFMATCH:
- sv_catpvf(sv, "IFMATCH[-%d]", o->flags);
- break;
- case SUCCEED:
- p = "SUCCEED";
- break;
- case WHILEM:
- p = "WHILEM";
- break;
- case DIGIT:
- p = "DIGIT";
- break;
- case NDIGIT:
- p = "NDIGIT";
- break;
- case ALNUM:
- p = "ALNUM";
- break;
- case NALNUM:
- p = "NALNUM";
- break;
- case SPACE:
- p = "SPACE";
- break;
- case NSPACE:
- p = "NSPACE";
- break;
- case ALNUML:
- p = "ALNUML";
- break;
- case NALNUML:
- p = "NALNUML";
- break;
- case SPACEL:
- p = "SPACEL";
- break;
- case NSPACEL:
- p = "NSPACEL";
- break;
- case EVAL:
- p = "EVAL";
- break;
- case LONGJMP:
- p = "LONGJMP";
- break;
- case BRANCHJ:
- p = "BRANCHJ";
- break;
- case IFTHEN:
- p = "IFTHEN";
- break;
- case GROUPP:
- sv_catpvf(sv, "GROUPP%d", ARG(o));
- break;
- case LOGICAL:
- sv_catpvf(sv, "LOGICAL[%d]", o->flags);
- break;
- case SUSPEND:
- p = "SUSPEND";
- break;
- case RENUM:
- p = "RENUM";
- break;
- case OPTIMIZED:
- p = "OPTIMIZED";
- break;
- default:
+ if (OP(o) >= reg_num) /* regnode.type is unsigned */
FAIL("corrupted regexp opcode");
+ sv_catpv(sv, (char*)reg_name[OP(o)]); /* Take off const! */
+
+ k = PL_regkind[(U8)OP(o)];
+
+ if (k == EXACT)
+ sv_catpvf(sv, " <%s%s%s>", PL_colors[0], OPERAND(o) + 1, PL_colors[1]);
+ else if (k == CURLY) {
+ if (OP(o) == CURLYM || OP(o) == CURLYN)
+ sv_catpvf(sv, "[%d]", o->flags); /* Parenth number */
+ sv_catpvf(sv, " {%d,%d}", ARG1(o), ARG2(o));
}
- if (p)
- sv_catpv(sv, p);
+ else if (k == REF || k == OPEN || k == CLOSE || k == GROUPP )
+ sv_catpvf(sv, "%d", ARG(o)); /* Parenth number */
+ else if (k == LOGICAL)
+ sv_catpvf(sv, "[%d]", ARG(o)); /* 2: embedded, otherwise 1 */
+ else if (k == BRANCHJ && (OP(o) == UNLESSM || OP(o) == IFMATCH))
+ sv_catpvf(sv, "[-%d]", o->flags);
#endif /* DEBUGGING */
}
diff --git a/regcomp.pl b/regcomp.pl
index d78321895c..d7d0733010 100644
--- a/regcomp.pl
+++ b/regcomp.pl
@@ -21,7 +21,7 @@ open OUT, ">$tmp_h";
print OUT <<EOP;
/* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
- This file is built by regcomp.pl from regcomp.sym.
+ This file is built by regcomp.pl from regcomp.sym.
Any changes made here will be lost!
*/
@@ -79,7 +79,7 @@ EOP
$ind = 0;
while (++$ind <= $tot) {
$size = $longj[$ind] || 0;
-
+
print OUT <<EOP;
$size, /* $name[$ind] */
EOP
@@ -87,6 +87,27 @@ EOP
print OUT <<EOP;
};
+
+#ifdef DEBUGGING
+const static char * const reg_name[] = {
+EOP
+
+$ind = 0;
+while (++$ind <= $tot) {
+ $hind = sprintf "%#4x", $ind-1;
+ $size = $longj[$ind] || 0;
+
+ print OUT <<EOP;
+ "$name[$ind]", /* $hind */
+EOP
+}
+
+print OUT <<EOP;
+};
+
+const static int reg_num = $tot;
+
+#endif /* DEBUGGING */
#endif /* REG_COMP_C */
EOP