public override CodeExpression GetReaderExpression(CodeExpression reader) { CodeExpression refExpr; if (_magicParser) { List <CodeExpression> args = new List <CodeExpression>(); args.Add(reader); foreach (SequenceChoice choice in _choices) { if (choice.SequenceType != null) { args.Add(CodeGen.GetTypeOf(new CodeTypeReference(choice.SequenceType.Name))); } } if (DefaultType != null) { args.Add(CodeGen.GetTypeOf(new CodeTypeReference(DefaultType.Name))); } return(CodeGen.CallMethod(CodeGen.GetThis(), "RSC", args.ToArray())); } else { if (_reference.IsValid()) { refExpr = CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames()); } else { refExpr = CodeGen.GetPrimitive(null); } List <CodeExpression> args = new List <CodeExpression>(); args.Add(reader); args.Add(refExpr); foreach (SequenceChoice choice in _choices) { if ((choice.BooleanExpression.IsValid) && (choice.SequenceType != null)) { args.Add(CodeGen.GetPrimitive(choice.BooleanExpression.Expression)); args.Add(CodeGen.GetTypeOf(new CodeTypeReference(choice.SequenceType.Name))); } } if (DefaultType != null) { args.Add(CodeGen.GetPrimitive("true")); args.Add(CodeGen.GetTypeOf(new CodeTypeReference(DefaultType.Name))); } return(CodeGen.CallMethod(CodeGen.GetThis(), "RSC", args.ToArray())); } }
private CodeExpression GetLength() { Type refType = ((BuiltinParserType)_reference.GetTargetMember().BaseType).DataType; CodeExpression ret = CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames()); if (refType != typeof(int)) { ret = CodeGen.CallMethod(CodeGen.GetThis(), "CL", ret); } if (_adjustment != 0) { ret = CodeGen.GetOperator(ret, CodeBinaryOperatorType.Add, CodeGen.GetPrimitive(_adjustment)); } return(ret); }
private CodeExpression GetLength() { CodeExpression ret = CodeGen.GetCast(typeof(int), CodeGen.GetField(CodeGen.GetThis(), _reference.GetNames())); if (_adjustment != 0) { ret = CodeGen.GetOperator(ret, CodeBinaryOperatorType.Add, CodeGen.GetPrimitive(_adjustment)); } return(ret); }
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 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); }