public void ConvertStructType(PegNode blocknamenode, IBfsStructType block)
{
if (block == null)
throw new AstConvertException("Type wasn't struct-like");
block.SourceRange = GetSourceRange(blocknamenode);
block.Name = GetNodeText(blocknamenode);
PegNode nextNode = blocknamenode.next_;
//If the structure has a Compression Method defined
if ( nextNode != null && GetNodeId(nextNode) == EBinaryFileSchemaParser.compressionmethod)
{
block.CompressionMethod = GetNodeText(nextNode);
block.CompressionRange = GetSourceRange(nextNode);
nextNode = nextNode.next_;
}
//If a primitive type is present, then it is a comsumeable struct type
if (nextNode != null && GetNodeId(nextNode) == EBinaryFileSchemaParser.primitivetype)
{
IBfsConsumptionType special = block as IBfsConsumptionType;
special.PrimitiveType = ConvertPrimitiveType(nextNode);
nextNode = nextNode.next_;
}
//For each of the fields the struct-type contains
for(PegNode field = nextNode; field != null; field = field.next_)
{
if (GetNodeId(field) == EBinaryFileSchemaParser.field)
{
BfsStructField fielditem = new BfsStructField();
fielditem.SourceRange = GetSourceRange(field);
ConvertStructField(field, fielditem);
block.StructFieldList.Add(fielditem);
}
else
if (GetNodeId(field) == EBinaryFileSchemaParser.localfield)
ConvertLocalField(field, block);
else
throw new AstConvertException("Node wasn't a field: " + GetNodeId(field));
}
}