diff options
author | Adrian Thurston <thurston@complang.org> | 2015-02-13 23:32:07 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-02-13 23:32:07 -0500 |
commit | c61aaeda6a00d6133cd8042c6a978291ddd44bec (patch) | |
tree | 5ddb55cfd20ccb1b8cd5ed309de75743f0012428 | |
parent | 3151be71170cd2ac01567d6277ccf5019a647bc9 (diff) | |
download | colm-c61aaeda6a00d6133cd8042c6a978291ddd44bec.tar.gz |
cleanup of the GenericType struct
-rw-r--r-- | src/compiler.h | 1 | ||||
-rw-r--r-- | src/declare.cc | 72 | ||||
-rw-r--r-- | src/map.h | 1 | ||||
-rw-r--r-- | src/parsetree.h | 20 | ||||
-rw-r--r-- | src/pdabuild.cc | 10 | ||||
-rw-r--r-- | src/resolve.cc | 19 | ||||
-rw-r--r-- | src/synthesis.cc | 4 |
7 files changed, 58 insertions, 69 deletions
diff --git a/src/compiler.h b/src/compiler.h index e7ba7bff..a79af2d6 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -807,7 +807,6 @@ struct Compiler void resolveTranslateBlock( LangEl *langEl ); void resolveReductionCode( Production *prod ); void resolveParseTree(); - void resolveGenericTypes(); void compileFunction( Function *func, CodeVect &code ); void compileFunction( Function *func ); diff --git a/src/declare.cc b/src/declare.cc index 386a0638..b5ca8efd 100644 --- a/src/declare.cc +++ b/src/declare.cc @@ -354,10 +354,10 @@ void Compiler::addProdRHSVars( ObjectDef *localFrame, ProdElList *prodElList ) void GenericType::declare( Compiler *pd, Namespace *nspace ) { - utArg = typeArg->uniqueType; + elUt = elTr->uniqueType; if ( typeId == GEN_MAP || typeId == GEN_VMAP ) - keyUT = keyTypeArg->uniqueType; + keyUt = keyTr->uniqueType; objDef = ObjectDef::cons( ObjectDef::BuiltinType, "generic", pd->nextObjectId++ ); @@ -384,7 +384,7 @@ void GenericType::declare( Compiler *pd, Namespace *nspace ) pd->initListElFields( this ); break; case GEN_PARSER: - utArg->langEl->parserId = pd->nextParserId++; + elUt->langEl->parserId = pd->nextParserId++; pd->initParserFunctions( this ); pd->initParserFields( this ); break; @@ -1034,34 +1034,34 @@ void Compiler::addError() void Compiler::initMapFunctions( GenericType *gen ) { - initFunction( gen->utArg, gen->objDef, "find", - IN_MAP_FIND, IN_MAP_FIND, gen->keyUT, true, true, gen ); + initFunction( gen->elUt, gen->objDef, "find", + IN_MAP_FIND, IN_MAP_FIND, gen->keyUt, true, true, gen ); initFunction( uniqueTypeInt, gen->objDef, "insert", - IN_MAP_INSERT_WV, IN_MAP_INSERT_WC, gen->utArg, false, true, gen ); + IN_MAP_INSERT_WV, IN_MAP_INSERT_WC, gen->elUt, false, true, gen ); - initFunction( gen->utArg, gen->objDef, "detach", - IN_MAP_DETACH_WV, IN_MAP_DETACH_WC, gen->utArg, false, true, gen ); + initFunction( gen->elUt, gen->objDef, "detach", + IN_MAP_DETACH_WV, IN_MAP_DETACH_WC, gen->elUt, false, true, gen ); } void Compiler::initValueMapFunctions( GenericType *gen ) { - initFunction( gen->valueUT, gen->objDef, "find", - IN_VMAP_FIND, IN_VMAP_FIND, gen->keyUT, true, true, gen ); + initFunction( gen->valueUt, gen->objDef, "find", + IN_VMAP_FIND, IN_VMAP_FIND, gen->keyUt, true, true, gen ); initFunction( uniqueTypeInt, gen->objDef, "insert", - IN_VMAP_INSERT_WV, IN_VMAP_INSERT_WC, gen->keyUT, gen->valueUT, + IN_VMAP_INSERT_WV, IN_VMAP_INSERT_WC, gen->keyUt, gen->valueUt, false, true, gen ); - initFunction( gen->utArg, gen->objDef, "remove", - IN_VMAP_REMOVE_WV, IN_VMAP_REMOVE_WC, gen->keyUT, false, true, gen ); + initFunction( gen->elUt, gen->objDef, "remove", + IN_VMAP_REMOVE_WV, IN_VMAP_REMOVE_WC, gen->keyUt, false, true, gen ); } void Compiler::initMapField( GenericType *gen, const char *name, int offset ) { /* Make the type ref and create the field. */ ObjectField *el = ObjectField::cons( internal, - ObjectField::InbuiltOffType, gen->typeArg, name ); + ObjectField::InbuiltOffType, gen->elTr, name ); el->inGetR = IN_GET_MAP_MEM_R; el->inGetWC = IN_GET_MAP_MEM_WC; @@ -1102,21 +1102,21 @@ void Compiler::initMapElKey( GenericType *gen, const char *name, int offset ) { /* Make the type ref and create the field. */ ObjectField *el = ObjectField::cons( internal, - ObjectField::GenericDependentType, gen->keyTypeArg, name ); + ObjectField::GenericDependentType, gen->keyTr, name ); gen->el->mapKeyField = el; /* Offset will be computed when the offset of the owning map element field * is computed. */ - gen->utArg->structEl->structDef->objectDef->rootScope->insertField( el->name, el ); + gen->elUt->structEl->structDef->objectDef->rootScope->insertField( el->name, el ); } void Compiler::initMapElField( GenericType *gen, const char *name, int offset ) { /* Make the type ref and create the field. */ ObjectField *el = ObjectField::cons( internal, - ObjectField::InbuiltOffType, gen->typeArg, name ); + ObjectField::InbuiltOffType, gen->elTr, name ); el->inGetR = IN_GET_MAP_EL_MEM_R; el->inGetValR = IN_GET_MAP_EL_MEM_R; @@ -1131,7 +1131,7 @@ void Compiler::initMapElField( GenericType *gen, const char *name, int offset ) /* Zero for head, One for tail. */ el->offset = offset; - gen->utArg->structEl->structDef->objectDef->rootScope->insertField( el->name, el ); + gen->elUt->structEl->structDef->objectDef->rootScope->insertField( el->name, el ); } void Compiler::initMapElFields( GenericType *gen ) @@ -1145,42 +1145,42 @@ void Compiler::initMapElFields( GenericType *gen ) void Compiler::initListFunctions( GenericType *gen ) { initFunction( uniqueTypeInt, gen->objDef, "push_head", - IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->utArg, false, true, gen ); + IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->elUt, false, true, gen ); initFunction( uniqueTypeInt, gen->objDef, "push_tail", - IN_LIST_PUSH_TAIL_WV, IN_LIST_PUSH_TAIL_WC, gen->utArg, false, true, gen ); + IN_LIST_PUSH_TAIL_WV, IN_LIST_PUSH_TAIL_WC, gen->elUt, false, true, gen ); initFunction( uniqueTypeInt, gen->objDef, "push", - IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->utArg, false, true, gen ); + IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->elUt, false, true, gen ); - initFunction( gen->utArg, gen->objDef, "pop_head", + initFunction( gen->elUt, gen->objDef, "pop_head", IN_LIST_POP_HEAD_WV, IN_LIST_POP_HEAD_WC, false, true, gen ); - initFunction( gen->utArg, gen->objDef, "pop_tail", + initFunction( gen->elUt, gen->objDef, "pop_tail", IN_LIST_POP_TAIL_WV, IN_LIST_POP_TAIL_WC, false, true, gen ); - initFunction( gen->utArg, gen->objDef, "pop", + initFunction( gen->elUt, gen->objDef, "pop", IN_LIST_POP_HEAD_WV, IN_LIST_POP_HEAD_WC, false, true, gen ); } void Compiler::initValueListFunctions( GenericType *gen ) { initFunction( uniqueTypeInt, gen->objDef, "push_head", - IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->utArg, false, true, gen ); + IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->elUt, false, true, gen ); initFunction( uniqueTypeInt, gen->objDef, "push_tail", - IN_LIST_PUSH_TAIL_WV, IN_LIST_PUSH_TAIL_WC, gen->utArg, false, true, gen ); + IN_LIST_PUSH_TAIL_WV, IN_LIST_PUSH_TAIL_WC, gen->elUt, false, true, gen ); initFunction( uniqueTypeInt, gen->objDef, "push", - IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->utArg, false, true, gen ); + IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->elUt, false, true, gen ); - initFunction( gen->utArg, gen->objDef, "pop_head", + initFunction( gen->elUt, gen->objDef, "pop_head", IN_LIST_POP_HEAD_WV, IN_LIST_POP_HEAD_WC, false, true, gen ); - initFunction( gen->utArg, gen->objDef, "pop_tail", + initFunction( gen->elUt, gen->objDef, "pop_tail", IN_LIST_POP_TAIL_WV, IN_LIST_POP_TAIL_WC, false, true, gen ); - initFunction( gen->utArg, gen->objDef, "pop", + initFunction( gen->elUt, gen->objDef, "pop", IN_LIST_POP_HEAD_WV, IN_LIST_POP_HEAD_WC, false, true, gen ); } @@ -1188,7 +1188,7 @@ void Compiler::initListElField( GenericType *gen, const char *name, int offset ) { /* Make the type ref and create the field. */ ObjectField *el = ObjectField::cons( internal, - ObjectField::InbuiltOffType, gen->typeArg, name ); + ObjectField::InbuiltOffType, gen->elTr, name ); el->inGetR = IN_GET_LIST_EL_MEM_R; el->inGetValR = IN_GET_LIST_EL_MEM_R; @@ -1203,7 +1203,7 @@ void Compiler::initListElField( GenericType *gen, const char *name, int offset ) /* Zero for head, One for tail. */ el->offset = offset; - gen->utArg->structEl->structDef->objectDef->rootScope->insertField( el->name, el ); + gen->elUt->structEl->structDef->objectDef->rootScope->insertField( el->name, el ); } void Compiler::initListElFields( GenericType *gen ) @@ -1218,7 +1218,7 @@ void Compiler::initListField( GenericType *gen, const char *name, int offset ) { /* Make the type ref and create the field. */ ObjectField *el = ObjectField::cons( internal, - ObjectField::InbuiltOffType, gen->typeArg, name ); + ObjectField::InbuiltOffType, gen->elTr, name ); el->inGetR = IN_GET_LIST_MEM_R; el->inGetWC = IN_GET_LIST_MEM_WC; @@ -1255,10 +1255,10 @@ void Compiler::initValueListFields( GenericType *gen ) void Compiler::initParserFunctions( GenericType *gen ) { - initFunction( gen->utArg, gen->objDef, "finish", + initFunction( gen->elUt, gen->objDef, "finish", IN_PARSE_FINISH_WV, IN_PARSE_FINISH_WC, true ); - initFunction( gen->utArg, gen->objDef, "eof", + initFunction( gen->elUt, gen->objDef, "eof", IN_PARSE_FINISH_WV, IN_PARSE_FINISH_WC, true ); } @@ -1285,7 +1285,7 @@ void Compiler::initParserFields( GenericType *gen ) { TypeRef *typeRef; - typeRef = TypeRef::cons( internal, gen->utArg ); + typeRef = TypeRef::cons( internal, gen->elUt ); initParserField( gen, "tree", 0, typeRef ); typeRef = TypeRef::cons( internal, uniqueTypeStr ); @@ -71,6 +71,7 @@ MapEl *colm_map_find( Program *prg, Map *map, Tree *key ); MapEl *colm_vmap_insert( Program *prg, Map *map, Struct *key, Struct *value ); MapEl *colm_vmap_remove( Program *prg, Map *map, Tree *key ); Tree *colm_map_iter_advance( Program *prg, Tree ***psp, ListIter *iter ); +Tree *colm_vmap_find( Program *prg, Map *map, Tree *key ); #if defined(__cplusplus) } diff --git a/src/parsetree.h b/src/parsetree.h index fe8fed7d..377cba4d 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -727,12 +727,11 @@ typedef Vector<Namespace*> NamespaceVect; struct GenericType : public DListEl<GenericType> { - GenericType( long typeId, long id, - TypeRef *typeArg ) + GenericType( long typeId, long id, TypeRef *elTr ) : typeId(typeId), id(id), - typeArg(typeArg), keyTypeArg(0), - utArg(0), keyUT(0), valueUT(0), + elTr(elTr), keyTr(0), + elUt(0), keyUt(0), valueUt(0), objDef(0), el(0), elOffset(0) {} @@ -740,11 +739,14 @@ struct GenericType long typeId; long id; - TypeRef *typeArg; - TypeRef *keyTypeArg; - UniqueType *utArg; - UniqueType *keyUT; - UniqueType *valueUT; + + TypeRef *elTr; + TypeRef *keyTr; + + UniqueType *elUt; + UniqueType *keyUt; + UniqueType *valueUt; + ObjectDef *objDef; ObjectField *el; long elOffset; diff --git a/src/pdabuild.cc b/src/pdabuild.cc index 96f601d9..91eaff75 100644 --- a/src/pdabuild.cc +++ b/src/pdabuild.cc @@ -1573,16 +1573,16 @@ void Compiler::makeRuntimeData() for ( NamespaceList::Iter nspace = namespaceList; nspace.lte(); nspace++ ) { for ( GenericList::Iter gen = nspace->genericList; gen.lte(); gen++ ) { runtimeData->genericInfo[gen->id].type = gen->typeId; - runtimeData->genericInfo[gen->id].typeArg = gen->utArg->typeId; - runtimeData->genericInfo[gen->id].keyType = gen->keyUT != 0 ? - gen->keyUT->typeId : 0; + runtimeData->genericInfo[gen->id].typeArg = gen->elUt->typeId; + runtimeData->genericInfo[gen->id].keyType = gen->keyUt != 0 ? + gen->keyUt->typeId : 0; runtimeData->genericInfo[gen->id].keyOffset = 0; runtimeData->genericInfo[gen->id].parserId = - gen->typeId == GEN_PARSER ? gen->utArg->langEl->parserId : -1; + gen->typeId == GEN_PARSER ? gen->elUt->langEl->parserId : -1; runtimeData->genericInfo[gen->id].elOffset = gen->el != 0 ? gen->el->offset : -1; runtimeData->genericInfo[gen->id].elStructId = - gen->typeId == GEN_VMAP ? gen->utArg->structEl->id : -1; + gen->typeId == GEN_VMAP ? gen->elUt->structEl->id : -1; runtimeData->genericInfo[gen->id].valueOffset = 0; } } diff --git a/src/resolve.cc b/src/resolve.cc index 0b2a4489..3e5ebeb0 100644 --- a/src/resolve.cc +++ b/src/resolve.cc @@ -223,7 +223,7 @@ UniqueType *TypeRef::resolveTypeMap( Compiler *pd ) GenericType *generic = new GenericType( GEN_MAP, pd->nextGenericId++, typeRef2 ); - generic->keyTypeArg = typeRef1; + generic->keyTr = typeRef1; generic->el = mapEl; nspace->genericList.append( generic ); @@ -347,9 +347,9 @@ UniqueType *TypeRef::resolveTypeValueMap( Compiler *pd ) GenericType *generic = new GenericType( GEN_VMAP, pd->nextGenericId++, typeRef2 ); - generic->keyTypeArg = typeRef1; + generic->keyTr = typeRef1; generic->el = mapEl; - generic->valueUT = utValue; + generic->valueUt = utValue; nspace->genericList.append( generic ); @@ -887,19 +887,6 @@ void Compiler::resolveProductionEls() } } -/* Is this necessary? */ -void Compiler::resolveGenericTypes() -{ - for ( NamespaceList::Iter ns = namespaceList; ns.lte(); ns++ ) { - for ( GenericList::Iter gen = ns->genericList; gen.lte(); gen++ ) { - gen->utArg = gen->typeArg->resolveType( this ); - - if ( gen->typeId == GEN_MAP ) - gen->keyUT = gen->keyTypeArg->resolveType( this ); - } - } -} - void Compiler::makeTerminalWrappers() { /* Make terminal language elements corresponding to each nonterminal in diff --git a/src/synthesis.cc b/src/synthesis.cc index 8cea9831..095703ff 100644 --- a/src/synthesis.cc +++ b/src/synthesis.cc @@ -1155,7 +1155,7 @@ UniqueType *LangTerm::evaluateNew( Compiler *pd, CodeVect &code ) const bool context = false; if ( newUT->typeId == TYPE_GENERIC && newUT->generic->typeId == GEN_PARSER && - newUT->generic->utArg->langEl->contextIn != 0 ) + newUT->generic->elUt->langEl->contextIn != 0 ) { if ( fieldInitArgs == 0 || fieldInitArgs->length() != 1 ) error(loc) << "parse command requires just input" << endp; @@ -1306,7 +1306,7 @@ UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code, bool tree, bool stop ) const { UniqueType *parserUT = typeRef->uniqueType; - UniqueType *targetUT = parserUT->generic->utArg; + UniqueType *targetUT = parserUT->generic->elUt; /* If this is a parse stop then we need to verify that the type is * compatible with parse stop. */ |