Ejemplo n.º 1
0
 public string GetDataTypeName(int id)
 {
     if (SystemDataTypeName.TryGetValue(id, out var result))
     {
         return(result);
     }
     else if (EplSystemId.IsLibDataType(id))
     {
         EplSystemId.DecomposeLibDataTypeId(id, out var lib, out var type);
         return(GetLibTypeName(lib, type));
     }
     else
     {
         return(GetUserDefinedName(id));
     }
 }
Ejemplo n.º 2
0
        private static Expression ParseExpression(BinaryReader reader, Encoding encoding, bool parseMember = true)
        {
            Expression result = null;
            byte       type;

            while (true)
            {
                type = reader.ReadByte();
                switch (type)
                {
                case 0x01:
                    result = ParamListEnd.Instance;
                    break;

                case 0x16:
                    result = DefaultValueExpression.Instance;
                    break;

                case 0x17:
                    result = new NumberLiteral(reader.ReadDouble());
                    break;

                case 0x18:
                    result = BoolLiteral.ValueOf(reader.ReadInt16() != 0);
                    break;

                case 0x19:
                    result = new DateTimeLiteral(DateTime.FromOADate(reader.ReadDouble()));
                    break;

                case 0x1A:
                    result = new StringLiteral(reader.ReadBStr(encoding));
                    break;

                case 0x1B:
                    result = new ConstantExpression(reader.ReadInt32());
                    break;

                case 0x1C:
                    result = new ConstantExpression((short)(reader.ReadInt16() - 1), (short)(reader.ReadInt16() - 1));
                    break;

                case 0x1D:
                    // 0x1D 0x38 <Int32:VarId>
                    continue;

                case 0x1E:
                    result = new MethodPtrExpression(reader.ReadInt32());
                    break;

                case 0x21:
                    result = ParseCallExpressionWithoutType(reader, encoding);
                    break;

                case 0x23:
                    result = new EmnuConstantExpression((short)(reader.ReadInt16() - 1), (short)(reader.ReadInt16() - 1), reader.ReadInt32() - 1);
                    break;

                case 0x37:
                    continue;

                case 0x1F:
                {
                    var        array = new ArrayLiteralExpression();
                    Expression exp;
                    while (!((exp = ParseExpression(reader, encoding)) is ArrayLiteralEnd))
                    {
                        array.Add(exp);
                    }
                    result = array;
                }
                break;

                case 0x20:
                    result = ArrayLiteralEnd.Instance;
                    break;

                case 0x38:     // ThisCall Or 访问变量
                {
                    int variable = reader.ReadInt32();
                    if (variable == 0x0500FFFE)
                    {
                        reader.ReadByte();         // 0x3A
                        return(ParseExpression(reader, encoding, true));
                    }
                    else
                    {
                        result      = new VariableExpression(variable);
                        parseMember = true;
                    }
                }
                break;

                case 0x3B:
                    result = new NumberLiteral(reader.ReadInt32());
                    break;

                default:
                    throw new Exception($"Unknown Type: {type:X2}");
                }
                break;
            }
            if (parseMember &&
                (result is VariableExpression ||
                 result is CallExpression ||
                 result is AccessMemberExpression ||
                 result is AccessArrayExpression))
            {
                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    switch (reader.ReadByte())
                    {
                    case 0x39:
                        int memberId = reader.ReadInt32();
                        int structId = reader.ReadInt32();
                        if (EplSystemId.IsLibDataType(structId))
                        {
                            EplSystemId.DecomposeLibDataTypeId(structId, out var libId, out var structIdInLibId);
                            result = new AccessMemberExpression(result, libId, structIdInLibId, memberId - 1);
                        }
                        else
                        {
                            result = new AccessMemberExpression(result, structId, memberId);
                        }
                        break;

                    case 0x3A:
                        result = new AccessArrayExpression(result, ParseExpression(reader, encoding, false));
                        break;

                    case 0x37:
                        goto parse_member_finish;

                    default:
                        reader.BaseStream.Position -= 1;
                        goto parse_member_finish;
                    }
                }
            }
parse_member_finish:
            return(result);
        }