public CodeExpression GetReaderExpression(CodeExpression reader)
        {
            CodeExpression returnExpression;

            // Might as well return an empty string
            if (!_reference.IsValid())
            {
                returnExpression = CodeGen.GetPrimitive(String.Empty);
            }
            else
            {
                string name = _isByteLength ? "FixBS" : "FixS";
                List <CodeExpression> parameters = new List <CodeExpression>();

                parameters.Add(reader);
                parameters.Add(CodeGen.GetEnum(StringEncoding));
                parameters.Add(CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames()));

                EvalExpression lengthRead = LengthReadExpression;

                if (lengthRead.IsValid)
                {
                    parameters.Add(CodeGen.GetPrimitive(lengthRead.Expression));
                }
                else
                {
                    parameters.Add(CodeGen.GetPrimitive(_adjustment));
                }

                returnExpression = CodeGen.CallMethod(CodeGen.GetThis(), name, parameters.ToArray());
            }

            return(returnExpression);
        }
        public CodeExpression GetReaderExpression(CodeExpression reader)
        {
            CodeExpression      ret   = null;
            IMemberReaderWriter entry = BaseEntry as IMemberReaderWriter;

            if (_reference.IsValid())
            {
                string name = _isByteLength ? "SAB" : "SA";
                List <CodeExpression> parameters = new List <CodeExpression>();

                parameters.Add(reader);

                EvalExpression lengthRead = LengthReadExpression;

                parameters.Add(CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames()));

                if (lengthRead.IsValid)
                {
                    parameters.Add(CodeGen.GetPrimitive(lengthRead.Expression));
                }
                else
                {
                    parameters.Add(CodeGen.GetPrimitive(_adjustment));
                }

                ret = CodeGen.CallMethod(CodeGen.GetThis(), name, BaseEntry.GetTypeReference(), parameters.ToArray());
            }
            else
            {
                ret = CodeGen.CreateArray(GetTypeReference(), 0);
            }

            return(ret);
        }
Esempio n. 3
0
 internal static CodeExpression GetLength(int length, EvalExpression lengthExpression)
 {
     if (lengthExpression.IsValid)
     {
         return(CodeGen.CallMethod(CodeGen.GetThis(), "CL", CodeGen.GetPrimitive(length), CodeGen.GetPrimitive(lengthExpression.Expression)));
     }
     else
     {
         return(CodeGen.GetPrimitive(length));
     }
 }
        public override System.CodeDom.CodeMemberMethod GetPreSerializeMethod()
        {
            CodeMemberMethod method = base.GetPreSerializeMethod();

            if (_reference.IsValid())
            {
                CodeExpression right = CodeGen.GetProperty(CodeGen.GetThisField(Name), "Length");

                if (_isByteLength)
                {
                    PrimitiveMemberEntry entry    = BaseEntry as PrimitiveMemberEntry;
                    BitFieldMemberEntry  bitField = entry as BitFieldMemberEntry;

                    if (bitField != null)
                    {
                        right = CodeGen.CallMethod(CodeGen.GetThis(), "CLBits", right, CodeGen.GetPrimitive(bitField.Bits));
                    }
                    else
                    {
                        right = CodeGen.GetOperator(CodeGen.GetPrimitive(entry.GetSize()), CodeBinaryOperatorType.Multiply, right);
                    }
                }

                EvalExpression lengthWrite = LengthWriteExpression;

                if (lengthWrite.IsValid)
                {
                    right = lengthWrite.GetEvalExpression(right);
                }
                else if (_adjustment != 0)
                {
                    right = CodeGen.GetOperator(right, CodeBinaryOperatorType.Subtract, CodeGen.GetPrimitive(_adjustment));
                }

                if (_reference.GetTargetMember().BaseType is StringParserType)
                {
                    right = CodeGen.CallMethod(right, "ToString");
                }
                else
                {
                    right = CodeGen.GetCast(_reference.GetTargetMember().GetTypeReference(), right);
                }

                method.Statements.Add(CodeGen.GetAssign(CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames()), right));
            }

            return(method);
        }
        public CodeExpression GetReaderExpression(CodeExpression reader)
        {
            CodeExpression       ret;
            PrimitiveMemberEntry entry = BaseEntry as PrimitiveMemberEntry;

            if (_reference.IsValid())
            {
                CodeExpression lengthExpression;
                EvalExpression lengthRead = LengthReadExpression;

                if (lengthRead.IsValid)
                {
                    lengthExpression = CodeGen.CallMethod(CodeGen.GetThis(), "CL", CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames()), CodeGen.GetPrimitive(lengthRead.Expression));
                }
                else
                {
                    Type refType = ((BuiltinParserType)_reference.GetTargetMember().BaseType).DataType;
                    lengthExpression = CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames());

                    if (refType != typeof(int))
                    {
                        lengthExpression = CodeGen.CallMethod(CodeGen.GetThis(), "CL", lengthExpression);
                    }

                    if (_adjustment != 0)
                    {
                        lengthExpression = CodeGen.GetOperator(lengthExpression, CodeBinaryOperatorType.Add, CodeGen.GetPrimitive(_adjustment));
                    }
                }

                if (_isByteLength)
                {
                    ret = CodeGen.CallMethod(CodeGen.GetThis(), "FixBPA", BaseEntry.GetTypeReference(), reader, lengthExpression, ((IntegerPrimitiveMemberEntry)BaseEntry).GetEndian());
                }
                else
                {
                    ret = CodeGen.CallMethod(CodeGen.GetThis(), "FixPA", BaseEntry.GetTypeReference(), reader, lengthExpression, ((IntegerPrimitiveMemberEntry)BaseEntry).GetEndian());
                }
            }
            else
            {
                ret = CodeGen.CreateArray(BaseEntry.GetTypeReference(), 0);
            }

            return(ret);
        }
        public override CodeMemberMethod GetPreSerializeMethod()
        {
            CodeMemberMethod method = base.GetPreSerializeMethod();

            if (_reference.IsValid())
            {
                CodeExpression right;

                if (_isByteLength)
                {
                    right = CodeGen.CallMethod(CodeGen.GetThis(), "SBL", CodeGen.GetThisField(Name), CodeGen.GetEnum(StringEncoding));
                }
                else
                {
                    right = CodeGen.GetProperty(CodeGen.GetThisField(Name), "Length");
                }

                EvalExpression lengthWrite = LengthWriteExpression;

                if (lengthWrite.IsValid)
                {
                    right = lengthWrite.GetEvalExpression(right);
                }
                else if (_adjustment != 0)
                {
                    right = CodeGen.GetOperator(right, CodeBinaryOperatorType.Subtract, CodeGen.GetPrimitive(_adjustment));
                }

                if (_reference.GetTargetMember().BaseType is StringParserType)
                {
                    right = CodeGen.CallMethod(right, "ToString");
                }
                else
                {
                    right = CodeGen.GetCast(_reference.GetTargetMember().GetTypeReference(), right);
                }

                method.Statements.Add(CodeGen.GetAssign(CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames()), right));
            }

            return(method);
        }
