diff options
author | Adrian Thurston <thurston@complang.org> | 2012-07-02 09:33:21 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-07-02 09:33:21 -0400 |
commit | a6a74ea14ef45682a4fdf665084c0b977902c379 (patch) | |
tree | 81db838c305eaa6987ef83f50c6e7caad46c9979 | |
parent | 1ec17c55a3bd0085c3ec38c7fbd344d425562660 (diff) | |
download | colm-a6a74ea14ef45682a4fdf665084c0b977902c379.tar.gz |
more static member constructor functions
-rw-r--r-- | src/lmparse.kl | 24 | ||||
-rw-r--r-- | src/parsetree.h | 49 |
2 files changed, 52 insertions, 21 deletions
diff --git a/src/lmparse.kl b/src/lmparse.kl index 26aad053..e49c1554 100644 --- a/src/lmparse.kl +++ b/src/lmparse.kl @@ -976,8 +976,8 @@ literal_item: opt_no_ignore TK_Literal opt_no_ignore if ( ldel != 0 ) error( $2->loc ) << "literal already defined in this namespace" << endp; else { - Join *join = new Join( Expression::cons( Term::cons( new FactorWithAug( - new FactorWithRep( $2->loc, FactorWithNeg::cons( $2->loc, Factor::cons( + Join *join = new Join( Expression::cons( Term::cons( FactorWithAug::cons( + FactorWithRep::cons( $2->loc, FactorWithNeg::cons( $2->loc, Factor::cons( new Literal( $2->loc, $2->data, Literal::LitString ) ) ) ) ) ) ) ); @@ -2211,7 +2211,7 @@ nonterm factor_with_aug factor_with_aug: factor_with_rep final { - $$->factorWithAug = new FactorWithAug( $1->factorWithRep ); + $$->factorWithAug = FactorWithAug::cons( $1->factorWithRep ); }; @@ -2225,47 +2225,47 @@ nonterm factor_with_rep factor_with_rep: factor_with_rep '*' final { - $$->factorWithRep = new FactorWithRep( $2->loc, $1->factorWithRep, + $$->factorWithRep = FactorWithRep::cons( $2->loc, $1->factorWithRep, 0, 0, FactorWithRep::StarType ); }; factor_with_rep: factor_with_rep TK_StarStar final { - $$->factorWithRep = new FactorWithRep( $2->loc, $1->factorWithRep, + $$->factorWithRep = FactorWithRep::cons( $2->loc, $1->factorWithRep, 0, 0, FactorWithRep::StarStarType ); }; factor_with_rep: factor_with_rep '?' final { - $$->factorWithRep = new FactorWithRep( $2->loc, $1->factorWithRep, + $$->factorWithRep = FactorWithRep::cons( $2->loc, $1->factorWithRep, 0, 0, FactorWithRep::OptionalType ); }; factor_with_rep: factor_with_rep '+' final { - $$->factorWithRep = new FactorWithRep( $2->loc, $1->factorWithRep, + $$->factorWithRep = FactorWithRep::cons( $2->loc, $1->factorWithRep, 0, 0, FactorWithRep::PlusType ); }; factor_with_rep: factor_with_rep '{' factor_rep_num '}' final { - $$->factorWithRep = new FactorWithRep( $2->loc, $1->factorWithRep, + $$->factorWithRep = FactorWithRep::cons( $2->loc, $1->factorWithRep, $3->rep, 0, FactorWithRep::ExactType ); }; factor_with_rep: factor_with_rep '{' ',' factor_rep_num '}' final { - $$->factorWithRep = new FactorWithRep( $2->loc, $1->factorWithRep, + $$->factorWithRep = FactorWithRep::cons( $2->loc, $1->factorWithRep, 0, $4->rep, FactorWithRep::MaxType ); }; factor_with_rep: factor_with_rep '{' factor_rep_num ',' '}' final { - $$->factorWithRep = new FactorWithRep( $2->loc, $1->factorWithRep, + $$->factorWithRep = FactorWithRep::cons( $2->loc, $1->factorWithRep, $3->rep, 0, FactorWithRep::MinType ); }; factor_with_rep: factor_with_rep '{' factor_rep_num ',' factor_rep_num '}' final { - $$->factorWithRep = new FactorWithRep( $2->loc, $1->factorWithRep, + $$->factorWithRep = FactorWithRep::cons( $2->loc, $1->factorWithRep, $3->rep, $5->rep, FactorWithRep::RangeType ); }; factor_with_rep: factor_with_neg final { - $$->factorWithRep = new FactorWithRep( + $$->factorWithRep = FactorWithRep::cons( $1->factorWithNeg->loc, $1->factorWithNeg ); }; diff --git a/src/parsetree.h b/src/parsetree.h index ee329108..608a783f 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -922,8 +922,17 @@ struct Term /* Third level of precedence. Augmenting nodes with actions and priorities. */ struct FactorWithAug { - FactorWithAug( FactorWithRep *factorWithRep ) : - priorDescs(0), factorWithRep(factorWithRep) { } + FactorWithAug() : + priorDescs(0), factorWithRep(0) { } + + static FactorWithAug *cons( FactorWithRep *factorWithRep ) + { + FactorWithAug *f = new FactorWithAug; + f->priorDescs = 0; + f->factorWithRep = factorWithRep; + return f; + } + ~FactorWithAug(); /* Tree traversal. */ @@ -961,14 +970,36 @@ struct FactorWithRep FactorWithNegType }; - FactorWithRep( const InputLoc &loc, FactorWithRep *factorWithRep, - int lowerRep, int upperRep, Type type ) : - loc(loc), factorWithRep(factorWithRep), - factorWithNeg(0), lowerRep(lowerRep), - upperRep(upperRep), type(type) { } + FactorWithRep() + : + factorWithRep(0), + factorWithNeg(0), + lowerRep(0), + upperRep(upperRep), + type((Type)-1) + { } + + static FactorWithRep *cons( const InputLoc &loc, FactorWithRep *factorWithRep, + int lowerRep, int upperRep, Type type ) + { + FactorWithRep *f = new FactorWithRep; + f->type = (type); + f->loc = (loc); + f->factorWithRep = (factorWithRep); + f->factorWithNeg = (0); + f->lowerRep = (lowerRep); + f->upperRep = (upperRep); + return f; + } - FactorWithRep( const InputLoc &loc, FactorWithNeg *factorWithNeg ) - : loc(loc), factorWithNeg(factorWithNeg), type(FactorWithNegType) { } + static FactorWithRep *cons( const InputLoc &loc, FactorWithNeg *factorWithNeg ) + { + FactorWithRep *f = new FactorWithRep; + f->type = FactorWithNegType; + f->loc = loc; + f->factorWithNeg = factorWithNeg; + return f; + } ~FactorWithRep(); |