]> granicus.if.org Git - re2c/commitdiff
- Add line info to header
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 22 Apr 2007 18:35:24 +0000 (18:35 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 22 Apr 2007 18:35:24 +0000 (18:35 +0000)
re2c/code.cc
re2c/globals.h
re2c/main.cc
re2c/run_tests.sh.in
re2c/test/condition_05.cgitcondition_05.cgit.h.c [new file with mode: 0755]
re2c/test/condition_05.cgitcondition_05.cgit.h.h [new file with mode: 0755]
re2c/test/condition_05.cgitcondition_05.cgit.h.re [new file with mode: 0755]
re2c/test/condition_05.cgtcondition_05.cgt.h.h

index ea5dc4cd7802f413a1d36c0dd4a1df7e2cc1a854..828f4aa906b7cd01dbf0e730b6361165c9f16d37 100644 (file)
@@ -1708,7 +1708,9 @@ void genHeader(std::ostream &o, uint ind, const RegExpMap& specMap)
                o.write(ctime(&now), 24);
        }
        o << " */\n";
-       //TODO: o << headerFileInfo;
+       o << headerFileInfo;
+       o << "\n";
+       // now the type(s)
        o << indent(ind++) << "enum " << mapCodeName["YYCONDTYPE"] << " {\n";
        for(RegExpMap::const_iterator it = specMap.begin(); it != specMap.end(); ++it)
        {
index ab296274a3a534dcffd567838b6f5a0c0655b2d7..21dc7d7d608cc082967b77d6eebd93ae0802facb 100644 (file)
@@ -14,6 +14,7 @@ namespace re2c
 
 extern file_info sourceFileInfo;
 extern file_info outputFileInfo;
+extern file_info headerFileInfo;
 
 extern bool bFlag;
 extern bool cFlag;
index 6cf792375643bd8f2c4af7baa89ba3fed23e9da5..e0980836eb7ded117fef4b3422c1ed0a2bdcc903 100644 (file)
@@ -20,6 +20,7 @@ namespace re2c
 
 file_info sourceFileInfo;
 file_info outputFileInfo;
+file_info headerFileInfo;
 
 bool bFlag = false;
 bool cFlag = false;
@@ -350,6 +351,7 @@ int main(int argc, char *argv[])
                        cerr << "re2c: error: cannot open " << headerFileName << "\n";
                        return 1;
                }
+               headerFileInfo = file_info(headerFileName, &header);
        }
        Scanner scanner(source, output);
        sourceFileInfo = file_info(sourceFileName, &scanner);