Esempio n. 7
0
        internal static CodeExpression GetLength(EvalExpression lengthExpression)
        {
            if (lengthExpression.IsValid)
            {
                int length;

                // If we can parse then just emit the primitive
                if (lengthExpression.ParseInt(out length))
                {
                    return(CodeGen.GetPrimitive(length));
                }
                else
                {
                    return(CodeGen.CallMethod(CodeGen.GetThis(), "CL", CodeGen.GetPrimitive(lengthExpression.Expression)));
                }
            }
            else
            {
                return(CodeGen.GetPrimitive(0));
            }
        }
Esempio n. 8
0
 internal static CodeExpression GetResolve(EvalExpression expr, CodeExpression value, CodeExpression writer)
 {
     return CodeGen.CallMethod(CodeGen.GetThis(), "Resolve", CodeGen.GetPrimitive(expr.Expression), writer, value);
 }
Esempio n. 9
0
        internal static CodeExpression GetLength(EvalExpression lengthExpression)
        {
            if (lengthExpression.IsValid)
            {
                int length;

                // If we can parse then just emit the primitive
                if (lengthExpression.ParseInt(out length))
                {
                    return CodeGen.GetPrimitive(length);
                }
                else
                {
                    return CodeGen.CallMethod(CodeGen.GetThis(), "CL", CodeGen.GetPrimitive(lengthExpression.Expression));
                }
            }
            else
            {
                return CodeGen.GetPrimitive(0);
            }
        }
Esempio n. 10
0
 internal static CodeExpression GetLength(int length, EvalExpression lengthExpression)
 {
     if (lengthExpression.IsValid)
     {
         return CodeGen.CallMethod(CodeGen.GetThis(), "CL", CodeGen.GetPrimitive(length), CodeGen.GetPrimitive(lengthExpression.Expression));
     }
     else
     {
         return CodeGen.GetPrimitive(length);
     }
 }
Esempio n. 11
0
 internal static CodeExpression GetCheck(EvalExpression expr, CodeExpression value, CodeExpression i)
 {
     return CodeGen.CallMethod(CodeGen.GetThis(), "Check", CodeGen.GetPrimitive(expr.Expression), value, i);
 }
Esempio n. 12
0
 internal static CodeExpression GetCalc(EvalExpression expr, CodeTypeReference fieldType, CodeExpression value)
 {
     return CodeGen.CallMethod(CodeGen.GetThis(), "Calc", fieldType, CodeGen.GetPrimitive(expr.Expression), value);
 }
Esempio n. 13
0
 internal static CodeExpression GetCheck(EvalExpression expr, CodeExpression value, CodeExpression i)
 {
     return(CodeGen.CallMethod(CodeGen.GetThis(), "Check", CodeGen.GetPrimitive(expr.Expression), value, i));
 }
Esempio n. 14
0
 internal static CodeExpression GetResolve(EvalExpression expr, CodeExpression value, CodeExpression writer)
 {
     return(CodeGen.CallMethod(CodeGen.GetThis(), "Resolve", CodeGen.GetPrimitive(expr.Expression), writer, value));
 }
Esempio n. 15
0
 internal static CodeExpression GetCalc(EvalExpression expr, CodeTypeReference fieldType, CodeExpression value)
 {
     return(CodeGen.CallMethod(CodeGen.GetThis(), "Calc", fieldType, CodeGen.GetPrimitive(expr.Expression), value));
 }