Exemple #1
0
 public static EocDateTimeLiteral Translate(CodeConverter C, DateTimeLiteral expr)
 {
     if (expr == null)
     {
         return(null);
     }
     return(new EocDateTimeLiteral(C, expr.Value));
 }
Exemple #2
0
        internal List <Statement> GetStatements()
        {
            return(_variables.Select(variable =>
            {
                Expression literal;
                if (variable.Value is int i)
                {
                    literal = new IntegerLiteral("IntegerLiteral", Convert.ToString(i));
                }
                else if (variable.Value is bool b)
                {
                    literal = new BooleanLiteral("BooleanLiteral", b);
                }
                else if (variable.Value is float f)
                {
                    literal = new FloatLiteral("FloatLiteral", Convert.ToDecimal(f));
                }
                else if (variable.Value is DateTime d)
                {
                    literal = new DateTimeLiteral("DateTimeLiteral", d);
                }
                else if (variable.Value is DateTimeOffset o)
                {
                    literal = new DateTimeLiteral("DateTimeLiteral", o.UtcDateTime);
                }
                else
                {
                    literal = new StringLiteral("StringLiteral", Convert.ToString(variable.Value));
                }

                var assignment = new VariableAssignment("VariableAssignment",
                                                        new Identifier("Identifier", variable.Name), literal);

                return new OptionStatement("OptionStatement", assignment) as Statement;
            }).ToList());
        }
        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.ToString("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();
                        if (EplSystemId.GetType(memberId) == EplSystemId.Type_StructMember)
                        {
                            result = new AccessMemberExpression(result, reader.ReadInt32(), memberId);
                        }
                        else
                        {
                            result = new AccessMemberExpression(result, (short)(reader.ReadInt16() - 1), (short)(reader.ReadInt16() - 1), memberId - 1);
                        }
                        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);
        }
Exemple #4
0
        private static Expression ParseExpression(BinaryReader reader, CodeSectionInfo codeSectionInfo, int blockId, bool parseMember = true)
        {
            Expression expression = null;
            byte       b          = reader.ReadByte();

            switch (b)
            {
            case 1:
                expression = new ParamListEnd();
                break;

            case 22:
                expression = null;
                break;

            case 23:
                expression = new NumberLiteral(reader.ReadDouble());
                break;

            case 24:
                expression = new BoolLiteral(reader.ReadInt16() != 0);
                break;

            case 25:
                expression = new DateTimeLiteral(DateTime.FromOADate(reader.ReadDouble()));
                break;

            case 26:
                expression = new StringLiteral(reader.ReadStringWithLengthPrefix());
                break;

            case 27:
                expression = new ConstantExpression(-2, reader.ReadInt32());
                break;

            case 28:
                expression = new ConstantExpression(reader.ReadInt16(), reader.ReadInt16());
                break;

            case 29:
                if (reader.ReadByte() != 56)
                {
                    throw new Exception();
                }
                expression = new VariableExpression(reader.ReadInt32(), codeSectionInfo, blockId);
                break;

            case 30:
                expression = new SubPtrExpression(reader.ReadInt32(), codeSectionInfo);
                break;

            case 33:
                expression = ParseCallExpressionWithoutType(reader, codeSectionInfo, blockId);
                break;

            case 35:
                expression = new EmnuConstantExpression(reader.ReadInt32(), reader.ReadInt32());
                break;

            case 31:
            {
                ArrayLiteralExpression arrayLiteralExpression = new ArrayLiteralExpression();
                Expression             item;
                while (!((item = ParseExpression(reader, codeSectionInfo, blockId, true)) is ArrayLiteralEnd))
                {
                    arrayLiteralExpression.Value.Add(item);
                }
                expression = arrayLiteralExpression;
                break;
            }

            case 32:
                expression = new ArrayLiteralEnd();
                break;

            case 56:
            {
                int num = reader.ReadInt32();
                if (num == 83951614)
                {
                    reader.ReadByte();
                    expression = ParseExpression(reader, codeSectionInfo, blockId, true);
                }
                else
                {
                    expression = new VariableExpression(num, codeSectionInfo, blockId);
                }
                break;
            }

            case 59:
                expression = new NumberLiteral((double)reader.ReadInt32());
                break;

            default:
                throw new Exception(string.Format("Unknown Type: {0}", b.ToString("X2")));

            case 55:
                break;
            }
            //bool flag = false;
            if (parseMember && (expression is VariableExpression || expression is CallExpression))
            {
                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    switch (reader.ReadByte())
                    {
                    case 57:
                        break;

                    case 58:
                        goto IL_027a;

                    default:
                        reader.BaseStream.Position -= 1L;
                        goto IL_02eb;

                    case 55:
                        goto IL_02eb;
                    }
                    int memberId = reader.ReadInt32();
                    int structId = reader.ReadInt32();
                    expression = new AccessMemberExpression(expression, structId, memberId);
                    continue;
IL_027a:
                    bool parseMember2           = reader.ReadByte() == 56;
                    reader.BaseStream.Position -= 1L;
                    expression = new AccessArrayExpression(expression, ParseExpression(reader, codeSectionInfo, blockId, parseMember2));
                }
            }
            goto IL_02eb;
IL_02eb:
            return(expression);
        }