]> granicus.if.org Git - re2c/commitdiff
- Simplify dfa caching
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Mon, 24 Mar 2008 14:21:11 +0000 (14:21 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Mon, 24 Mar 2008 14:21:11 +0000 (14:21 +0000)
re2c/bootstrap/parser.cc
re2c/parser.y

index 56d089325cd77176e576f54cf4f275d3ff5ffb22..62dae88ea11f5d299a6de9db5c6e4a5240a18d27 100644 (file)
@@ -2176,7 +2176,6 @@ namespace re2c
 
 void parse(Scanner& i, std::ostream& o, std::ostream* h)
 {
-       DFA *dfa = NULL;
        std::map<std::string, DFA*>  dfa_map;
 
        in = &i;
@@ -2198,24 +2197,19 @@ void parse(Scanner& i, std::ostream& o, std::ostream* h)
        while ((parseMode = i.echo()) != Scanner::Stop)
        {
                bool bPrologBrace = false;
-               if (rFlag && parseMode == Scanner::Rules && (dfa || dfa_map.size()))
+               if (rFlag && parseMode == Scanner::Rules && dfa_map.size())
                {
                        in->fatal("cannot have a second 'rules:re2c' block");
                }
                if (parseMode == Scanner::Reuse)
                {
-                       if (!dfa && dfa_map.empty())
+                       if (dfa_map.empty())
                        {
                                in->fatal("got 'use:re2c' without 'rules:re2c'");
                        }
                }
                else
                {
-                       if (dfa)
-                       {
-                               delete dfa;
-                               dfa = NULL;
-                       }
                        dfa_map.clear();
                }
                in->set_in_parse(true);
@@ -2320,21 +2314,20 @@ void parse(Scanner& i, std::ostream& o, std::ostream* h)
                                genTypes(typesInline, 0, specMap);
                        }
                }
-               else if (spec || dfa)
+               else if (spec || !dfa_map.empty())
                {
                        if (parseMode == Scanner::Reuse)
                        {
-                               dfa->emit(o, topIndent, NULL, "", 0, bPrologBrace);
+                               dfa_map[""]->emit(o, topIndent, NULL, "", 0, bPrologBrace);
                        }
                        else
                        {
-                               dfa = genCode(spec);
-                               dfa->prepare();
+                               dfa_map[""] = genCode(spec);
+                               dfa_map[""]->prepare();
                                if (!rFlag)
                                {
-                                       dfa->emit(o, topIndent, NULL, "", 0, bPrologBrace);
-                                       delete dfa;
-                                       dfa = NULL;
+                                       dfa_map[""]->emit(o, topIndent, NULL, "", 0, bPrologBrace);
+                                       dfa_map.clear();
                                }
                        }
                }
@@ -2379,10 +2372,6 @@ void parse(Scanner& i, std::ostream& o, std::ostream* h)
        specStar.clear();
        specNone = NULL;
        in = NULL;
-       if (dfa)
-       {
-               delete dfa;
-       }
 }
 
 } // end namespace re2c
index 1b11bc4b991463319147b2dbfb45cfb37eb17e87..6c0ef42a8621cf956c87be5b283200aec65082af 100644 (file)
@@ -474,7 +474,6 @@ namespace re2c
 
 void parse(Scanner& i, std::ostream& o, std::ostream* h)
 {
-       DFA *dfa = NULL;
        std::map<std::string, DFA*>  dfa_map;
 
        in = &i;
@@ -496,24 +495,19 @@ void parse(Scanner& i, std::ostream& o, std::ostream* h)
        while ((parseMode = i.echo()) != Scanner::Stop)
        {
                bool bPrologBrace = false;
-               if (rFlag && parseMode == Scanner::Rules && (dfa || dfa_map.size()))
+               if (rFlag && parseMode == Scanner::Rules && dfa_map.size())
                {
                        in->fatal("cannot have a second 'rules:re2c' block");
                }
                if (parseMode == Scanner::Reuse)
                {
-                       if (!dfa && dfa_map.empty())
+                       if (dfa_map.empty())
                        {
                                in->fatal("got 'use:re2c' without 'rules:re2c'");
                        }
                }
                else
                {
-                       if (dfa)
-                       {
-                               delete dfa;
-                               dfa = NULL;
-                       }
                        dfa_map.clear();
                }
                in->set_in_parse(true);
@@ -618,21 +612,20 @@ void parse(Scanner& i, std::ostream& o, std::ostream* h)
                                genTypes(typesInline, 0, specMap);
                        }
                }
-               else if (spec || dfa)
+               else if (spec || !dfa_map.empty())
                {
                        if (parseMode == Scanner::Reuse)
                        {
-                               dfa->emit(o, topIndent, NULL, "", 0, bPrologBrace);
+                               dfa_map[""]->emit(o, topIndent, NULL, "", 0, bPrologBrace);
                        }
                        else
                        {
-                               dfa = genCode(spec);
-                               dfa->prepare();
+                               dfa_map[""] = genCode(spec);
+                               dfa_map[""]->prepare();
                                if (!rFlag)
                                {
-                                       dfa->emit(o, topIndent, NULL, "", 0, bPrologBrace);
-                                       delete dfa;
-                                       dfa = NULL;
+                                       dfa_map[""]->emit(o, topIndent, NULL, "", 0, bPrologBrace);
+                                       dfa_map.clear();
                                }
                        }
                }
@@ -677,10 +670,6 @@ void parse(Scanner& i, std::ostream& o, std::ostream* h)
        specStar.clear();
        specNone = NULL;
        in = NULL;
-       if (dfa)
-       {
-               delete dfa;
-       }
 }
 
 } // end namespace re2c