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\tvirtual EBTStatus update_impl(Agent* pAgent, EBTStatus childStatus)", indent); stream.WriteLine("{0}\t\t{{", indent); stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent); stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(childStatus);", indent); stream.WriteLine("{0}\t\t\tEBTStatus result = BT_SUCCESS;", indent); if (assignment.Opl != null && assignment.Opr != null) { if (assignment.Opl.IsPar) { ParInfo par = assignment.Opl.Value as ParInfo; if (par != null) { RightValueCppExporter.GenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType, "opr", "opr"); uint id = Behaviac.Design.CRC32.CalcCRC(par.Name); stream.WriteLine("{0}\t\t\tBEHAVIAC_ASSERT(behaviac::MakeVariableId(\"{1}\") == {2}u);", indent, par.Name, id); stream.WriteLine("{0}\t\t\tpAgent->SetVariable(\"{1}\", opr, {2}u);", indent, par.Name, id); } } else { string opl = VariableCppExporter.GenerateCode(assignment.Opl, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl"); RightValueCppExporter.GenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType, "opr", "opr"); stream.WriteLine("{0}\t\t\t{1} = opr;", indent, opl); VariableCppExporter.PostGenerateCode(assignment.Opl, stream, indent + "\t\t\t", assignment.Opl.NativeType, "opl", string.Empty); } if (assignment.Opr.IsMethod) { RightValueCppExporter.PostGenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType, "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\tvirtual EBTStatus update_impl(Agent* pAgent, EBTStatus childStatus)", indent); stream.WriteLine("{0}\t\t{{", indent); stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent); stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(childStatus);", indent); stream.WriteLine("{0}\t\t\tEBTStatus result = BT_SUCCESS;", indent); if (compute.Opl != null && compute.Opr1 != null && compute.Opr2 != null) { RightValueCppExporter.GenerateCode(compute.Opr1, stream, indent + "\t\t\t", compute.Opr1.NativeType, "opr1", "opr1"); RightValueCppExporter.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 = DataCppExporter.GetBasicGeneratedNativeType(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\tBEHAVIAC_ASSERT(behaviac::MakeVariableId(\"{1}\") == {2}u);", indent, par.Name, id); stream.WriteLine("{0}\t\t\tpAgent->SetVariable(\"{1}\", opr, {2}u);", indent, par.Name, id); } } else { string opl = VariableCppExporter.GenerateCode(compute.Opl, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl"); stream.WriteLine("{0}\t\t\t{1} = opr;", indent, opl); VariableCppExporter.PostGenerateCode(compute.Opl, stream, indent + "\t\t\t", compute.Opl.NativeType, "opl", string.Empty, null, "", "opr"); } if (compute.Opr1.IsMethod) { RightValueCppExporter.PostGenerateCode(compute.Opr1, stream, indent + "\t\t\t", compute.Opr1.NativeType, "opr1", string.Empty); } if (compute.Opr2.IsMethod) { RightValueCppExporter.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); }