uses HWI
interface DNTypeUtilLib {
char[] typeCheck(OpToken op, DanaType types[])
bool isSuperTypeOf(DanaType x, DanaType y, DanaType types[])
int getDataFieldIndex(DanaType t, char name[])
DanaTypeField getDataField(DanaType t, char name[])
DanaTypeField getDataFieldAt(DanaType t, int index)
int getDataFieldCount(DanaType t)
int getTypeDistance(DanaType a, DanaType b, DanaType types[])
int getFieldIndex(DanaType fromType, char fieldName[], DanaType types[])
}
component provides TypeUtil requires native DNTypeUtilLib lib, DNCUtil dncUtil, data.query.Search search {
char[] TypeUtil:typeCheck(OpToken op, DanaType types[])
{
return lib.typeCheck(op, types)
}
bool TypeUtil:isSuperTypeOf(DanaType x, DanaType y, DanaType types[])
{
return lib.isSuperTypeOf(x, y, types)
}
int TypeUtil:getDataFieldIndex(DanaType t, char name[])
{
int index = 0
for (int i = 0; i < t.fields.arrayLength; i++)
{
if (t.fields[i].qualifier != "constant")
{
if (t.fields[i].name == name)
return index
index ++
}
}
return INT_MAX
}
DanaTypeField TypeUtil:getDataField(DanaType t, char name[])
{
for (int i = 0; i < t.fields.arrayLength; i++)
{
if (t.fields[i].qualifier != "constant")
{
if (t.fields[i].name == name)
return t.fields[i]
}
}
return null
}
DanaTypeField TypeUtil:getDataFieldAt(DanaType t, int index)
{
for (int i = 0; i < t.fields.arrayLength; i++)
{
if (t.fields[i].qualifier != "constant")
{
if (index == 0)
return t.fields[i]
index --
}
}
return null
}
int TypeUtil:getDataFieldCount(DanaType t)
{
int count = 0
for (int i = 0; i < t.fields.arrayLength; i++)
{
if (t.fields[i].qualifier != "constant")
{
count ++
}
}
return count
}
int TypeUtil:getTypeDistance(DanaType a, DanaType b, DanaType types[])
{
return lib.getTypeDistance(a, b, types)
}
int TypeUtil:getFieldIndex(DanaType fromType, char fieldName[], DanaType types[])
{
if (fromType.class == DanaType.INTERFACE)
{
int eventIndex = 0
int functionIndex = 0
for (int i = 0; i < fromType.fields.arrayLength; i++)
{
DanaType fieldType = types.findFirst(DanaType.[name], new DanaType(name = fromType.fields[i].type))
if (fieldType.class == DanaType.EVENT)
{
if (fromType.fields[i].name == fieldName)
{
return eventIndex
}
eventIndex ++
}
else if (fieldType.class == DanaType.FUNCTION)
{
if (fromType.fields[i].name == fieldName)
{
return functionIndex
}
functionIndex ++
}
}
}
else if (fromType.class == DanaType.DATA)
{
int count = 0
for (int i = 0; i < fromType.fields.arrayLength; i++)
{
if (fromType.fields[i].qualifier != "constant")
{
if (fromType.fields[i].name == fieldName)
return count
count ++
}
}
}
return INT_MAX
}
}
To propose a new revision to this entity, use dana source put -uc your/new/version.dn -n util.compiler.TypeUtil -m "reason for update" -u yourUsername
Version 1 (this version) by barry
Notes for this version: New compiler components