summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2014-12-07 19:13:44 -0500
committerAdrian Thurston <thurston@complang.org>2014-12-07 19:13:44 -0500
commit17b04f1c8be3214286500b72141611a2db9e9796 (patch)
treefa549ea17e9260c36b4206c6edfa9ae386b24f60 /src
parent5b927d9ccf76631d5f1e9149d121f8704d373983 (diff)
downloadcolm-17b04f1c8be3214286500b72141611a2db9e9796.tar.gz
find the list element pointers instead assuming they are the first item
Diffstat (limited to 'src')
-rw-r--r--src/parsetree.cc6
-rw-r--r--src/parsetree.h10
-rw-r--r--src/pdabuild.cc1
-rw-r--r--src/pdacodegen.cc7
-rw-r--r--src/resolve.cc24
-rw-r--r--src/tree.c16
-rw-r--r--src/tree.h1
7 files changed, 44 insertions, 21 deletions
diff --git a/src/parsetree.cc b/src/parsetree.cc
index acb482d1..b7581b75 100644
--- a/src/parsetree.cc
+++ b/src/parsetree.cc
@@ -170,6 +170,12 @@ int CmpUniqueList2::compare( const UniqueList2 &ut1, const UniqueList2 &ut2 )
return -1;
else if ( ut1.value > ut2.value )
return 1;
+ else {
+ if ( ut1.attrOff < ut2.attrOff )
+ return -1;
+ else if ( ut1.attrOff > ut2.attrOff )
+ return 1;
+ }
return 0;
}
diff --git a/src/parsetree.h b/src/parsetree.h
index d1d78a6f..d5d5cd42 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -704,8 +704,7 @@ struct GenericType
:
name(name), typeId(typeId), id(id), langEl(langEl),
typeArg(typeArg), keyTypeArg(0),
- utArg(0), keyUT(0),
- objDef(0)
+ utArg(0), keyUT(0), objDef(0), elOffset(0)
{}
const String &getKey() const
@@ -721,8 +720,8 @@ struct GenericType
TypeRef *keyTypeArg;
UniqueType *utArg;
UniqueType *keyUT;
-
ObjectDef *objDef;
+ long elOffset;
};
typedef DList<GenericType> GenericList;
@@ -1969,10 +1968,11 @@ typedef AvlBasic< UniqueList2El, CmpUniqueList2El > UniqueList2ElMap;
struct UniqueList2
: public AvlTreeEl<UniqueList2>
{
- UniqueList2( UniqueType *value ) :
- value(value), generic(0) {}
+ UniqueList2( UniqueType *value, int attrOff ) :
+ value(value), attrOff(attrOff), generic(0) {}
UniqueType *value;
+ int attrOff;
GenericType *generic;
};
diff --git a/src/pdabuild.cc b/src/pdabuild.cc
index 8472ab44..d7e642da 100644
--- a/src/pdabuild.cc
+++ b/src/pdabuild.cc
@@ -1515,6 +1515,7 @@ void Compiler::makeRuntimeData()
runtimeData->genericInfo[gen->id].keyOffset = 0;
runtimeData->genericInfo[gen->id].langElId = gen->langEl->id;
runtimeData->genericInfo[gen->id].parserId = gen->utArg->langEl->parserId;
+ runtimeData->genericInfo[gen->id].elOffset = gen->elOffset;
}
}
diff --git a/src/pdacodegen.cc b/src/pdacodegen.cc
index b420ab82..056b569b 100644
--- a/src/pdacodegen.cc
+++ b/src/pdacodegen.cc
@@ -348,9 +348,10 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData, PdaTables *pdaTable
runtimeData->genericInfo[i].type << ", " <<
runtimeData->genericInfo[i].typeArg << ", " <<
runtimeData->genericInfo[i].keyOffset << ", " <<
- runtimeData->genericInfo[i].keyType << ", " <<
- runtimeData->genericInfo[i].langElId << ", " <<
- runtimeData->genericInfo[i].parserId << " },\n";
+ runtimeData->genericInfo[i].keyType << ", " <<
+ runtimeData->genericInfo[i].langElId << ", " <<
+ runtimeData->genericInfo[i].parserId << ", " <<
+ runtimeData->genericInfo[i].elOffset << " },\n";
}
out << "};\n\n";
diff --git a/src/resolve.cc b/src/resolve.cc
index aa545e0d..b41289bc 100644
--- a/src/resolve.cc
+++ b/src/resolve.cc
@@ -255,10 +255,27 @@ UniqueType *TypeRef::resolveTypeList2Obj( Compiler *pd )
UniqueType *utValue = typeRef1->resolveType( pd );
- UniqueList2 searchKey( utValue );
+ /* Find the offset of the list element. */
+ int off = 0;
+ bool found = false;
+ ObjFieldList *elFieldList = utValue->langEl->objectDef->objFieldList;
+ for ( ObjFieldList::Iter f = *elFieldList; f.lte(); f++, off++ ) {
+ UniqueType *fUT = f->value->typeRef->resolveType( pd );
+ if ( fUT->langEl->generic != 0 &&
+ fUT->langEl->generic->typeId == GEN_LIST2EL )
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if ( !found )
+ error( loc ) << "cound not find list element in type ref" << endp;
+
+ UniqueList2 searchKey( utValue, off );
UniqueList2 *inMap = pd->uniqueList2Map.find( &searchKey );
if ( inMap == 0 ) {
- inMap = new UniqueList2( utValue );
+ inMap = new UniqueList2( utValue, off );
pd->uniqueList2Map.insert( inMap );
/* FIXME: Need uniqe name allocator for types. */
@@ -268,10 +285,9 @@ UniqueType *TypeRef::resolveTypeList2Obj( Compiler *pd )
GenericType *generic = new GenericType( name, GEN_LIST2,
pd->nextGenericId++, 0/*langEl*/, typeRef1 );
+ generic->elOffset = off;
nspace->genericList.append( generic );
-
generic->declare( pd, nspace );
-
inMap->generic = generic;
}
diff --git a/src/tree.c b/src/tree.c
index 30d8af0a..e391a811 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -1700,13 +1700,13 @@ void list2PushTail( Program *prg, Tree **sp, List *list, Tree *val )
val = ((Pointer*)val)->value->tree;
/* Make sure val has an element tree. */
- Tree *el = colm_get_attr( val, 0 );
+ Tree *el = colm_get_attr( val, list->genericInfo->elOffset );
if ( el == 0 ) {
el = treeAllocate( prg );
el->id = 0;
el->refs = 1;
el->child = allocAttrs( prg, 2 );
- setAttr( val, 0, constructPointer( prg, el ) );
+ setAttr( val, list->genericInfo->elOffset, constructPointer( prg, el ) );
}
else {
/* Deref the list element (must be a pointer too for time being) */
@@ -1718,22 +1718,20 @@ void list2PushTail( Program *prg, Tree **sp, List *list, Tree *val )
setAttr( el, 0, (Tree*)list->tail );
setAttr( el, 1, 0 );
-// if list->tail == 0
-// list->tail = list->tail = val
-// else
-// list->tail->next = val
-// list->tail = val
-
Tree *pval = constructPointer( prg, val );
pval->refs += 100;
val->refs += 100;
if ( list->tail == 0 ) {
+ /* list->tail = list->tail = val */
list->head = list->tail = (ListEl*)pval;
}
else {
- Tree *tel = colm_get_attr( ((Pointer*)list->tail)->value->tree, 0 );
+ /* list->tail->next = val */
+ /* list->tail = val */
+ Tree *tel = colm_get_attr( ((Pointer*)list->tail)->value->tree,
+ list->genericInfo->elOffset );
setAttr( ((Pointer*)tel)->value->tree, 1, pval );
list->tail = (ListEl*)pval;
}
diff --git a/src/tree.h b/src/tree.h
index 6a2d18f7..148d52e3 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -131,6 +131,7 @@ typedef struct _GenericInfo
long keyType;
long langElId;
long parserId;
+ long elOffset;
} GenericInfo;
typedef struct _List