protected override void GenerateMethod(Node node, StreamWriter stream, string indent) { base.GenerateMethod(node, stream, indent); Assignment assignment = node as Assignment; Debug.Check(assignment != null); stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent); stream.WriteLine("{0}\t\t{{", indent); stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent); if (assignment.Opl != null && assignment.Opr != null) { if (assignment.Opl.IsPar) { ParInfo par = assignment.Opl.Value as ParInfo; if (par != null) { RightValueCsExporter.GenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType.Replace("::", "."), "opr", "opr"); uint id = Behaviac.Design.CRC32.CalcCRC(par.Name); string typename = DataCsExporter.GetGeneratedNativeType(par.NativeType); stream.WriteLine("{0}\t\t\tDebug.Check(behaviac.Utils.MakeVariableId(\"{1}\") == {2}u);", indent, par.Name, id); stream.WriteLine("{0}\t\t\tpAgent.SetVariable<{1}>(\"{2}\", opr, {3}u);", indent, typename, par.Name, id); } } else { Debug.Check(assignment.Opl.IsProperty); RightValueCsExporter.GenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType.Replace("::", "."), "opr", "opr"); //VariableCsExporter.GenerateCode(assignment.Opl, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl", "opr"); VariableCsExporter.PostGenerateCode(assignment.Opl, stream, indent + "\t\t\t", assignment.Opl.NativeType.Replace("::", "."), "opl", string.Empty, null, "", "opr"); } if (assignment.Opr.IsMethod) { RightValueCsExporter.PostGenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType.Replace("::", "."), "opr", string.Empty); } } stream.WriteLine("{0}\t\t\treturn result;", indent); stream.WriteLine("{0}\t\t}}", indent); }
protected override void GenerateMethod(Node node, StreamWriter stream, string indent) { base.GenerateMethod(node, stream, indent); Compute compute = node as Compute; Debug.Check(compute != null); stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent); stream.WriteLine("{0}\t\t{{", indent); stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent); if (compute.Opl != null && compute.Opr1 != null && compute.Opr2 != null) { RightValueCsExporter.GenerateCode(compute.Opr1, stream, indent + "\t\t\t", compute.Opr1.NativeType, "opr1", "opr1"); RightValueCsExporter.GenerateCode(compute.Opr2, stream, indent + "\t\t\t", compute.Opr2.NativeType, "opr2", "opr2"); string oprStr = string.Empty; switch (compute.Operator) { case ComputeOperator.Add: oprStr = "opr1 + opr2"; break; case ComputeOperator.Sub: oprStr = "opr1 - opr2"; break; case ComputeOperator.Mul: oprStr = "opr1 * opr2"; break; case ComputeOperator.Div: oprStr = "opr1 / opr2"; break; default: Debug.Check(false, "The operator is wrong!"); break; } string basicType = DataCsExporter.GetGeneratedNativeType(compute.Opl.NativeType); stream.WriteLine("{0}\t\t\t{1} opr = ({1})({2});", indent, basicType, oprStr); if (compute.Opl.IsPar) { ParInfo par = compute.Opl.Value as ParInfo; if (par != null) { uint id = Behaviac.Design.CRC32.CalcCRC(par.Name); stream.WriteLine("{0}\t\t\tDebug.Check(behaviac.Utils.MakeVariableId(\"{1}\") == {2}u);", indent, par.Name, id); stream.WriteLine("{0}\t\t\tpAgent.SetVariable(\"{1}\", opr, {2}u);", indent, par.Name, id); } } else { //VariableCsExporter.GenerateCode(compute.Opl, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl", "opr"); VariableCsExporter.PostGenerateCode(compute.Opl, stream, indent + "\t\t\t", compute.Opl.NativeType, "opl", string.Empty, null, "", "opr"); } if (compute.Opr1.IsMethod) { RightValueCsExporter.PostGenerateCode(compute.Opr1, stream, indent + "\t\t\t", compute.Opr1.NativeType, "opr1", string.Empty); } if (compute.Opr2.IsMethod) { RightValueCsExporter.PostGenerateCode(compute.Opr2, stream, indent + "\t\t\t", compute.Opr2.NativeType, "opr2", string.Empty); } } stream.WriteLine("{0}\t\t\treturn result;", indent); stream.WriteLine("{0}\t\t}}", indent); }