index d2d3e89caf7eb2bb03ce4b05839f0e45009a8e9c..2bf517eb70983d913ff7558a402bd2705b065fb2 100644 (file)
@@ -28,6 +28,7 @@ for x in @top_srcdir@/test/*.re `find @top_srcdir@/lessons -name '*.re'|sort`; d
                rm $headers
                if ${diff} ${x%.re}.h $typname > $typdiff; then
                        echo "Passed header test."
+                       rm $typname
                else
                        echo "Failed: ${x%.re}.h ${x%.re}.h.temp differ."
                        result=1
diff --git a/re2c/test/condition_05.cgitcondition_05.cgit.h.c b/re2c/test/condition_05.cgitcondition_05.cgit.h.c
new file mode 100755 (executable)
index 0000000..de63c6e
--- /dev/null
@@ -0,0 +1,139 @@
+/* Generated by re2c */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define        BSIZE   8192
+
+typedef struct Scanner
+{
+       FILE                    *fp;
+       unsigned char   *cur, *tok, *lim, *eof;
+       unsigned char   buffer[BSIZE];
+} Scanner;
+
+int fill(Scanner *s, int len)
+{
+       if (!len)
+       {
+               s->cur = s->tok = s->lim = s->buffer;
+               s->eof = 0;
+       }
+       if (!s->eof)
+       {
+               int got, cnt = s->tok - s->buffer;
+
+               if (cnt > 0)
+               {
+                       memcpy(s->buffer, s->tok, s->lim - s->tok);
+                       s->tok -= cnt;
+                       s->cur -= cnt;
+                       s->lim -= cnt;
+               }
+               cnt = BSIZE - cnt;
+               if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt)
+               {
+                       s->eof = &s->lim[got];
+               }
+               s->lim += got;
+       }
+       else if (s->cur + len > s->eof)
+       {
+               return 0; /* not enough input data */
+       }
+       return -1;
+}
+
+char scan(Scanner *s)
+{
+       int state = 1;
+       
+       fill(s, 0);
+
+       for(;;)
+       {
+               s->tok = s->cur;
+
+               {
+                       unsigned char yych;
+                       static void *yyctable[2] = {
+                               &&yyc_comment,
+                               &&yyc_normal,
+                       };
+                       goto *yyctable[state];
+/* *********************************** */
+yyc_comment:
+
+                       if((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; };
+                       yych = *s->cur;
+                       if(yych != '*') goto yy4;
+                       ++s->cur;
+                       if((yych = *s->cur) == '/') goto yy5;
+yy3:
+                       {
+                               goto yyc_comment;
+                       }
+yy4:
+                       yych = *++s->cur;
+                       goto yy3;
+yy5:
+                       ++s->cur;
+                       {
+                               continue;
+                       }
+/* *********************************** */
+yyc_normal:
+                       if((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; };
+                       yych = *s->cur;
+                       if(yych != '/') goto yy11;
+                       ++s->cur;
+                       if((yych = *s->cur) == '*') goto yy12;
+yy10:
+                       {
+                               fputc(*s->tok, stdout);
+                               continue;
+                       }
+yy11:
+                       yych = *++s->cur;
+                       goto yy10;
+yy12:
+                       ++s->cur;
+                       {
+                               goto yyc_comment;
+                       }
+               }
+
+       }
+}
+
+int main(int argc, char **argv)
+{
+       Scanner in;
+       char c;
+
+       if (argc != 2)
+       {
+               fprintf(stderr, "%s <file>\n", argv[0]);
+               return 1;;
+       }
+
+       memset((char*) &in, 0, sizeof(in));
+
+       if (!strcmp(argv[1], "-"))
+       {
+               in.fp = stdin;
+       }
+       else if ((in.fp = fopen(argv[1], "r")) == NULL)
+       {
+               fprintf(stderr, "Cannot open file '%s'\n", argv[1]);
+               return 1;
+       }
+
+       scan(&in);
+
+       if (in.fp != stdin)
+       {
+               fclose(in.fp);
+       }
+       return 0;
+}
diff --git a/re2c/test/condition_05.cgitcondition_05.cgit.h.h b/re2c/test/condition_05.cgitcondition_05.cgit.h.h
new file mode 100755 (executable)
index 0000000..9cda0d7
--- /dev/null
@@ -0,0 +1,6 @@
+/* Generated by re2c */
+
+enum YYCONDTYPE {
+       comment,
+       normal,
+}
diff --git a/re2c/test/condition_05.cgitcondition_05.cgit.h.re b/re2c/test/condition_05.cgitcondition_05.cgit.h.re
new file mode 100755 (executable)
index 0000000..7c702fa
--- /dev/null
@@ -0,0 +1,118 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define        BSIZE   8192
+
+typedef struct Scanner
+{
+       FILE                    *fp;
+       unsigned char   *cur, *tok, *lim, *eof;
+       unsigned char   buffer[BSIZE];
+} Scanner;
+
+int fill(Scanner *s, int len)
+{
+       if (!len)
+       {
+               s->cur = s->tok = s->lim = s->buffer;
+               s->eof = 0;
+       }
+       if (!s->eof)
+       {
+               int got, cnt = s->tok - s->buffer;
+
+               if (cnt > 0)
+               {
+                       memcpy(s->buffer, s->tok, s->lim - s->tok);
+                       s->tok -= cnt;
+                       s->cur -= cnt;
+                       s->lim -= cnt;
+               }
+               cnt = BSIZE - cnt;
+               if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt)
+               {
+                       s->eof = &s->lim[got];
+               }
+               s->lim += got;
+       }
+       else if (s->cur + len > s->eof)
+       {
+               return 0; /* not enough input data */
+       }
+       return -1;
+}
+
+char scan(Scanner *s)
+{
+       int state = 1;
+       
+       fill(s, 0);
+
+       for(;;)
+       {
+               s->tok = s->cur;
+/*!re2c
+
+re2c:define:YYCTYPE     = "unsigned char";
+re2c:define:YYCURSOR    = s->cur;
+re2c:define:YYLIMIT     = s->lim;
+re2c:define:YYMARKER    = s->ptr;
+re2c:define:YYFILL      = "{ if(fill(s, 2) >= 0) break; }";
+re2c:define:YYCONDITION = state;
+re2c:yyfill:parameter   = 0;
+re2c:indent:top         = 2;
+
+<normal>       "/*"
+                       {
+                               goto yyc_comment;
+                       }
+<normal>       [^]
+                       {
+                               fputc(*s->tok, stdout);
+                               continue;
+                       }
+<comment>      "*" "/"
+                       {
+                               continue;
+                       }
+<comment>      [^]
+                       {
+                               goto yyc_comment;
+                       }
+
+*/
+       }
+}
+
+int main(int argc, char **argv)
+{
+       Scanner in;
+       char c;
+
+       if (argc != 2)
+       {
+               fprintf(stderr, "%s <file>\n", argv[0]);
+               return 1;;
+       }
+
+       memset((char*) &in, 0, sizeof(in));
+
+       if (!strcmp(argv[1], "-"))
+       {
+               in.fp = stdin;
+       }
+       else if ((in.fp = fopen(argv[1], "r")) == NULL)
+       {
+               fprintf(stderr, "Cannot open file '%s'\n", argv[1]);
+               return 1;
+       }
+
+       scan(&in);
+
+       if (in.fp != stdin)
+       {
+               fclose(in.fp);
+       }
+       return 0;
+}
index 767b013c31452f82efb4ce836cc5bcb986478206..9c472d7a937291a126e147f838b519944ebf7e79 100755 (executable)
@@ -1,4 +1,6 @@
 /* Generated by re2c */
+#line 3 "condition_05.cgt.h"
+
 enum YYCONDTYPE {
        comment,
        normal,