summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2011-07-07 01:41:42 +0000
committerAdrian Thurston <thurston@complang.org>2011-07-07 01:41:42 +0000
commit587232ded3f23b10b87d744d9fd4d5605b1fd2b8 (patch)
treef4964f5748144aad17924de23a45c4b5f913da56
parent99462cb6687354fd12ae0859848c482ae5358f8a (diff)
downloadcolm-587232ded3f23b10b87d744d9fd4d5605b1fd2b8.tar.gz
Some class renaming and minor cleanup.
-rw-r--r--colm/declare.cc4
-rw-r--r--colm/lmparse.kl22
-rw-r--r--colm/parsedata.cc12
-rw-r--r--colm/parsedata.h25
-rw-r--r--colm/parsetree.h14
-rw-r--r--colm/pdabuild.cc2
-rw-r--r--colm/resolve.cc71
7 files changed, 75 insertions, 75 deletions
diff --git a/colm/declare.cc b/colm/declare.cc
index 2a918f9e..311ac86c 100644
--- a/colm/declare.cc
+++ b/colm/declare.cc
@@ -153,7 +153,7 @@ void ParseData::addProdRHSVars( ObjectDef *localFrame, ProdElList *prodElList )
{
long position = 1;
for ( ProdElList::Iter rhsEl = *prodElList; rhsEl.lte(); rhsEl++, position++ ) {
- if ( rhsEl->type == PdaFactor::ReferenceType ) {
+ if ( rhsEl->type == ProdEl::ReferenceType ) {
TypeRef *typeRef = new TypeRef( rhsEl->loc, rhsEl->nspaceQual, rhsEl->refName );
/* Use an offset of zero. For frame objects we compute the offset on
@@ -179,7 +179,7 @@ void ParseData::addProdRHSLoads( Definition *prod, CodeVect &code, long &insertP
CodeVect loads;
long elPos = 0;
for ( ProdElList::Iter rhsEl = *prod->prodElList; rhsEl.lte(); rhsEl++, elPos++ ) {
- if ( rhsEl->type == PdaFactor::ReferenceType ) {
+ if ( rhsEl->type == ProdEl::ReferenceType ) {
if ( rhsEl->objField->beenReferenced ) {
loads.append ( IN_INIT_RHS_EL );
loads.appendHalf( elPos );
diff --git a/colm/lmparse.kl b/colm/lmparse.kl
index 972e0bb2..82d37e9e 100644
--- a/colm/lmparse.kl
+++ b/colm/lmparse.kl
@@ -282,13 +282,13 @@ pred_token_list: pred_token
nonterm pred_token
{
- PdaFactor *factor;
+ ProdEl *factor;
};
pred_token:
region_qual TK_Word
final {
- $$->factor = new PdaFactor( $2->loc, false, $1->nspaceQual,
+ $$->factor = new ProdEl( $2->loc, false, $1->nspaceQual,
$2->data, 0, RepeatNone, false, false );
pd->resolveReferenceFactor( $$->factor );
};
@@ -297,7 +297,7 @@ pred_token:
region_qual TK_Literal
final {
PdaLiteral *literal = new PdaLiteral( $2->loc, *$2 );
- $$->factor = new PdaFactor( $2->loc, false, $1->nspaceQual,
+ $$->factor = new ProdEl( $2->loc, false, $1->nspaceQual,
literal, 0, RepeatNone, false, false );
pd->resolveLiteralFactor( $$->factor );
};
@@ -638,7 +638,7 @@ nonterm pattern_el_type_or_lit
pattern_el_type_or_lit: region_qual TK_Word opt_repeat
final {
- PdaFactor *factor = new PdaFactor( $2->loc, false, $1->nspaceQual,
+ ProdEl *factor = new ProdEl( $2->loc, false, $1->nspaceQual,
$2->data, 0, $3->repeatType, $3->opt, $3->repeat );
$$->patternItem = new PatternItem( $2->loc, factor, PatternItem::FactorType );
patternItemList->append( $$->patternItem );
@@ -647,7 +647,7 @@ pattern_el_type_or_lit: region_qual TK_Word opt_repeat
pattern_el_type_or_lit: region_qual TK_Literal opt_repeat
final {
PdaLiteral *literal = new PdaLiteral( $2->loc, *$2 );
- PdaFactor *factor = new PdaFactor( $2->loc, false, $1->nspaceQual,
+ ProdEl *factor = new ProdEl( $2->loc, false, $1->nspaceQual,
literal, 0, $3->repeatType, $3->opt, $3->repeat );
$$->patternItem = new PatternItem( $2->loc, factor, PatternItem::FactorType );
patternItemList->append( $$->patternItem );
@@ -700,7 +700,7 @@ repl_el_list: ;
repl_el: region_qual TK_Literal
final {
PdaLiteral *literal = new PdaLiteral( $2->loc, *$2 );
- PdaFactor *factor = new PdaFactor( $2->loc, false, $1->nspaceQual,
+ ProdEl *factor = new ProdEl( $2->loc, false, $1->nspaceQual,
literal, 0, RepeatNone, false, false );
ReplItem *replItem = new ReplItem( $2->loc, ReplItem::FactorType, factor );
replItemList->append( replItem );
@@ -751,7 +751,7 @@ accum_el_list: ;
#accum_el: region_qual TK_Literal
# final {
# PdaLiteral *literal = new PdaLiteral( $2->loc, *$2 );
-# PdaFactor *factor = new PdaFactor( $2->loc, false, $1->nspaceQual,
+# ProdEl *factor = new ProdEl( $2->loc, false, $1->nspaceQual,
# literal, 0, RepeatNone, false, false );
# ReplItem *replItem = new ReplItem( $2->loc, ReplItem::FactorType, factor );
# replItemList->append( replItem );
@@ -797,7 +797,7 @@ string_el_list: ;
#accum_el: region_qual TK_Literal
# final {
# PdaLiteral *literal = new PdaLiteral( $2->loc, *$2 );
-# PdaFactor *factor = new PdaFactor( $2->loc, false, $1->nspaceQual,
+# ProdEl *factor = new ProdEl( $2->loc, false, $1->nspaceQual,
# literal, 0, RepeatNone, false, false );
# ReplItem *replItem = new ReplItem( $2->loc, ReplItem::FactorType, factor );
# replItemList->append( replItem );
@@ -821,13 +821,13 @@ prod_el_list:
nonterm prod_el
{
- PdaFactor *factor;
+ ProdEl *factor;
};
prod_el:
opt_commit region_qual TK_Word opt_repeat
final {
- $$->factor = new PdaFactor( $3->loc, $1->commit,
+ $$->factor = new ProdEl( $3->loc, $1->commit,
$2->nspaceQual, $3->data, 0, $4->repeatType, $4->opt, $4->repeat );
};
@@ -836,7 +836,7 @@ prod_el:
final {
/* Create a new factor node going to a concat literal. */
PdaLiteral *literal = new PdaLiteral( $3->loc, *$3 );
- $$->factor = new PdaFactor( $3->loc, $1->commit, $2->nspaceQual,
+ $$->factor = new ProdEl( $3->loc, $1->commit, $2->nspaceQual,
literal, 0, $4->repeatType, $4->opt, $4->repeat );
};
diff --git a/colm/parsedata.cc b/colm/parsedata.cc
index 7631202a..58fcb95c 100644
--- a/colm/parsedata.cc
+++ b/colm/parsedata.cc
@@ -1127,9 +1127,9 @@ KlangEl *ParseData::makeRepeatProd( Namespace *nspace, const String &repeatName,
ProdElList *prodElList1 = new ProdElList;
/* Build the first production of the repeat. */
- PdaFactor *factor1 = new PdaFactor( InputLoc(), false, nspaceQual,
+ ProdEl *factor1 = new ProdEl( InputLoc(), false, nspaceQual,
name, 0, RepeatNone, false, false );
- PdaFactor *factor2 = new PdaFactor( InputLoc(), false, nspaceQual,
+ ProdEl *factor2 = new ProdEl( InputLoc(), false, nspaceQual,
repeatName, 0, RepeatNone, false, false );
prodElList1->append( factor1 );
@@ -1162,9 +1162,9 @@ KlangEl *ParseData::makeListProd( Namespace *nspace, const String &listName, Nam
prodName->isList = true;
/* Build the first production of the list. */
- PdaFactor *factor1 = new PdaFactor( InputLoc(), false, nspaceQual,
+ ProdEl *factor1 = new ProdEl( InputLoc(), false, nspaceQual,
name, 0, RepeatNone, false, false );
- PdaFactor *factor2 = new PdaFactor( InputLoc(), false, nspaceQual,
+ ProdEl *factor2 = new ProdEl( InputLoc(), false, nspaceQual,
listName, 0, RepeatNone, false, false );
ProdElList *prodElList1 = new ProdElList;
@@ -1179,7 +1179,7 @@ KlangEl *ParseData::makeListProd( Namespace *nspace, const String &listName, Nam
prodList.append( newDef1 );
/* Build the second production of the list. */
- PdaFactor *factor3 = new PdaFactor( InputLoc(), false, nspaceQual,
+ ProdEl *factor3 = new ProdEl( InputLoc(), false, nspaceQual,
name, 0, RepeatNone, false, false );
ProdElList *prodElList2 = new ProdElList;
@@ -1204,7 +1204,7 @@ KlangEl *ParseData::makeOptProd( Namespace *nspace, const String &optName, Names
ProdElList *prodElList1 = new ProdElList;
/* Build the first production of the repeat. */
- PdaFactor *factor1 = new PdaFactor( InputLoc(), false, nspaceQual,
+ ProdEl *factor1 = new ProdEl( InputLoc(), false, nspaceQual,
name, 0, RepeatNone, false, false );
prodElList1->append( factor1 );
diff --git a/colm/parsedata.h b/colm/parsedata.h
index 4b983211..5370134d 100644
--- a/colm/parsedata.h
+++ b/colm/parsedata.h
@@ -66,7 +66,7 @@ inline long makeReduceCode( long reduction, bool isShiftReduce )
( reduction << 2 );
}
-struct PdaFactor;
+struct ProdEl;
struct ProdElList;
struct PdaLiteral;
struct Definition;
@@ -81,7 +81,7 @@ struct Bindings
struct DefListEl { Definition *prev, *next; };
struct LelDefListEl { Definition *prev, *next; };
typedef Vector< KlangEl* > KlangElVect;
-typedef Vector< PdaFactor* > FactorVect;
+typedef Vector< ProdEl* > FactorVect;
typedef AvlMap<String, long, CmpStr> StringMap;
typedef AvlMapEl<String, long> StringMapEl;
@@ -237,7 +237,7 @@ struct KlangEl : public DListEl<KlangEl>
Context *contextIn;
};
-struct PdaFactor
+struct ProdEl
{
/* Language elements a factor node can be. */
enum Type {
@@ -246,25 +246,25 @@ struct PdaFactor
};
/* Construct with a literal fsm. */
- PdaFactor( const InputLoc &loc, bool commit, NamespaceQual *nspaceQual,
+ ProdEl( const InputLoc &loc, bool commit, NamespaceQual *nspaceQual,
PdaLiteral *literal, int priorVal, RepeatType repeatType, bool opt, bool repeat ) :
loc(loc), commit(commit), nspaceQual(nspaceQual),
literal(literal), langEl(0), priorVal(priorVal), repeatType(repeatType),
nspace(0), type(LiteralType), objField(0) {}
/* Construct with a reference to a var def. */
- PdaFactor( const InputLoc &loc, bool commit, NamespaceQual *nspaceQual,
+ ProdEl( const InputLoc &loc, bool commit, NamespaceQual *nspaceQual,
const String &refName, int priorVal, RepeatType repeatType, bool opt, bool repeat ) :
loc(loc), commit(commit), nspaceQual(nspaceQual), refName(refName),
literal(0), langEl(0), priorVal(priorVal), repeatType(repeatType),
nspace(0), type(ReferenceType), objField(0) {}
- PdaFactor( const InputLoc &loc, KlangEl *langEl ) :
+ ProdEl( const InputLoc &loc, KlangEl *langEl ) :
loc(loc), commit(false), nspaceQual(0), literal(0), langEl(langEl),
priorVal(0), repeatType(RepeatNone), nspace(0),
type(ReferenceType), objField(0) {}
- PdaFactor() :
+ ProdEl() :
commit(false), nspaceQual(0),
literal(0), langEl(0), priorVal(0), repeatType(RepeatNone),
nspace(0), type(LiteralType), objField(0) {}
@@ -280,11 +280,10 @@ struct PdaFactor
Namespace *nspace;
Type type;
ObjField *objField;
-
- PdaFactor *prev, *next;
+ ProdEl *prev, *next;
};
-struct ProdElList : public DList<PdaFactor>
+struct ProdElList : public DList<ProdEl>
{
PdaGraph *walk( ParseData *pd );
};
@@ -723,9 +722,9 @@ struct ParseData
NamespaceQual *nspaceQual, const String &name );
KlangEl *makeOptProd( Namespace *nspace, const String &optName,
NamespaceQual *nspaceQual, const String &name );
- void resolveLiteralFactor( PdaFactor *fact );
- void resolveReferenceFactor( PdaFactor *fact );
- void resolveFactor( PdaFactor *fact );
+ void resolveLiteralFactor( ProdEl *fact );
+ void resolveReferenceFactor( ProdEl *fact );
+ void resolveFactor( ProdEl *fact );
void resolveProductionEls();
void resolvePatternEls();
void resolveReplacementEls();
diff --git a/colm/parsetree.h b/colm/parsetree.h
index 9ebafc5b..4324fe46 100644
--- a/colm/parsetree.h
+++ b/colm/parsetree.h
@@ -1076,7 +1076,7 @@ struct InlineItem
* ptreetypes, which should be just typedef forwards. */
struct InlineList : public DList<InlineItem> { };
-struct PdaFactor;
+struct ProdEl;
struct LangVarRef;
struct ObjField;
@@ -1091,12 +1091,12 @@ struct PatternItem
loc(loc), factor(0), data(data), type(type), region(0),
varRef(0), bindId(0) {}
- PatternItem( const InputLoc &loc, PdaFactor *factor, Type type ) :
+ PatternItem( const InputLoc &loc, ProdEl *factor, Type type ) :
loc(loc), factor(factor), type(type), region(0),
varRef(0), bindId(0) {}
InputLoc loc;
- PdaFactor *factor;
+ ProdEl *factor;
String data;
Type type;
TokenRegion *region;
@@ -1123,7 +1123,7 @@ struct ReplItem
ReplItem( const InputLoc &loc, Type type, LangExpr *expr ) :
loc(loc), type(type), expr(expr), bindId(0) {}
- ReplItem( const InputLoc &loc, Type type, PdaFactor *factor ) :
+ ReplItem( const InputLoc &loc, Type type, ProdEl *factor ) :
loc(loc), type(type), expr(expr), factor(factor), bindId(0) {}
InputLoc loc;
@@ -1131,7 +1131,7 @@ struct ReplItem
String data;
LangExpr *expr;
KlangEl *langEl;
- PdaFactor *factor;
+ ProdEl *factor;
long bindId;
ReplItem *prev, *next;
@@ -1358,7 +1358,7 @@ struct TypeRef
/* A factor in a pattern. In the case of matches we need a type ref at
* parse time, but factors have not been resolved yet, so this allows us
* to do it on demand. */
- TypeRef( const InputLoc &loc, NamespaceQual *nspaceQual, PdaFactor *factor ) :
+ TypeRef( const InputLoc &loc, NamespaceQual *nspaceQual, ProdEl *factor ) :
loc(loc), nspaceQual(nspaceQual), iterDef(0), factor(factor),
isPtr(false), isRef(false), repeatType(RepeatNone),
uniqueType(0), searchUniqueType(0) {}
@@ -1372,7 +1372,7 @@ struct TypeRef
NamespaceQual *nspaceQual;
String typeName;
IterDef *iterDef;
- PdaFactor *factor;
+ ProdEl *factor;
bool isPtr;
bool isRef;
RepeatType repeatType;
diff --git a/colm/pdabuild.cc b/colm/pdabuild.cc
index 03140dd4..600301da 100644
--- a/colm/pdabuild.cc
+++ b/colm/pdabuild.cc
@@ -147,7 +147,7 @@ KlangEl *getKlangEl( ParseData *pd, Namespace *nspace, const String &data )
ProdElList *makeProdElList( KlangEl *langEl )
{
ProdElList *prodElList = new ProdElList();
- prodElList->append( new PdaFactor( InputLoc(), langEl ) );
+ prodElList->append( new ProdEl( InputLoc(), langEl ) );
prodElList->tail->langEl = langEl;
return prodElList;
}
diff --git a/colm/resolve.cc b/colm/resolve.cc
index 4d327f46..2a1c5cc3 100644
--- a/colm/resolve.cc
+++ b/colm/resolve.cc
@@ -53,36 +53,6 @@ UniqueType *TypeRef::lookupTypePart( ParseData *pd,
return 0;
}
-UniqueType *TypeRef::lookupType( ParseData *pd )
-{
- if ( uniqueType != 0 )
- return uniqueType;
-
- sugaredDecls( pd );
-
-// cout << __PRETTY_FUNCTION__ << " " << typeName.data << " " << this << endl;
-
- if ( iterDef != 0 )
- uniqueType = pd->findUniqueType( TYPE_ITER, iterDef );
- else if ( factor != 0 )
- uniqueType = pd->findUniqueType( TYPE_TREE, factor->langEl );
- else {
- String name = typeName;
- if ( repeatType == RepeatOpt )
- name.setAs( 32, "_opt_%s", name.data );
- else if ( repeatType == RepeatRepeat )
- name.setAs( 32, "_repeat_%s", name.data );
- else if ( repeatType == RepeatList )
- name.setAs( 32, "_list_%s", name.data );
-
- /* Not an iterator. May be a reference. */
- uniqueType = lookupTypePart( pd, nspaceQual, name );
- }
-
- return uniqueType;
-}
-
-
void TypeRef::sugaredDecls( ParseData *pd ) const
{
/* Look for the production's associated region. */
@@ -120,6 +90,37 @@ void TypeRef::sugaredDecls( ParseData *pd ) const
}
}
+
+UniqueType *TypeRef::lookupType( ParseData *pd )
+{
+ if ( uniqueType != 0 )
+ return uniqueType;
+
+ sugaredDecls( pd );
+
+// cout << __PRETTY_FUNCTION__ << " " << typeName.data << " " << this << endl;
+// if ( iterDef != 0 )
+// uniqueType = pd->findUniqueType( TYPE_ITER, iterDef );
+
+ if ( factor != 0 )
+ uniqueType = pd->findUniqueType( TYPE_TREE, factor->langEl );
+ else {
+ String name = typeName;
+ if ( repeatType == RepeatOpt )
+ name.setAs( 32, "_opt_%s", name.data );
+ else if ( repeatType == RepeatRepeat )
+ name.setAs( 32, "_repeat_%s", name.data );
+ else if ( repeatType == RepeatList )
+ name.setAs( 32, "_list_%s", name.data );
+
+ /* Not an iterator. May be a reference. */
+ uniqueType = lookupTypePart( pd, nspaceQual, name );
+ }
+
+ return uniqueType;
+}
+
+
void LangTerm::resolve( ParseData *pd ) const
{
switch ( type ) {
@@ -427,7 +428,7 @@ void ParseData::resolveUses()
}
}
-void ParseData::resolveLiteralFactor( PdaFactor *fact )
+void ParseData::resolveLiteralFactor( ProdEl *fact )
{
/* Interpret escape sequences and remove quotes. */
bool unusedCI;
@@ -451,7 +452,7 @@ void ParseData::resolveLiteralFactor( PdaFactor *fact )
fact->langEl = tokenDef->token;
}
-void ParseData::resolveReferenceFactor( PdaFactor *fact )
+void ParseData::resolveReferenceFactor( ProdEl *fact )
{
/* Look for the production's associated region. */
Namespace *nspace = fact->nspaceQual->getQual( this );
@@ -503,13 +504,13 @@ void ParseData::resolveReferenceFactor( PdaFactor *fact )
}
}
-void ParseData::resolveFactor( PdaFactor *fact )
+void ParseData::resolveFactor( ProdEl *fact )
{
switch ( fact->type ) {
- case PdaFactor::LiteralType:
+ case ProdEl::LiteralType:
resolveLiteralFactor( fact );
break;
- case PdaFactor::ReferenceType:
+ case ProdEl::ReferenceType:
resolveReferenceFactor( fact );
break;
}