summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2012-07-01 20:38:42 -0400
committerAdrian Thurston <thurston@complang.org>2012-07-01 20:38:42 -0400
commit5bdf8bfcb05dde0f89d291533378d1db38d9b975 (patch)
treea351a3c8f7ca8a4781b58228ed43b9ed4265d79b
parent024594868b14862744e990093ea061f20d48e55f (diff)
downloadcolm-5bdf8bfcb05dde0f89d291533378d1db38d9b975.tar.gz
using a cons function for Term
-rw-r--r--src/compiler.cc2
-rw-r--r--src/parsetree.cc4
-rw-r--r--src/parsetree.h61
3 files changed, 44 insertions, 23 deletions
diff --git a/src/compiler.cc b/src/compiler.cc
index 9ca947b7..057373b8 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -230,8 +230,6 @@ FsmGraph *makeBuiltin( BuiltinMachine builtin, Compiler *pd )
bool isSigned = keyOps->isSigned;
switch ( builtin ) {
- case BT_None:
- break;;
case BT_Any: {
/* All characters. */
retFsm = dotFsm( pd );
diff --git a/src/parsetree.cc b/src/parsetree.cc
index 496167e4..084ffbb8 100644
--- a/src/parsetree.cc
+++ b/src/parsetree.cc
@@ -610,8 +610,6 @@ FsmGraph *Join::walk( Compiler *pd )
Expression::~Expression()
{
switch ( type ) {
- case None:
- break;
case OrType: case IntersectType: case SubtractType:
case StrongSubtractType:
delete expression;
@@ -630,8 +628,6 @@ FsmGraph *Expression::walk( Compiler *pd, bool lastInSeq )
{
FsmGraph *rtnVal = 0;
switch ( type ) {
- case None:
- break;
case OrType: {
/* Evaluate the expression. */
rtnVal = expression->walk( pd, false );
diff --git a/src/parsetree.h b/src/parsetree.h
index 89a15793..aa8b7f4c 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -129,7 +129,6 @@ struct CodeVect : public Vector<Code>
/* Types of builtin machines. */
enum BuiltinMachine
{
- BT_None,
BT_Any,
BT_Ascii,
BT_Extend,
@@ -809,7 +808,6 @@ struct Join
struct Expression
{
enum Type {
- None,
OrType,
IntersectType,
SubtractType,
@@ -819,35 +817,35 @@ struct Expression
};
Expression( ) :
- expression(0), term(0), builtin(BT_None),
- type(None), prev(this), next(this) { }
+ expression(0), term(0), builtin((BuiltinMachine)-1),
+ type((Type)-1), prev(this), next(this) { }
/* Construct with an expression on the left and a term on the right. */
static Expression *cons( Expression *expression, Term *term, Type type )
{
- Expression *expr = new Expression;
- expr->type = type;
- expr->expression = expression;
- expr->term = term;
- return expr;
+ Expression *ret = new Expression;
+ ret->type = type;
+ ret->expression = expression;
+ ret->term = term;
+ return ret;
}
/* Construct with only a term. */
static Expression *cons( Term *term )
{
- Expression *expr = new Expression;
- expr->type = TermType;
- expr->term = term;
- return expr;
+ Expression *ret = new Expression;
+ ret->type = TermType;
+ ret->term = term;
+ return ret;
}
/* Construct with a builtin type. */
static Expression *cons( BuiltinMachine builtin )
{
- Expression *expr = new Expression;
- expr->type = BuiltinType;
- expr->builtin = builtin;
- return expr;
+ Expression *ret = new Expression;
+ ret->type = BuiltinType;
+ ret->builtin = builtin;
+ return ret;
}
~Expression();
@@ -886,6 +884,35 @@ struct Term
Term( FactorWithAug *factorWithAug ) :
term(0), factorWithAug(factorWithAug), type(FactorWithAugType) { }
+
+ Term() :
+ term(0), factorWithAug(0), type((Type)-1) { }
+
+ Term *cons( Term *term, FactorWithAug *factorWithAug )
+ {
+ Term *ret = new Term;
+ ret->term = term;
+ ret->factorWithAug = factorWithAug;
+ ret->type = ConcatType;
+ return ret;
+ }
+
+ Term *cons( Term *term, FactorWithAug *factorWithAug, Type type )
+ {
+ Term *ret = new Term;
+ ret->type = type;
+ ret->term = term;
+ ret->factorWithAug = factorWithAug;
+ return ret;
+ }
+
+ Term *cons( FactorWithAug *factorWithAug )
+ {
+ Term *ret = new Term;
+ ret->type = FactorWithAugType;
+ ret->factorWithAug = factorWithAug;
+ return term;
+ }
~Term();