Пример #1
0
        private IEnumerable <MemberDefinition> YieldMemberDefinitions(IEnumerable <BaseNode> members, ILogger logger)
        {
            Contract.Requires(members != null);
            Contract.Requires(Contract.ForAll(members, m => m != null));
            Contract.Ensures(Contract.Result <IEnumerable <MemberDefinition> >() != null);
            Contract.Ensures(Contract.ForAll(Contract.Result <IEnumerable <MemberDefinition> >(), d => d != null));

            foreach (var member in members.WhereNot(n => n is BaseHexNode))
            {
                var bitFieldNode = member as BitFieldNode;
                if (bitFieldNode != null)
                {
                    string type;
                    switch (bitFieldNode.Bits)
                    {
                    default:
                        type = typeToTypedefMap[typeof(UInt8Node)];
                        break;

                    case 16:
                        type = typeToTypedefMap[typeof(UInt16Node)];
                        break;

                    case 32:
                        type = typeToTypedefMap[typeof(UInt32Node)];
                        break;

                    case 64:
                        type = typeToTypedefMap[typeof(UInt64Node)];
                        break;
                    }

                    yield return(new MemberDefinition(member, type));
                }
                else
                {
                    string type;
                    if (typeToTypedefMap.TryGetValue(member.GetType(), out type))
                    {
                        yield return(new MemberDefinition(member, type));
                    }
                    else
                    {
                        var generator = CustomCodeGenerator.GetGenerator(member, Language);
                        if (generator != null)
                        {
                            yield return(generator.GetMemberDefinition(member, Language, logger));

                            continue;
                        }

                        logger.Log(LogLevel.Error, $"Skipping node with unhandled type: {member.GetType()}");
                    }
                }
            }
        }
Пример #2
0
        private IEnumerable <MemberDefinition> YieldMemberDefinitions(IEnumerable <BaseNode> members, ILogger logger)
        {
            Contract.Requires(members != null);
            Contract.Requires(Contract.ForAll(members, m => m != null));
            Contract.Ensures(Contract.Result <IEnumerable <MemberDefinition> >() != null);
            Contract.Ensures(Contract.ForAll(Contract.Result <IEnumerable <MemberDefinition> >(), d => d != null));

            int fill      = 0;
            int fillStart = 0;

            foreach (var member in members.WhereNot(m => m is VTableNode))
            {
                if (member is BaseHexNode)
                {
                    if (fill == 0)
                    {
                        fillStart = member.Offset.ToInt32();
                    }
                    fill += member.MemorySize;

                    continue;
                }

                if (fill != 0)
                {
                    yield return(new MemberDefinition(Program.Settings.TypePadding, fill, $"pad_{fillStart:X04}", fillStart, string.Empty));

                    fill = 0;
                }

                if (typeToTypedefMap.TryGetValue(member.GetType(), out var type))
                {
                    var count = (member as BaseTextNode)?.Length ?? 0;

                    yield return(new MemberDefinition(member, type, count));
                }
                else if (member is BitFieldNode)
                {
                    switch (((BitFieldNode)member).Bits)
                    {
                    case 8:
                        type = Program.Settings.TypeUInt8;
                        break;

                    case 16:
                        type = Program.Settings.TypeUInt16;
                        break;

                    case 32:
                        type = Program.Settings.TypeUInt32;
                        break;

                    case 64:
                        type = Program.Settings.TypeUInt64;
                        break;
                    }

                    yield return(new MemberDefinition(member, type));
                }
                else if (member is ClassInstanceArrayNode)
                {
                    var instanceArray = (ClassInstanceArrayNode)member;

                    yield return(new MemberDefinition(member, instanceArray.InnerNode.Name, instanceArray.Count));
                }
                else if (member is ClassInstanceNode)
                {
                    yield return(new MemberDefinition(member, ((ClassInstanceNode)member).InnerNode.Name));
                }
                else if (member is ClassPtrArrayNode)
                {
                    var ptrArray = (ClassPtrArrayNode)member;

                    yield return(new MemberDefinition(member, $"class {ptrArray.InnerNode.Name}*", ptrArray.Count));
                }
                else if (member is ClassPtrNode)
                {
                    yield return(new MemberDefinition(member, $"class {((ClassPtrNode)member).InnerNode.Name}*"));
                }
                else
                {
                    var generator = CustomCodeGenerator.GetGenerator(member, Language);
                    if (generator != null)
                    {
                        yield return(generator.GetMemberDefinition(member, Language, logger));
                    }
                    else
                    {
                        logger.Log(LogLevel.Error, $"Skipping node with unhandled type: {member.GetType()}");
                    }
                }
            }

            if (fill != 0)
            {
                yield return(new MemberDefinition(Program.Settings.TypePadding, fill, $"pad_{fillStart:X04}", fillStart, string.Empty));
            }
        }