summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common.cc129
-rw-r--r--src/inputdata.cc139
-rw-r--r--src/parsedata.h53
-rw-r--r--src/parsetree.cc1
-rw-r--r--src/parsetree.h30
-rw-r--r--test/Makefile.am4
-rw-r--r--test/ragel.d/Makefile.am2
7 files changed, 155 insertions, 203 deletions
diff --git a/src/common.cc b/src/common.cc
index 6e0f5c0c..548d094f 100644
--- a/src/common.cc
+++ b/src/common.cc
@@ -139,135 +139,6 @@ HostType *findAlphTypeInternal( const HostLang *hostLang, const char *s1 )
return 0;
}
-/* Construct a new parameter checker with for paramSpec. */
-ParamCheck::ParamCheck( const char *paramSpec, int argc, const char **argv )
-:
- state(noparam),
- argOffset(0),
- curArg(0),
- iCurArg(1),
- paramSpec(paramSpec),
- argc(argc),
- argv(argv)
-{
-}
-
-/* Check a single option. Returns the index of the next parameter. Sets p to
- * the arg character if valid, 0 otherwise. Sets parg to the parameter arg if
- * there is one, NULL otherwise. */
-bool ParamCheck::check()
-{
- bool requiresParam;
-
- if ( iCurArg >= argc ) { /* Off the end of the arg list. */
- state = noparam;
- return false;
- }
-
- if ( argOffset != 0 && *argOffset == 0 ) {
- /* We are at the end of an arg string. */
- iCurArg += 1;
- if ( iCurArg >= argc ) {
- state = noparam;
- return false;
- }
- argOffset = 0;
- }
-
- if ( argOffset == 0 ) {
- /* Set the current arg. */
- curArg = argv[iCurArg];
-
- /* We are at the beginning of an arg string. */
- if ( argv[iCurArg] == 0 || /* Argv[iCurArg] is null. */
- argv[iCurArg][0] != '-' || /* Not a param. */
- argv[iCurArg][1] == 0 ) { /* Only a dash. */
- parameter = 0;
- paramArg = 0;
-
- iCurArg += 1;
- state = noparam;
- return true;
- }
- argOffset = argv[iCurArg] + 1;
- }
-
- /* Get the arg char. */
- char argChar = *argOffset;
-
- /* Loop over all the parms and look for a match. */
- const char *pSpec = paramSpec;
- while ( *pSpec != 0 ) {
- char pSpecChar = *pSpec;
-
- /* If there is a ':' following the char then
- * it requires a parm. If a parm is required
- * then move ahead two in the parmspec. Otherwise
- * move ahead one in the parm spec. */
- if ( pSpec[1] == ':' ) {
- requiresParam = true;
- pSpec += 2;
- }
- else {
- requiresParam = false;
- pSpec += 1;
- }
-
- /* Do we have a match. */
- if ( argChar == pSpecChar ) {
- if ( requiresParam ) {
- if ( argOffset[1] == 0 ) {
- /* The param must follow. */
- if ( iCurArg + 1 == argc ) {
- /* We are the last arg so there
- * cannot be a parameter to it. */
- parameter = argChar;
- paramArg = 0;
- iCurArg += 1;
- argOffset = 0;
- state = invalid;
- return true;
- }
- else {
- /* the parameter to the arg is the next arg. */
- parameter = pSpecChar;
- paramArg = argv[iCurArg + 1];
- iCurArg += 2;
- argOffset = 0;
- state = match;
- return true;
- }
- }
- else {
- /* The param for the arg is built in. */
- parameter = pSpecChar;
- paramArg = argOffset + 1;
- iCurArg += 1;
- argOffset = 0;
- state = match;
- return true;
- }
- }
- else {
- /* Good, we matched the parm and no
- * arg is required. */
- parameter = pSpecChar;
- paramArg = 0;
- argOffset += 1;
- state = match;
- return true;
- }
- }
- }
-
- /* We did not find a match. Bad Argument. */
- parameter = argChar;
- paramArg = 0;
- argOffset += 1;
- state = invalid;
- return true;
-}
-
std::streamsize output_filter::countAndWrite( const char *s, std::streamsize n )
{
for ( int i = 0; i < n; i++ ) {
diff --git a/src/inputdata.cc b/src/inputdata.cc
index d7e075d8..33a0b5b8 100644
--- a/src/inputdata.cc
+++ b/src/inputdata.cc
@@ -29,6 +29,8 @@
#include "reducer.h"
#include "version.h"
#include "pcheck.h"
+#include <libfsm/dot.h>
+
#include <colm/colm.h>
#include <stdlib.h>
@@ -265,6 +267,13 @@ void InputData::closeOutput()
}
}
+void InputData::writeDot( ostream &out )
+{
+ ParseData *pd = dotGenPd;
+ GraphvizDotGen dotGen( this, pd->fsmCtx, pd->sectionGraph, pd->sectionName, pd->machineId, out );
+ dotGen.write();
+}
+
void InputData::processDot()
{
/* Compiles the DOT machines. */
@@ -678,6 +687,136 @@ void escapeLineDirectivePath( std::ostream &out, char *path )
}
}
+/* Construct a new parameter checker with for paramSpec. */
+ParamCheck::ParamCheck( const char *paramSpec, int argc, const char **argv )
+:
+ state(noparam),
+ argOffset(0),
+ curArg(0),
+ iCurArg(1),
+ paramSpec(paramSpec),
+ argc(argc),
+ argv(argv)
+{
+}
+
+/* Check a single option. Returns the index of the next parameter. Sets p to
+ * the arg character if valid, 0 otherwise. Sets parg to the parameter arg if
+ * there is one, NULL otherwise. */
+bool ParamCheck::check()
+{
+ bool requiresParam;
+
+ if ( iCurArg >= argc ) { /* Off the end of the arg list. */
+ state = noparam;
+ return false;
+ }
+
+ if ( argOffset != 0 && *argOffset == 0 ) {
+ /* We are at the end of an arg string. */
+ iCurArg += 1;
+ if ( iCurArg >= argc ) {
+ state = noparam;
+ return false;
+ }
+ argOffset = 0;
+ }
+
+ if ( argOffset == 0 ) {
+ /* Set the current arg. */
+ curArg = argv[iCurArg];
+
+ /* We are at the beginning of an arg string. */
+ if ( argv[iCurArg] == 0 || /* Argv[iCurArg] is null. */
+ argv[iCurArg][0] != '-' || /* Not a param. */
+ argv[iCurArg][1] == 0 ) { /* Only a dash. */
+ parameter = 0;
+ paramArg = 0;
+
+ iCurArg += 1;
+ state = noparam;
+ return true;
+ }
+ argOffset = argv[iCurArg] + 1;
+ }
+
+ /* Get the arg char. */
+ char argChar = *argOffset;
+
+ /* Loop over all the parms and look for a match. */
+ const char *pSpec = paramSpec;
+ while ( *pSpec != 0 ) {
+ char pSpecChar = *pSpec;
+
+ /* If there is a ':' following the char then
+ * it requires a parm. If a parm is required
+ * then move ahead two in the parmspec. Otherwise
+ * move ahead one in the parm spec. */
+ if ( pSpec[1] == ':' ) {
+ requiresParam = true;
+ pSpec += 2;
+ }
+ else {
+ requiresParam = false;
+ pSpec += 1;
+ }
+
+ /* Do we have a match. */
+ if ( argChar == pSpecChar ) {
+ if ( requiresParam ) {
+ if ( argOffset[1] == 0 ) {
+ /* The param must follow. */
+ if ( iCurArg + 1 == argc ) {
+ /* We are the last arg so there
+ * cannot be a parameter to it. */
+ parameter = argChar;
+ paramArg = 0;
+ iCurArg += 1;
+ argOffset = 0;
+ state = invalid;
+ return true;
+ }
+ else {
+ /* the parameter to the arg is the next arg. */
+ parameter = pSpecChar;
+ paramArg = argv[iCurArg + 1];
+ iCurArg += 2;
+ argOffset = 0;
+ state = match;
+ return true;
+ }
+ }
+ else {
+ /* The param for the arg is built in. */
+ parameter = pSpecChar;
+ paramArg = argOffset + 1;
+ iCurArg += 1;
+ argOffset = 0;
+ state = match;
+ return true;
+ }
+ }
+ else {
+ /* Good, we matched the parm and no
+ * arg is required. */
+ parameter = pSpecChar;
+ paramArg = 0;
+ argOffset += 1;
+ state = match;
+ return true;
+ }
+ }
+ }
+
+ /* We did not find a match. Bad Argument. */
+ parameter = argChar;
+ paramArg = 0;
+ argOffset += 1;
+ state = invalid;
+ return true;
+}
+
+
void InputData::parseArgs( int argc, const char **argv )
{
ParamCheck pc( "o:dnmleabjkS:M:I:vHh?-:sT:F:W:G:LpV", argc, argv );
diff --git a/src/parsedata.h b/src/parsedata.h
index 1df3aa2e..109f36e6 100644
--- a/src/parsedata.h
+++ b/src/parsedata.h
@@ -115,65 +115,12 @@ typedef AvlMap<std::string, int, CmpString> PriorDict;
typedef AvlMapEl<std::string, int> LocalErrDictEl;
typedef AvlMap<std::string, int, CmpString> LocalErrDict;
-struct NameMapVal
-{
- Vector<NameInst*> vals;
-};
-
/* Tree of instantiated names. */
typedef AvlMapEl<std::string, NameMapVal*> NameMapEl;
typedef AvlMap<std::string, NameMapVal*, CmpString> NameMap;
typedef Vector<NameInst*> NameVect;
typedef BstSet<NameInst*> NameSet;
-/* Node in the tree of instantiated names. */
-struct NameInst
-{
- NameInst( const InputLoc &loc, NameInst *parent, std::string name, int id, bool isLabel ) :
- loc(loc), parent(parent), name(name), id(id), isLabel(isLabel),
- isLongestMatch(false), numRefs(0), numUses(0), start(0), final(0) {}
-
- ~NameInst();
-
- InputLoc loc;
-
- /* Keep parent pointers in the name tree to retrieve
- * fully qulified names. */
- NameInst *parent;
-
- std::string name;
- int id;
- bool isLabel;
- bool isLongestMatch;
-
- int numRefs;
- int numUses;
-
- /* Names underneath us, excludes anonymous names. */
- NameMap children;
-
- /* All names underneath us in order of appearance. */
- NameVect childVect;
-
- /* Join scopes need an implicit "final" target. */
- NameInst *start, *final;
-
- /* During a fsm generation walk, lists the names that are referenced by
- * epsilon operations in the current scope. After the link is made by the
- * epsilon reference and the join operation is complete, the label can
- * have its refcount decremented. Once there are no more references the
- * entry point can be removed from the fsm returned. */
- NameVect referencedNames;
-
- /* Pointers for the name search queue. */
- NameInst *prev, *next;
-
- /* Check if this name inst or any name inst below is referenced. */
- bool anyRefsRec();
-};
-
-typedef DList<NameInst> NameInstList;
-
/* Stack frame used in walking the name tree. */
struct NameFrame
{
diff --git a/src/parsetree.cc b/src/parsetree.cc
index f51c35e8..f882bc2c 100644
--- a/src/parsetree.cc
+++ b/src/parsetree.cc
@@ -30,6 +30,7 @@
/* Parsing. */
#include <libfsm/ragel.h>
+#include <libfsm/action.h>
#include "parsetree.h"
#include "parsedata.h"
diff --git a/src/parsetree.h b/src/parsetree.h
index 37f2fda7..9c47c0c2 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -151,7 +151,6 @@ struct InlineItem;
struct InlineList;
/* Reference to a named state. */
-struct NameRef : public Vector<std::string> {};
typedef Vector<NameRef*> NameRefList;
typedef Vector<NameInst*> NameTargList;
@@ -284,30 +283,21 @@ struct VarDef
* and consume the current character.
*/
struct LongestMatchPart
+:
+ public FsmLongestMatchPart
{
LongestMatchPart( Join *join, Action *action,
const InputLoc &semiLoc, int longestMatchId )
:
- join(join), action(action), semiLoc(semiLoc),
- longestMatchId(longestMatchId), inLmSelect(false) { }
+ FsmLongestMatchPart( action, longestMatchId ),
+ join(join), semiLoc(semiLoc)
+ { }
InputLoc getLoc();
Join *join;
- Action *action;
InputLoc semiLoc;
- Action *setActId;
- Action *actOnLast;
- Action *actOnNext;
- Action *actLagBehind;
- Action *actNfaOnLast;
- Action *actNfaOnNext;
- Action *actNfaOnEof;
- int longestMatchId;
- bool inLmSelect;
- LongestMatch *longestMatch;
-
LongestMatchPart *prev, *next;
};
@@ -315,21 +305,25 @@ struct LongestMatchPart
struct LmPartList : DList<LongestMatchPart> {};
struct LongestMatch
+:
+ public FsmLongestMatch
{
/* Construct with a list of joins */
LongestMatch( const InputLoc &loc, LmPartList *longestMatchList )
:
+ FsmLongestMatch( new FsmLmPartList ),
loc(loc),
longestMatchList(longestMatchList),
- lmSwitchHandlesError(false),
nfaConstruction(false)
- { }
+ {
+ for ( LongestMatchPart *lmPart = longestMatchList->head; lmPart != 0; lmPart = lmPart->next )
+ FsmLongestMatch::longestMatchList->append( lmPart );
+ }
InputLoc loc;
LmPartList *longestMatchList;
std::string name;
Action *lmActSelect;
- bool lmSwitchHandlesError;
bool nfaConstruction;
LongestMatch *next, *prev;
diff --git a/test/Makefile.am b/test/Makefile.am
index abaa35f0..d70e20ae 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,8 +1,8 @@
SUBDIRS = . ragel.d
-noinst_SCRIPTS = subject.mk subject.sh
+noinst_SCRIPTS = runtests subject.mk subject.sh
-EXTRA_DIST = subject.mk.in subject.sh.in runtests
+EXTRA_DIST = subject.mk.in subject.sh.in runtests.sh
subject.mk: subject.mk.in Makefile
@$(top_srcdir)/sedsubst $< $@ -w,+x $(SED_SUBST)
diff --git a/test/ragel.d/Makefile.am b/test/ragel.d/Makefile.am
index a95381c5..f6845367 100644
--- a/test/ragel.d/Makefile.am
+++ b/test/ragel.d/Makefile.am
@@ -19,7 +19,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
COLM_BIN = @COLM@
-RAGEL_LM = ../../ragel
+RAGEL_LM = ../../src
COLM_xCPPFLAGS = # -I../../colm/include
COLM_xLDFLAGS = # -L../../colm