public static void PostGenerateCode(Behaviac.Design.MethodDef method, StreamWriter stream, string indent, string typename, string var, string caller) { string paramsName = getParamsName(var, caller); for (int i = 0; i < method.Params.Count; ++i) { //if (method.Params[i].NativeType.EndsWith("&")) if (method.Params[i].NativeType.IndexOf("&") >= 0) { object obj = method.Params[i].Value; if (obj != null) { string nativeType = DataCsExporter.GetGeneratedNativeType(method.Params[i].NativeType); string param = getParamName(var, caller, i); string paramName = string.Format("(({0}){1}[{2}])", nativeType, paramsName, i); if (!method.Params[i].IsProperty && !method.Params[i].IsPar) { Type type = obj.GetType(); if (!Plugin.IsArrayType(type) && !Plugin.IsCustomClassType(type)) { param = paramName; } } else { paramName = null; } ParameterCsExporter.PostGenerateCode(method.Params[i], stream, indent, nativeType, param, caller, method, paramName); } } } }
public static string GenerateCode(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement, bool isRefParam, StreamWriter stream, string indent, string typename, string var, string caller, string setValue = null) { if (property.IsPar || property.IsCustomized) return ParInfoCsExporter.GenerateCode(property, isRefParam, stream, indent, typename, var, caller); string agentName = GetGenerateAgentName(property, var, caller); string prop = GetProperty(property, arrayIndexElement, stream, indent, var, caller); if (!property.IsReadonly) { if (setValue == null) { if (!string.IsNullOrEmpty(var)) { if (string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} = {2};", indent, var, prop); } else { string nativeType = DataCsExporter.GetPropertyNativeType(property, arrayIndexElement); stream.WriteLine("{0}{1} {2} = {3};", indent, nativeType, var, prop); } } } else { string propBasicName = property.BasicName.Replace("[]", ""); stream.WriteLine("{0}AgentExtra_Generated.SetProperty({1}, \"{2}\", {3});", indent, agentName, propBasicName, setValue); } } return prop; }
public static void GenerateClassMember(Behaviac.Design.MethodDef method, StreamWriter stream, string indent, string var) { Debug.Check(!string.IsNullOrEmpty(var)); if (method.Params.Count == 0) { return; } if (!method.IsPublic) { string paramsName = getParamsName(var, ""); stream.WriteLine("{0}\t\tobject[] {1};", indent, paramsName); } for (int i = 0; i < method.Params.Count; ++i) { // const value if (!method.Params[i].IsProperty && !method.Params[i].IsPar) { Type type = method.Params[i].Value.GetType(); if (method.IsPublic || Plugin.IsArrayType(type) || Plugin.IsCustomClassType(type)) { string param = getParamName(var, "", i); string nativeType = DataCsExporter.GetGeneratedNativeType(method.Params[i].NativeType); stream.WriteLine("{0}\t\t{1} {2};", indent, nativeType, param); } } } }
public MetaMethodDialog(AgentType agent, MethodDef method, MemberType memberType) { InitializeComponent(); this.Owner = MainWindow.Instance; this.metaMethodPanel.Initialize(true, agent, method, memberType); }
public static void PostGenerateCode(Behaviac.Design.MethodDef method, StringWriter stream, string indent, string typename, string var, string caller) { for (int i = 0; i < method.Params.Count; ++i) { if (!method.Params[i].NativeType.StartsWith("const ") && method.Params[i].NativeType.EndsWith("&")) { string param = (string.IsNullOrEmpty(var) ? caller : var) + "_p" + i; string nativeType = DataCppExporter.GetBasicGeneratedNativeType(method.Params[i].NativeType); ParameterCppExporter.PostGenerateCode(method.Params[i], stream, indent, nativeType, param, caller, method); } } }
public override bool ResetMembers(bool check, AgentType agentType, bool clear, MethodDef method = null, PropertyDef property = null) { bool bReset = false; if (this._frames != null) { bReset |= this._frames.ResetMembers(check, agentType, clear, method, property); } bReset |= base.ResetMembers(check, agentType, clear, method, property); return bReset; }
public static void GenerateClassMember(Behaviac.Design.MethodDef method, StringWriter stream, string indent, string var) { for (int i = 0; i < method.Params.Count; ++i) { // const value if (!method.Params[i].IsProperty && !method.Params[i].IsLocalVar) { string basicNativeType = DataCppExporter.GetBasicGeneratedNativeType(method.Params[i].NativeType); string param = var + "_p" + i; stream.WriteLine("{0}\t\t{1} {2};", indent, basicNativeType, param); } } }
public static string GetProperty(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement, StreamWriter stream, string indent, string var, string caller) { string agentName = GetGenerateAgentName(property, var, caller); if (property.Owner != Behaviac.Design.VariableDef.kSelf) { string instanceName = property.Owner.Replace("::", "."); stream.WriteLine("{0}behaviac.Agent {1} = behaviac.Utils.GetParentAgent(pAgent, \"{2}\");", indent, agentName, instanceName); stream.WriteLine("{0}Debug.Check({1} != null || Utils.IsStaticClass(\"{2}\"));", indent, agentName, instanceName); } string prop = getProperty(property, arrayIndexElement, agentName, stream, indent); return prop; }
public static void GenerateClassConstructor(DefaultObject defaultObj, Behaviac.Design.MethodDef method, StringWriter stream, string indent, string var) { for (int i = 0; i < method.Params.Count; ++i) { // const value if (!method.Params[i].IsProperty && !method.Params[i].IsLocalVar) { object obj = method.Params[i].Value; if (obj != null) { string param = var + "_p" + i; Type type = obj.GetType(); if (Plugin.IsArrayType(type)) { string nativeType = DataCppExporter.GetGeneratedNativeType(method.Params[i].NativeType); int startIndex = nativeType.IndexOf('<'); int endIndex = nativeType.LastIndexOf('>'); string itemType = nativeType.Substring(startIndex + 1, endIndex - startIndex - 1); ArrayCppExporter.GenerateCode(obj, defaultObj, stream, indent + "\t\t\t", itemType, param); } else if (Plugin.IsCustomClassType(type)) { if (Plugin.IsRefType(type)) { stream.WriteLine("{0}\t\t\t{1} = NULL;", indent, param); } else if (DesignerStruct.IsPureConstDatum(obj, method, method.Params[i].Name)) { StructCppExporter.GenerateCode(obj, defaultObj, stream, indent + "\t\t\t", param, null, ""); } } else { string nativeType = DataCppExporter.GetBasicGeneratedNativeType(method.Params[i].NativeType); string retStr = DataCppExporter.GenerateCode(obj, defaultObj, stream, string.Empty, nativeType, string.Empty, string.Empty); stream.WriteLine("{0}\t\t\t{1} = {2};", indent, param, retStr); } } } } }
public static void PostGenerateCode(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement, StreamWriter stream, string indent, string typename, string var, string caller, string setValue = null) { if (property.IsPar || property.IsCustomized) { ParInfoCsExporter.PostGenerateCode(property, arrayIndexElement, stream, indent, typename, var, caller); return; } if (!property.IsReadonly) { string agentName = GetGenerateAgentName(property, var, caller); string prop = setValue; if (property.Owner != Behaviac.Design.VariableDef.kSelf) { stream.WriteLine("{0}behaviac.Agent {1} = behaviac.Agent.GetInstance(\"{2}\", pAgent.GetContextId());", indent, agentName, property.Owner.Replace("::", ".")); stream.WriteLine("{0}Debug.Check({1} != null);", indent, agentName); } string propBasicName = property.BasicName.Replace("[]", ""); if (setValue != null) { stream.WriteLine("{0}AgentExtra_Generated.SetProperty({1}, \"{2}\", {3});", indent, agentName, propBasicName, prop); } else { prop = getProperty(property, arrayIndexElement, agentName, stream, indent); } uint id = Behaviac.Design.CRC32.CalcCRC(propBasicName); stream.WriteLine("{0}Debug.Check(behaviac.Utils.MakeVariableId(\"{1}\") == {2}u);", indent, propBasicName, id); if (string.IsNullOrEmpty(typename)) { typename = property.NativeType; } typename = DataCsExporter.GetGeneratedNativeType(typename); stream.WriteLine("{0}{1}.SetVariable<{2}>(\"{3}\", {4}, {5}u);", indent, agentName, typename, property.BasicName, prop, id); } }
public static string GenerateCode(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement, bool isRefParam, StreamWriter stream, string indent, string typename, string var, string caller) { if (property.IsPar || property.IsCustomized) return ParInfoCppExporter.GenerateCode(property, isRefParam, stream, indent, typename, var, caller); string prop = GetProperty(property, arrayIndexElement, stream, indent, var, caller); if (!string.IsNullOrEmpty(var)) { if (string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} = {2};", indent, var, prop); } else { stream.WriteLine("{0}{1} {2} = {3};", indent, DataCppExporter.GetGeneratedNativeType(property.NativeType), var, prop); } } return prop; }
public bool ResetMembers(bool check, AgentType agentType, bool clear, MethodDef method, PropertyDef property) { if (this.IsMethod && this.Method != null) { if (method != null && method.OldName == this.Method.Name) { if (!check) { if (clear || this.Method.ShouldBeCleared(agentType)) { this.m_method = null; } else { this.Method.CopyFrom(method); } } return true; } return this.Method.ResetMembers(check, agentType, clear, method, property); } else if (this.Var != null) { return this.Var.ResetMembers(check, agentType, clear, property); } return false; }
public override bool ResetMembers(bool check, AgentType agentType, bool clear, MethodDef method = null, PropertyDef property = null) { bool bReset = false; if (this.Opl != null) { bReset |= this.Opl.ResetMembers(check, agentType, clear, method, property); } if (this.Opr1 != null) { bReset |= this.Opr1.ResetMembers(check, agentType, clear, method, property); } if (this.Opr2 != null) { bReset |= this.Opr2.ResetMembers(check, agentType, clear, method, property); } bReset |= base.ResetMembers(check, agentType, clear, method, property); if (!check && bReset) { OnPropertyValueChanged(false); } return bReset; }
void createParamEditor(MethodDef method, bool enable) { List<MethodDef.Param> parameters = method.Params; foreach (MethodDef.Param p in parameters) { Type editorType = typeof(DesignerParameterComboEnumEditor); string arugmentsName = " " + p.DisplayName; Label label = propertyGrid.AddProperty(arugmentsName, editorType, p.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly)); label.MouseEnter += new EventHandler(label_MouseEnter); DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; editor.Enabled = enable; editor.SetParameter(p, _selectedObject); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.DescriptionWasChanged += editor_DescriptionWasChanged; editor.ValueWasChanged += editor_ValueWasChanged; } }
public bool ResetMembers(bool check, AgentType agentType, bool clear, MethodDef method, PropertyDef property) { bool bReset = false; if (method != null) { if (method.OldName == this.Name) { bReset = true; if (!check) { this.CopyFrom(method); } } } else if (property != null) { foreach (MethodDef.Param param in this.Params) { if (param.Value is VariableDef) { VariableDef var = param.Value as VariableDef; bReset |= var.ResetMembers(check, agentType, clear, property); } else if (param.Value is ParInfo) { ParInfo par = param.Value as ParInfo; if (property.IsPar && (property.OldName == par.Name || !property.IsArrayElement && par.IsArrayElement && (property.OldName + "[]") == par.Name)) { if (clear || this.ShouldBeCleared(agentType)) { bReset = true; if (!check) { param.Value = Plugin.DefaultValue(param.Type); } } else { bReset = true; if (!check) { bool isArrayElement = par.IsArrayElement; par.CopyFrom(property); if (isArrayElement) { par.SetArrayElement(property); } } } } } } } return bReset; }
private static MethodDef CreateAction(AgentType agentType, Type delegateType, string owner, string typeName, string typeDisplayName, bool isNamedEvent, bool isActionMethodOnly, out string displayName) { System.Reflection.MethodInfo method = AgentType.GetMethodInfo(delegateType); System.Reflection.ParameterInfo[] parameters = AgentType.GetMethodParams(method); bool isChangeableType = false; bool isPublic = false; bool isStatic = false; string name = typeName + "::" + delegateType.Name; string nativeReturnType = "void"; displayName = name; string description = name; Attribute[] attributes = (Attribute[])delegateType.GetCustomAttributes(typeof(Behaviac.Design.MethodDescAttribute), false); if (attributes.Length > 0) { MethodDescAttribute methodAttr = (MethodDescAttribute)attributes[0]; isChangeableType = methodAttr.IsChangeableType; isPublic = methodAttr.IsPublic; isStatic = methodAttr.IsStatic; nativeReturnType = methodAttr.NativeReturnType; displayName = typeDisplayName + "::" + methodAttr.DisplayName; description = methodAttr.Description; } MethodDef methodDef = new MethodDef(agentType, isNamedEvent ? MemberType.Task : MemberType.Method, isChangeableType, isPublic, isStatic, typeName, owner, name, displayName, description, nativeReturnType, method.ReturnType, isActionMethodOnly, new List<MethodDef.Param>()); string category = "Arguments"; foreach(System.Reflection.ParameterInfo par in parameters) { Attribute[] paramAttributes = (Attribute[])par.GetCustomAttributes(typeof(Behaviac.Design.ParamDescAttribute), false); string paramNativeType = Plugin.GetNativeTypeName(par.ParameterType); string paramDisplayName = par.Name; string paramDescription = paramDisplayName; string defaultValue = ""; bool isOut = false; bool isRef = false; float rangeMin = float.MinValue; float rangeMax = float.MaxValue; if (paramAttributes.Length > 0) { ParamDescAttribute paramDescAttr = ((ParamDescAttribute)paramAttributes[0]); paramNativeType = paramDescAttr.NativeType; paramDisplayName = paramDescAttr.DisplayName; paramDescription = paramDescAttr.Description; defaultValue = paramDescAttr.DefaultValue; isOut = paramDescAttr.IsOut; isRef = paramDescAttr.IsRef; rangeMin = paramDescAttr.RangeMin; rangeMax = paramDescAttr.RangeMax; } //object value = par.ParameterType.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, null); object value = Plugin.DefaultValue(par.ParameterType, defaultValue); MethodDef.Param p = new MethodDef.Param(category, par, value, paramNativeType, paramDisplayName, paramDescription, isOut, isRef, rangeMin, rangeMax); methodDef.Params.Add(p); } return methodDef; }
public static string GenerateCode(DefaultObject defaultObj, Behaviac.Design.MethodDef method, StringWriter stream, string indent, string typename, string var, string caller) { string allParamTypes = string.Empty; string allParams = string.Empty; for (int i = 0; i < method.Params.Count; ++i) { string nativeType = DataCppExporter.GetGeneratedNativeType(method.Params[i].NativeType); string basicNativeType = DataCppExporter.GetBasicGeneratedNativeType(nativeType); string param = (string.IsNullOrEmpty(var) ? caller : var) + "_p" + i; allParamTypes += ", " + nativeType; if (method.Params[i].IsProperty || method.Params[i].IsLocalVar) // property { VariableDef v = method.Params[i].Value as VariableDef; if (v != null && v.ArrayIndexElement != null) { PropertyDef prop = method.Params[i].Property; if (prop != null && prop.IsArrayElement) { string property = PropertyCppExporter.GetProperty(defaultObj, prop, v.ArrayIndexElement, stream, indent, param, caller); string propName = prop.BasicName.Replace("[]", ""); ParameterCppExporter.GenerateCode(defaultObj, v.ArrayIndexElement, stream, indent, "int", param + "_index", param + caller); param = string.Format("({0})[{1}_index]", property, param); } } else { if ((method.Params[i].Property != null && method.Params[i].Property.IsCustomized) || method.Params[i].IsLocalVar) { ParameterCppExporter.GenerateCode(defaultObj, method.Params[i], stream, indent, basicNativeType, param, caller); } else { if (method.IsPublic) { param = ParameterCppExporter.GenerateCode(defaultObj, method.Params[i], stream, indent, basicNativeType, "", param); } else { ParameterCppExporter.GenerateCode(defaultObj, method.Params[i], stream, indent, basicNativeType, param, caller); } } } } else // const value { object obj = method.Params[i].Value; if (obj != null) { Type type = obj.GetType(); //if (Plugin.IsArrayType(type)) //{ // string nativeTypeStr = DataCppExporter.GetGeneratedNativeType(method.Params[i].NativeType); // int startIndex = nativeTypeStr.IndexOf('<'); // int endIndex = nativeTypeStr.LastIndexOf('>'); // string itemType = nativeTypeStr.Substring(startIndex + 1, endIndex - startIndex - 1); // ArrayCppExporter.GenerateCode(obj, stream, indent, itemType, param); //} //else if (Plugin.IsCustomClassType(type) && !DesignerStruct.IsPureConstDatum(obj, method, method.Params[i].Name)) { StructCppExporter.GenerateCode(obj, defaultObj, stream, indent, param, method, method.Params[i].Name); } } } if (basicNativeType == "System::Object") { param = "*(System::Object*)&" + param; } if (i > 0) { allParams += ", "; } allParams += param; } string agentName = "pAgent"; if (method.Owner != Behaviac.Design.VariableDef.kSelf) { agentName = "pAgent_" + caller; bool isGlobal = Plugin.IsInstanceName(method.Owner, null); PropertyDef ownerProperty = null; if (!isGlobal) { Debug.Check(defaultObj != null && defaultObj.Behavior != null && defaultObj.Behavior.AgentType != null); if (defaultObj != null && defaultObj.Behavior != null && defaultObj.Behavior.AgentType != null) { ownerProperty = defaultObj.Behavior.AgentType.GetPropertyByName(method.Owner); } } if (isGlobal || ownerProperty == null || ownerProperty.IsCustomized || ownerProperty.IsPar) // global or customized instance { stream.WriteLine("{0}Agent* {1} = Agent::GetInstance(pAgent, \"{2}\");", indent, agentName, method.Owner); } else // member instance { string propName = ownerProperty.Name.Replace("::", "_"); string nativeType = DataCppExporter.GetGeneratedNativeType(ownerProperty.NativeType); string prop = string.Format("(({0}*)pAgent)->_Get_Property_<{1}PROPERTY_TYPE_{2}, {3} >()", ownerProperty.ClassName, getNamespace(ownerProperty.ClassName), propName, nativeType); stream.WriteLine("{0}Agent* {1} = {2};", indent, agentName, prop); } stream.WriteLine("{0}BEHAVIAC_ASSERT({1});", indent, agentName); } string nativeReturnType = DataCppExporter.GetGeneratedNativeType(method.NativeReturnType); if (method.NativeReturnType.StartsWith("const ")) { nativeReturnType = "const " + nativeReturnType; } string retStr = ""; if (method.IsPublic) { if (method.IsStatic) { retStr = string.Format("{0}::{1}({2})", method.ClassName, method.BasicName, allParams); } else { retStr = string.Format("(({0}*){1})->{2}({3})", method.ClassName, agentName, method.BasicName, allParams); } } else { retStr = string.Format("(({0}*){1})->_Execute_Method_<{2}METHOD_TYPE_{3}, {4}{5} >({6})", method.ClassName, agentName, getNamespace(method.ClassName), method.Name.Replace("::", "_"), nativeReturnType, allParamTypes, allParams); } if (!string.IsNullOrEmpty(var)) { stream.WriteLine("{0}{1} {2} = {3};", indent, nativeReturnType, var, retStr); } return(retStr); }
public static string GetPropertyNativeType(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement) { string nativeType = DataCppExporter.GetGeneratedNativeType(property.NativeType); return nativeType; }
private static void LoadCustomMembers(List<Nodes.Node.ErrorCheck> result, XmlNode rootNode) { if (rootNode == null) { return; } // Set the default base agent. if (Plugin.AgentTypes.Count == 0) { AgentType agent = new AgentType(typeof(Agent), "Agent", false, "Agent", ""); Plugin.AgentTypes.Add(agent); } foreach(XmlNode xmlNode in rootNode.ChildNodes) { if (xmlNode.Name == "agent") { string agentName = GetAttribute(xmlNode, "type"); string agentBase = GetAttribute(xmlNode, "base"); int baseIndex = -1; for (int i = 0; i < Plugin.AgentTypes.Count; ++i) { if (Plugin.AgentTypes[i].AgentTypeName == agentBase) { baseIndex = i; break; } } string agentDisp = GetAttribute(xmlNode, "disp"); string agentDesc = GetAttribute(xmlNode, "desc"); if (string.IsNullOrEmpty(agentDisp)) { agentDisp = agentName; } AgentType agent = Plugin.GetAgentType(agentName); if (agent == null) { agent = new AgentType(agentName, (baseIndex > -1) ? Plugin.AgentTypes[baseIndex] : null, agentDisp, agentDesc); Plugin.AgentTypes.Add(agent); } foreach(XmlNode bbNode in xmlNode) { if (bbNode.Name == "properties") { foreach(XmlNode propNode in bbNode) { if (propNode.Name == "property") { string propName = GetAttribute(propNode, "name"); string isStatic = GetAttribute(propNode, "static"); bool bStatic = false; if (!string.IsNullOrEmpty(isStatic) && isStatic == "true") { bStatic = true; } string isPublic = GetAttribute(propNode, "public"); bool bPublic = false; if (string.IsNullOrEmpty(isPublic) || isPublic == "true") { bPublic = true; } string isReadonly = GetAttribute(propNode, "readonly"); bool bReadonly = false; if (!string.IsNullOrEmpty(isReadonly) && isReadonly == "true") { bReadonly = true; } string propType = GetAttribute(propNode, "type"); Type type = Plugin.GetTypeFromName(propType); string classname = GetAttribute(propNode, "classname"); if (string.IsNullOrEmpty(classname)) { classname = agent.AgentTypeName; } string propDisp = GetAttribute(propNode, "disp"); if (string.IsNullOrEmpty(propDisp)) { propDisp = propName; } string propDesc = GetAttribute(propNode, "desc"); PropertyDef prop = new PropertyDef(agent, type, classname, propName, propDisp, propDesc); prop.IsStatic = bStatic; prop.IsPublic = bPublic; prop.IsReadonly = bReadonly; string defaultValue = GetAttribute(propNode, "defaultvalue"); if (!string.IsNullOrEmpty(defaultValue)) { prop.Variable = new VariableDef(null); Plugin.InvokeTypeParser(result, type, defaultValue, (object value) => prop.Variable.Value = value, null); } agent.AddProperty(prop); } } } else if (bbNode.Name == "methods") { foreach(XmlNode methodNode in bbNode) { if (methodNode.Name == "method") { string methodName = GetAttribute(methodNode, "name"); Type returnType = Plugin.GetTypeFromName(GetAttribute(methodNode, "returntype")); string isStatic = GetAttribute(methodNode, "static"); bool bStatic = false; if (!string.IsNullOrEmpty(isStatic) && isStatic == "true") { bStatic = true; } string isPublic = GetAttribute(methodNode, "public"); bool bPublic = false; if (string.IsNullOrEmpty(isPublic) || isPublic == "true") { bPublic = true; } string classname = GetAttribute(methodNode, "classname"); if (string.IsNullOrEmpty(classname)) { classname = agent.AgentTypeName; } string methodDisp = GetAttribute(methodNode, "disp"); if (string.IsNullOrEmpty(methodDisp)) { methodDisp = methodName; } string methodDesc = GetAttribute(methodNode, "desc"); bool istask = (GetAttribute(methodNode, "istask") == "true"); //bool isevent = (GetAttribute(methodNode, "isevent") == "true"); MemberType memberType = MemberType.Method; if (istask) { memberType = MemberType.Task; } methodName = string.Format("{0}::{1}", agent.AgentTypeName, methodName); MethodDef method = new MethodDef(agent, memberType, classname, methodName, methodDisp, methodDesc, "", returnType); method.IsStatic = bStatic; method.IsPublic = bPublic; agent.AddMethod(method); foreach(XmlNode paramNode in methodNode) { string paramName = GetAttribute(paramNode, "name"); Type paramType = Plugin.GetTypeFromName(GetAttribute(paramNode, "type")); bool isOut = (GetAttribute(paramNode, "isout") == "true"); bool isRef = (GetAttribute(paramNode, "isref") == "true"); string nativeType = Plugin.GetNativeTypeName(paramType); string paramDisp = GetAttribute(paramNode, "disp"); if (string.IsNullOrEmpty(paramDisp)) { paramDisp = paramName; } string paramDesc = GetAttribute(paramNode, "desc"); MethodDef.Param param = new MethodDef.Param(paramName, paramType, nativeType, paramDisp, paramDesc); param.IsOut = isOut; param.IsRef = isRef; method.Params.Add(param); } } } } } } } }
public static string GetProperty(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement, StreamWriter stream, string indent) { string retStr = string.Empty; if (property != null) { string typename = DataCsExporter.GetGeneratedNativeType(property.NativeType); if (property.IsArrayElement && !typename.StartsWith("List<")) { typename = string.Format("List<{0}>", typename); } string propBasicName = property.BasicName.Replace("[]", ""); uint id = Behaviac.Design.CRC32.CalcCRC(propBasicName); //stream.WriteLine("{0}Debug.Check(behaviac.Utils.MakeVariableId(\"{1}\") == {2}u);", indent, propBasicName, id); retStr = string.Format("({0})pAgent.GetVariable({1}u)", typename, id); } return retStr; }
public static string GetPropertyBasicName(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement) { string propName = property.BasicName; if (property != null && property.IsArrayElement && arrayIndexElement != null) { propName = propName.Replace("[]", ""); } return propName; }
public static void GenerateClassConstructor(Behaviac.Design.MethodDef method, StreamWriter stream, string indent, string var) { Debug.Check(!string.IsNullOrEmpty(var)); if (method.Params.Count == 0) { return; } string paramsName = getParamsName(var, ""); if (!method.IsPublic) { stream.WriteLine("{0}\t\t\t{1} = new object[{2}];", indent, paramsName, method.Params.Count); } for (int i = 0; i < method.Params.Count; ++i) { // const value if (!method.Params[i].IsProperty && !method.Params[i].IsPar) { object obj = method.Params[i].Value; if (obj != null) { string param = getParamName(var, "", i); string paramName = string.Format("{0}[{1}]", paramsName, i); Type type = obj.GetType(); if (Plugin.IsArrayType(type)) { string typename = DataCsExporter.GetGeneratedNativeType(method.Params[i].NativeType); int startIndex = typename.IndexOf('<'); int endIndex = typename.LastIndexOf('>'); string itemType = typename.Substring(startIndex + 1, endIndex - startIndex - 1); ArrayCsExporter.GenerateCode(obj, stream, indent + "\t\t\t", itemType, param); if (!method.IsPublic) { stream.WriteLine("{0}\t\t\t{1} = {2};", indent, paramName, param); } } else if (Plugin.IsCustomClassType(type)) { if (DesignerStruct.IsPureConstDatum(obj, method, method.Params[i].Name)) { if (obj is Behaviac.Design.Agent) { stream.WriteLine("{0}\t\t\t{1} = null;", indent, param); } StructCsExporter.GenerateCode(obj, stream, indent + "\t\t\t", param, null, ""); if (!method.IsPublic) { stream.WriteLine("{0}\t\t\t{1} = {2};", indent, paramName, param); } } } else { string retStr = DataCsExporter.GenerateCode(obj, stream, string.Empty, method.Params[i].NativeType, string.Empty, string.Empty); if (!method.IsPublic) { param = paramName; } stream.WriteLine("{0}\t\t\t{1} = {2};", indent, param, retStr); } } } } }
public static void PostGenerateCode(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement, StreamWriter stream, string indent, string typename, string var, string caller) { if (string.IsNullOrEmpty(typename)) { typename = property.NativeType; } typename = DataCsExporter.GetGeneratedNativeType(typename); string propBasicName = property.BasicName.Replace("[]", ""); uint id = Behaviac.Design.CRC32.CalcCRC(propBasicName); stream.WriteLine("{0}Debug.Check(behaviac.Utils.MakeVariableId(\"{1}\") == {2}u);", indent, propBasicName, id); stream.WriteLine("{0}pAgent.SetVariable<{1}>(\"{2}\", ({1}){3}, {4}u);", indent, typename, property.Name, var, id); }
public static string GenerateCode(Behaviac.Design.MethodDef method, StreamWriter stream, string indent, string typename, string var, string caller) { Debug.Check(!string.IsNullOrEmpty(var) || !string.IsNullOrEmpty(caller)); string allParams = string.Empty; string paramsName = (method.Params.Count == 0) ? "null" : getParamsName(var, caller); for (int i = 0; i < method.Params.Count; ++i) { string nativeType = DataCsExporter.GetGeneratedNativeType(method.Params[i].NativeType); string param = string.Empty; if (method.IsPublic) { param = getParamName(var, caller, i); } else { param = string.Format("{0}[{1}]", paramsName, i); } if (method.Params[i].IsProperty) // property { if (method.IsPublic) { param = ParameterCsExporter.GenerateCode(method.Params[i], stream, indent, nativeType, "", param); } else { ParameterCsExporter.GenerateCode(method.Params[i], stream, indent, "", param, caller); } } else { if (method.Params[i].IsPar) // par { ParameterCsExporter.GenerateCode(method.Params[i], stream, indent, method.IsPublic ? nativeType : "", param, caller); } else // const value { object obj = method.Params[i].Value; if (obj != null) { Type type = obj.GetType(); if (Plugin.IsCustomClassType(type) && !DesignerStruct.IsPureConstDatum(obj, method, method.Params[i].Name)) { string paramName = getParamName(var, caller, i); StructCsExporter.GenerateCode(obj, stream, indent, paramName, method, method.Params[i].Name); if (!method.IsPublic) { stream.WriteLine("{0}{1} = {2};", indent, param, paramName); } } } } } if (i > 0) { allParams += ", "; } //if (method.Params[i].NativeType.EndsWith("&")) if (method.Params[i].NativeType.IndexOf("&") >= 0) { param = "ref " + param; } allParams += param; } string agentName = "pAgent"; if (method.Owner != Behaviac.Design.VariableDef.kSelf && (!method.IsPublic || !method.IsStatic)) { agentName = "pAgent_" + caller; stream.WriteLine("{0}behaviac.Agent {1} = behaviac.Agent.GetInstance(\"{2}\", pAgent.GetContextId());", indent, agentName, method.Owner.Replace("::", ".")); stream.WriteLine("{0}Debug.Check({1} != null);", indent, agentName); } string retStr = string.Empty; if (method.IsPublic) { string className = method.ClassName.Replace("::", "."); if (method.IsStatic) { retStr = string.Format("{0}.{1}({2})", className, method.BasicName, allParams); } else { retStr = string.Format("(({0}){1}).{2}({3})", className, agentName, method.BasicName, allParams); } } else { retStr = string.Format("AgentExtra_Generated.ExecuteMethod({0}, \"{1}\", {2})", agentName, method.BasicName, paramsName); } if (!string.IsNullOrEmpty(var)) { string nativeReturnType = DataCsExporter.GetGeneratedNativeType(method.NativeReturnType); string typeConvertStr = (nativeReturnType == "void") ? string.Empty : "(" + nativeReturnType + ")"; stream.WriteLine("{0}{1} {2} = {3}{4};", indent, nativeReturnType, var, typeConvertStr, retStr); } return(retStr); }
public static string GetProperty(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement, StreamWriter stream, string indent) { string retStr = string.Empty; if (property != null) { string typename = DataCppExporter.GetGeneratedNativeType(property.NativeType); if (!typename.EndsWith("*") && Plugin.IsRefType(property.Type)) { typename += "*"; } if (property.IsArrayElement && !typename.StartsWith("behaviac::vector<")) { typename = string.Format("behaviac::vector<{0} >", typename); } string propBasicName = property.BasicName.Replace("[]", ""); uint id = Behaviac.Design.CRC32.CalcCRC(propBasicName); stream.WriteLine("{0}BEHAVIAC_ASSERT(behaviac::MakeVariableId(\"{1}\") == {2}u);", indent, propBasicName, id); retStr = string.Format("({0}&)pAgent->GetVariable<{0} >({1}u)", typename, id); } return retStr; }
public static string GetProperty(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement, StreamWriter stream, string indent, string var, string caller) { string agentName = GetGenerateAgentName(property, var, caller); if (property.Owner != Behaviac.Design.VariableDef.kSelf) { stream.WriteLine("{0}Agent* {1} = Agent::GetInstance(pAgent, \"{2}\");", indent, agentName, property.Owner); stream.WriteLine("{0}BEHAVIAC_ASSERT({1});", indent, agentName); } string prop = getProperty(property, arrayIndexElement, agentName, stream, indent); return prop; }
public static string GenerateCode(Behaviac.Design.MethodDef method, StreamWriter stream, string indent, string typename, string var, string caller) { string allParamTypes = string.Empty; string allParams = string.Empty; for (int i = 0; i < method.Params.Count; ++i) { string nativeType = DataCppExporter.GetGeneratedNativeType(method.Params[i].NativeType); string basicNativeType = DataCppExporter.GetBasicGeneratedNativeType(nativeType); string param = (string.IsNullOrEmpty(var) ? caller : var) + "_p" + i; allParamTypes += ", " + nativeType; if (method.Params[i].IsProperty || method.Params[i].IsLocalVar) // property { if ((method.Params[i].Property != null && method.Params[i].Property.IsCustomized) || method.Params[i].IsLocalVar) { ParameterCppExporter.GenerateCode(method.Params[i], stream, indent, basicNativeType, param, caller); } else { if (method.IsPublic) { param = ParameterCppExporter.GenerateCode(method.Params[i], stream, indent, basicNativeType, "", param); } else { ParameterCppExporter.GenerateCode(method.Params[i], stream, indent, basicNativeType, param, caller); } } VariableDef v = method.Params[i].Value as VariableDef; if (v != null && v.ArrayIndexElement != null) { PropertyDef prop = method.Params[i].Property; if (prop != null && prop.IsArrayElement) { string property = PropertyCppExporter.GetProperty(prop, v.ArrayIndexElement, stream, indent, param, caller); string propName = prop.BasicName.Replace("[]", ""); ParameterCppExporter.GenerateCode(v.ArrayIndexElement, stream, indent, "int", param + "_index", param + caller); param = string.Format("({0})[{1}_index]", property, param); } } } else // const value { object obj = method.Params[i].Value; if (obj != null) { Type type = obj.GetType(); if (Plugin.IsCustomClassType(type) && !DesignerStruct.IsPureConstDatum(obj, method, method.Params[i].Name)) { StructCppExporter.GenerateCode(obj, stream, indent, param, method, method.Params[i].Name); } } } if (basicNativeType == "System::Object") { param = "*(System::Object*)&" + param; } if (i > 0) { allParams += ", "; } allParams += param; } string agentName = "pAgent"; if (method.Owner != Behaviac.Design.VariableDef.kSelf) { agentName = "pAgent_" + caller; stream.WriteLine("{0}Agent* {1} = Agent::GetInstance(pAgent, \"{2}\");", indent, agentName, method.Owner); stream.WriteLine("{0}BEHAVIAC_ASSERT({1});", indent, agentName); } string nativeReturnType = DataCppExporter.GetGeneratedNativeType(method.NativeReturnType); if (method.NativeReturnType.StartsWith("const ")) { nativeReturnType = "const " + nativeReturnType; } string retStr = ""; if (method.IsPublic) { if (method.IsStatic) { retStr = string.Format("{0}::{1}({2})", method.ClassName, method.BasicName, allParams); } else { retStr = string.Format("(({0}*){1})->{2}({3})", method.ClassName, agentName, method.BasicName, allParams); } } else { retStr = string.Format("(({0}*){1})->_Execute_Method_<{2}METHOD_TYPE_{3}, {4}{5} >({6})", method.ClassName, agentName, getNamespace(method.ClassName), method.Name.Replace("::", "_"), nativeReturnType, allParamTypes, allParams); } if (!string.IsNullOrEmpty(var)) { stream.WriteLine("{0}{1} {2} = {3};", indent, nativeReturnType, var, retStr); } return(retStr); }
public MethodDef(MethodDef other) { CopyFrom(other); }
private bool isNullMethod(MethodDef method) { return (method != null && method.BasicName == "null_method"); }
public static bool IsMatchedStatusMethod(MethodDef method, MethodDef resultFunctor) { if (method != null && resultFunctor != null && resultFunctor.NativeReturnType == "behaviac::EBTStatus") { if (method.NativeReturnType == "void") { return (resultFunctor.Params.Count == 0); } return (resultFunctor.Params.Count == 1) && (resultFunctor.Params[0].Type == method.ReturnType); } return false; }
public static string GenerateCode(DefaultObject defaultObj, Behaviac.Design.MethodDef method, StreamWriter stream, string indent, string typename, string var, string caller) { Debug.Check(!string.IsNullOrEmpty(var) || !string.IsNullOrEmpty(caller)); string allParams = string.Empty; string paramsName = getParamsName(var, caller); for (int i = 0; i < method.Params.Count; ++i) { string nativeType = DataCsExporter.GetGeneratedNativeType(method.Params[i].NativeType); string param = string.Empty; if (method.IsPublic) { param = getParamName(var, caller, i); } else { param = string.Format("{0}[{1}]", paramsName, i); } if (method.Params[i].IsProperty || method.Params[i].IsLocalVar) // property { if ((method.Params[i].Property != null && method.Params[i].Property.IsCustomized) || method.Params[i].IsLocalVar) { ParameterCsExporter.GenerateCode(defaultObj, method.Params[i], stream, indent, method.IsPublic ? nativeType : "", param, caller); } else { if (method.IsPublic) { param = ParameterCsExporter.GenerateCode(defaultObj, method.Params[i], stream, indent, nativeType, "", param); } else { ParameterCsExporter.GenerateCode(defaultObj, method.Params[i], stream, indent, "", param, caller); } } VariableDef v = method.Params[i].Value as VariableDef; if (v != null && v.ArrayIndexElement != null) { PropertyDef prop = method.Params[i].Property; if (prop != null && prop.IsArrayElement) { ParameterCsExporter.GenerateCode(defaultObj, v.ArrayIndexElement, stream, indent, "int", param + "_index", param + caller); if (string.IsNullOrEmpty(param)) { string property = PropertyCsExporter.GetProperty(defaultObj, prop, v.ArrayIndexElement, stream, indent, param, caller); param = string.Format("({0})[{1}_index]", property, param); } else { param = string.Format("{0}[{0}_index]", param); } } } } else // const value { object obj = method.Params[i].Value; if (obj != null) { Type type = obj.GetType(); if (Plugin.IsCustomClassType(type) && !DesignerStruct.IsPureConstDatum(obj, method, method.Params[i].Name)) { string paramName = getParamName(var, caller, i); string paramType = DataCsExporter.GetGeneratedNativeType(method.Params[i].NativeType); StructCsExporter.GenerateCode(obj, defaultObj, stream, indent, paramName, paramType, method, method.Params[i].Name); if (!method.IsPublic) { stream.WriteLine("{0}{1} = {2};", indent, param, paramName); } } } } if (i > 0) { allParams += ", "; } if (method.Params[i].IsRef) { param = "ref " + param; } else if (method.Params[i].IsOut) { param = "out " + param; } allParams += param; } string agentName = "pAgent"; if (method.Owner != Behaviac.Design.VariableDef.kSelf && (!method.IsPublic || !method.IsStatic)) { string instanceName = method.Owner.Replace("::", "."); agentName = "pAgent_" + caller; bool isGlobal = Plugin.IsInstanceName(instanceName, null); PropertyDef ownerProperty = null; if (!isGlobal) { Debug.Check(defaultObj != null && defaultObj.Behavior != null && defaultObj.Behavior.AgentType != null); ownerProperty = defaultObj.Behavior.AgentType.GetPropertyByName(instanceName); } if (isGlobal || ownerProperty == null || ownerProperty.IsCustomized) // global or customized instance { stream.WriteLine("{0}behaviac.Agent {1} = behaviac.Utils.GetParentAgent(pAgent, \"{2}\");", indent, agentName, instanceName); } else // member instance { string prop = ""; if (ownerProperty.IsPublic) { string className = ownerProperty.ClassName.Replace("::", "."); if (ownerProperty.IsStatic) { prop = string.Format("{0}.{1}", className, instanceName); } else { prop = string.Format("(({0})pAgent).{1}", className, instanceName); } } else { string nativeType = DataCsExporter.GetGeneratedNativeType(ownerProperty.NativeType); prop = string.Format("({0})AgentMetaVisitor.GetProperty(pAgent, \"{1}\")", nativeType, instanceName); } stream.WriteLine("{0}behaviac.Agent {1} = {2};", indent, agentName, prop); } stream.WriteLine("{0}Debug.Check({1} != null || Utils.IsStaticClass(\"{2}\"));", indent, agentName, instanceName); } string retStr = string.Empty; if (method.IsPublic) { string className = method.ClassName.Replace("::", "."); if (method.IsStatic) { retStr = string.Format("{0}.{1}({2})", className, method.BasicName, allParams); } else { retStr = string.Format("(({0}){1}).{2}({3})", className, agentName, method.BasicName, allParams); } } else { retStr = string.Format("AgentMetaVisitor.ExecuteMethod({0}, \"{1}\", {2})", agentName, method.BasicName, paramsName); } if (!string.IsNullOrEmpty(var)) { string nativeReturnType = DataCsExporter.GetGeneratedNativeType(method.NativeReturnType); string typeConvertStr = (nativeReturnType == "void") ? string.Empty : "(" + nativeReturnType + ")"; stream.WriteLine("{0}{1} {2} = {3}{4};", indent, nativeReturnType, var, typeConvertStr, retStr); } return(retStr); }
private void resetMembersInWorkspace(AgentType agentType, bool clear, MethodDef method, PropertyDef property) { foreach(Nodes.BehaviorNode behavior in getAllBehaviors(property)) { if (behavior != null && behavior is Nodes.Node) { bool bReset = ((Nodes.Node)behavior).ResetMembers(false, agentType, clear, method, property); if (bReset) UndoManager.Save(behavior); } } }
/// <summary> /// Generate the native code for the given value object. /// </summary> /// <param name="obj">The given object.</param> /// <param name="stream">The file stream for generating the codes.</param> /// <param name="indent">The indent string when generating the line of codes.</param> /// <param name="typename">The native type of the variable.</param> /// <param name="var">The variable for the given object when generating the codes.</param> /// <param name="caller">The caller for the method or the agent.</param> /// <returns>Returns the string generated value.</returns> public static string GenerateCode(object obj, StreamWriter stream, string indent, string typename, string var, string caller) { string retStr = string.Empty; if (obj != null) { Type type = obj.GetType(); if (obj is Behaviac.Design.MethodDef) { Behaviac.Design.MethodDef method = obj as Behaviac.Design.MethodDef; retStr = MethodCppExporter.GenerateCode(method, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.MethodDef.Param) { Behaviac.Design.MethodDef.Param param = obj as Behaviac.Design.MethodDef.Param; retStr = ParameterCppExporter.GenerateCode(param, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.ParInfo) { Behaviac.Design.ParInfo par = obj as Behaviac.Design.ParInfo; retStr = ParInfoCppExporter.GenerateCode(par, false, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.PropertyDef) { Behaviac.Design.PropertyDef property = obj as Behaviac.Design.PropertyDef; retStr = PropertyCppExporter.GenerateCode(property, null, false, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.VariableDef) { Behaviac.Design.VariableDef variable = obj as Behaviac.Design.VariableDef; retStr = VariableCppExporter.GenerateCode(variable, false, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.RightValueDef) { Behaviac.Design.RightValueDef rightValue = obj as Behaviac.Design.RightValueDef; retStr = RightValueCppExporter.GenerateCode(rightValue, stream, indent, typename, var, caller); } // Array type else if (Plugin.IsArrayType(type)) { retStr = var; if (!string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} {2};", indent, DataCppExporter.GetBasicGeneratedNativeType(typename), var); } else { typename = DataCppExporter.GetGeneratedNativeType(type); } int startIndex = typename.IndexOf('<'); int endIndex = typename.LastIndexOf('>'); string itemType = typename.Substring(startIndex + 1, endIndex - startIndex - 1); ArrayCppExporter.GenerateCode(obj, stream, indent, itemType, var); } // Struct type else if (Plugin.IsCustomClassType(type)) { retStr = var; if (!string.IsNullOrEmpty(typename)) { if (typename.EndsWith("*")) { stream.WriteLine("{0}{1} {2} = NULL;", indent, DataCppExporter.GetBasicGeneratedNativeType(typename), var); } else { stream.WriteLine("{0}{1} {2};", indent, DataCppExporter.GetBasicGeneratedNativeType(typename), var); } } StructCppExporter.GenerateCode(obj, stream, indent, var, null, ""); } // Other types else { retStr = obj.ToString(); if (Plugin.IsStringType(type)) // string { retStr = string.Format("\"{0}\"", retStr); if (typename.StartsWith("behaviac::wstring")) { retStr = string.Format("StringUtils::MBSToWCS({0})", retStr); } else { retStr = string.Format("(char*)({0})", retStr); } } else if (Plugin.IsBooleanType(type)) // bool { retStr = retStr.ToLowerInvariant(); } else if (Plugin.IsEnumType(type)) // enum { retStr = EnumCppExporter.GeneratedCode(obj); } else if (Plugin.IsFloatType(type)) // float { if (retStr.Contains(".") && !retStr.EndsWith("f") && !retStr.EndsWith("F")) { retStr = retStr + "f"; } } if (!string.IsNullOrEmpty(var)) { if (string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} = {2};", indent, var, retStr); } else { typename = DataCppExporter.GetGeneratedNativeType(typename); stream.WriteLine("{0}{1} {2} = {3};", indent, typename, var, retStr); } } } } return(retStr); }
public MemberItem(string displayName, MethodDef method) { DisplayName = displayName; Method = method; }
public override bool ResetMembers(bool check, AgentType agentType, bool clear, MethodDef method = null, PropertyDef property = null) { bool bReset = false; if (this._task != null && method != null && this._task.Name == method.OldName) { if (method != null && this._task.Name == method.OldName && (clear || this._task.ShouldBeCleared(agentType))) { bReset = true; if (!check) { this._task = null; } } else { bReset |= this._task.ResetMembers(check, agentType, clear, method, property); } } bReset |= base.ResetMembers(check, agentType, clear, method, property); return bReset; }
private bool checkMembersInWorkspace(AgentType agentType, bool clear, MethodDef method, PropertyDef property) { foreach(Nodes.BehaviorNode behavior in getAllBehaviors(property)) { if (behavior != null && behavior is Nodes.Node) { bool bReset = ((Nodes.Node)behavior).ResetMembers(true, agentType, clear, method, property); if (bReset) return DialogResult.Yes == MessageBox.Show(Resources.ModifyMemberWarning, Resources.Warning, MessageBoxButtons.YesNo); } } return true; }
public RightValueDef(MethodDef method, string valueClass) { m_method = method; _valueClass = valueClass; }
private string getPrefixString(MethodDef m) { if (m != null) { if (m.IsChangeableType) return (m.ReturnType == typeof(object)) ? Empty_Type_Str : Changeable_Type_Str; if (m.IsCustomized) return Customized_Str; } return Member_Str; }
public static Type GetListParamItemType(MethodDef.Param param) { Type type = null; if (param.ListParam.Value is VariableDef) { VariableDef varDef = param.ListParam.Value as VariableDef; type = varDef.ValueType; } else if (param.ListParam.Value is ParInfo) { ParInfo pi = param.ListParam.Value as ParInfo; type = pi.Type; } if (Plugin.IsArrayType(type)) { Type itemType = type.GetGenericArguments()[0]; return itemType; } return null; }
/// <summary> /// Generate code for the given value object. /// </summary> /// <param name="obj">The given object.</param> /// <param name="stream">The file stream for generating the codes.</param> /// <param name="indent">The indent string when generating the line of codes.</param> /// <param name="typename">The native type of the variable.</param> /// <param name="var">The variable for the given object when generating the codes.</param> /// <param name="caller">The caller for the method or the agent.</param> /// <returns>Returns the string generated value.</returns> public static string GenerateCode(object obj, StreamWriter stream, string indent, string typename, string var, string caller, string setValue = null) { string retStr = string.Empty; if (obj != null) { Type type = obj.GetType(); if (obj is Behaviac.Design.MethodDef) { Behaviac.Design.MethodDef method = obj as Behaviac.Design.MethodDef; retStr = MethodCsExporter.GenerateCode(method, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.MethodDef.Param) { Behaviac.Design.MethodDef.Param param = obj as Behaviac.Design.MethodDef.Param; retStr = ParameterCsExporter.GenerateCode(param, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.ParInfo) { Behaviac.Design.ParInfo par = obj as Behaviac.Design.ParInfo; retStr = ParInfoCsExporter.GenerateCode(par, false, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.PropertyDef) { Behaviac.Design.PropertyDef property = obj as Behaviac.Design.PropertyDef; retStr = PropertyCsExporter.GenerateCode(property, null, false, stream, indent, typename, var, caller, setValue); } else if (obj is Behaviac.Design.VariableDef) { Behaviac.Design.VariableDef variable = obj as Behaviac.Design.VariableDef; retStr = VariableCsExporter.GenerateCode(variable, false, stream, indent, typename, var, caller); } else if (obj is Behaviac.Design.RightValueDef) { Behaviac.Design.RightValueDef rightValue = obj as Behaviac.Design.RightValueDef; retStr = RightValueCsExporter.GenerateCode(rightValue, stream, indent, typename, var, caller); } // Array type else if (Plugin.IsArrayType(type)) { retStr = var; if (!string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} {2};", indent, typename, var); } else { typename = DataCsExporter.GetGeneratedNativeType(type); } int startIndex = typename.IndexOf('<'); int endIndex = typename.LastIndexOf('>'); string itemType = typename.Substring(startIndex + 1, endIndex - startIndex - 1); ArrayCsExporter.GenerateCode(obj, stream, indent, itemType, var); } // Struct type else if (Plugin.IsCustomClassType(type)) { retStr = var; if (!string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} {2};", indent, typename, var); } StructCsExporter.GenerateCode(obj, stream, indent, var, null, ""); } // Other types else { retStr = obj.ToString(); if (Plugin.IsStringType(type)) // string { retStr = string.Format("\"{0}\"", retStr); } else if (Plugin.IsCharType(type)) // char { char c = 'A'; if (retStr.Length >= 1) { c = retStr[0]; } retStr = string.Format("\'{0}\'", c); } else if (Plugin.IsBooleanType(type)) // bool { retStr = retStr.ToLowerInvariant(); } else if (Plugin.IsEnumType(type)) // enum { retStr = EnumCsExporter.GeneratedCode(obj); } else if (type == typeof(float)) // float { retStr += "f"; } if (!string.IsNullOrEmpty(var)) { if (string.IsNullOrEmpty(typename)) { stream.WriteLine("{0}{1} = {2};", indent, var, retStr); } else { stream.WriteLine("{0}{1} {2} = {3};", indent, typename, var, retStr); } } } } return(retStr); }
public void CopyFrom(MethodDef other) { _agentType = other._agentType; _isChangeableType = other._isChangeableType; _isPublic = other._isPublic; _isStatic = other._isStatic; _classname = other._classname; _owner = other._owner; _name = other._name; _displayName = other._displayName; _description = other._description; _nativeReturnType = other._nativeReturnType; _returnType = other._returnType; _isActionMethodOnly = other._isActionMethodOnly; _memberType = other._memberType; _isCustomized = other._isCustomized; _params.Clear(); foreach (Param param in other.Params) _params.Add(new Param(param)); }
private static string getProperty(Behaviac.Design.PropertyDef property, MethodDef.Param arrayIndexElement, string agentName, StreamWriter stream, string indent) { if (property.IsPar || property.IsCustomized) return ParInfoCppExporter.GetProperty(property, arrayIndexElement, stream, indent); string propName = DataCppExporter.GetPropertyBasicName(property, arrayIndexElement); string nativeType = DataCppExporter.GetPropertyNativeType(property, arrayIndexElement); if (property.IsPublic) { string className = property.ClassName; if (property.IsStatic) { return string.Format("{0}::{1}", className, propName); } else { return string.Format("(({0}*){1})->{2}", className, agentName, propName); } } propName = property.Name.Replace("::", "_"); propName = propName.Replace("[]", ""); return string.Format("(({0}*){1})->_Get_Property_<{2}PROPERTY_TYPE_{3}, {4} >()", property.ClassName, agentName, getNamespace(property.ClassName), propName, nativeType); }