protected virtual void AddCreator(DefFunction f) { if (f == null) { AddCreatorOverload(f, 0); } else { int defcount = 0; if (!f.HasAttribute <NoDefaultParamOverloadsAttribute>()) { foreach (DefParam param in f.Parameters) { if (param.DefaultValue != null) { defcount++; } } } // The overloads (because of default values) for (int dc = 0; dc <= defcount; dc++) { if (dc < defcount && f.HasAttribute <HideParamsWithDefaultValuesAttribute>()) { continue; } AddCreatorOverload(f, f.Parameters.Count - dc); } } }
protected virtual void AddCreator(DefFunction f) { if (f == null) { _sb.AppendLine("static " + _t.CLRName + " Create();"); } else { int defcount = 0; if (!f.HasAttribute <NoDefaultParamOverloadsAttribute>()) { foreach (DefParam param in f.Parameters) { if (param.DefaultValue != null) { defcount++; } } } // The overloads (because of default values) for (int dc = 0; dc <= defcount; dc++) { if (dc < defcount && f.HasAttribute <HideParamsWithDefaultValuesAttribute>()) { continue; } _sb.AppendIndent("static " + _t.CLRName + " Create"); AddMethodParameters(f, f.Parameters.Count - dc); _sb.Append(";\n"); } } }
protected virtual void AddPublicConstructor(DefFunction function) { if (function == null) { AddPublicConstructorOverload(function, 0); } else { int defcount = 0; if (!function.HasAttribute <NoDefaultParamOverloadsAttribute>()) { foreach (DefParam param in function.Parameters) { if (param.DefaultValue != null) { defcount++; } } } bool hideParams = function.HasAttribute <HideParamsWithDefaultValuesAttribute>(); // The overloads (because of default values) for (int dc = 0; dc <= defcount; dc++) { if (dc < defcount && function.HasAttribute <HideParamsWithDefaultValuesAttribute>()) { continue; } AddPublicConstructorOverload(function, function.Parameters.Count - dc); } } }
protected virtual bool?CheckFunctionForGetProperty(DefFunction f) { string name = f.HasAttribute <RenameAttribute>() ? f.GetAttribute <RenameAttribute>().Name : f.Name; if (f.HasAttribute <CustomIncDeclarationAttribute>() || f.HasAttribute <CustomCppDeclarationAttribute>()) { return(false); } if (f.TypeName == "bool" && ((name.StartsWith("is") && Char.IsUpper(name[2])) || (name.StartsWith("has") && Char.IsUpper(name[3]))) && f.Parameters.Count == 0) { return(true); } return(CheckTypeMemberForGetProperty(f)); }
protected virtual void AddPublicConstructor(DefFunction function) { string className = (_t.IsInterface) ? _t.Name : _t.CLRName; if (function == null) { _sb.AppendLine(className + "();"); } else { int defcount = 0; if (!function.HasAttribute <NoDefaultParamOverloadsAttribute>()) { foreach (DefParam param in function.Parameters) { if (param.DefaultValue != null) { defcount++; } } } bool hideParams = function.HasAttribute <HideParamsWithDefaultValuesAttribute>(); // The overloads (because of default values) for (int dc = 0; dc <= defcount; dc++) { if (dc < defcount && hideParams) { continue; } _sb.AppendIndent(className); AddMethodParameters(function, function.Parameters.Count - dc); _sb.Append(";\n"); } } }
protected override void AddMethod(DefFunction f) { string def = f.Definition.Replace(f.Class.FullNativeName, GetClassName()) + "("; if (def.StartsWith("virtual ")) { def = def.Substring("virtual ".Length); } _sb.AppendIndent(def); for (int i = 0; i < f.Parameters.Count; i++) { DefParam param = f.Parameters[i]; _sb.Append(" "); AddNativeMethodParam(param); if (i < f.Parameters.Count - 1) { _sb.Append(","); } } _sb.Append(" )\n"); _sb.AppendLine("{"); _sb.IncreaseIndent(); _sb.AppendLine("if (doCallFor" + f.CLRName + ")"); _sb.AppendLine("{"); _sb.IncreaseIndent(); CppNativeProxyClassProducer.AddNativeProxyMethodBody(f, "_receiver", _sb); _sb.DecreaseIndent(); _sb.AppendLine("}"); if (!f.IsVoid) { _sb.AppendLine("else"); string ret = null; if (f.HasAttribute <DefaultReturnValueAttribute>()) { ret = f.GetAttribute <DefaultReturnValueAttribute>().Name; } else { throw new Exception("Default return value not set."); } _sb.AppendLine("\treturn " + ret + ";"); } _sb.DecreaseIndent(); _sb.AppendLine("}"); }
public override bool HasAttribute <T>() { if (base.HasAttribute <T>()) { return(true); } if (BaseFunction != null) { return(BaseFunction.HasAttribute <T>()); } else { return(false); } }
protected virtual bool AllowFunction(DefFunction f) { if (f.HasAttribute <IgnoreAttribute>() || IsUnhandledType(f)) { return(false); } else { foreach (DefParam param in f.Parameters) { if (IsUnhandledType(param)) { return(false); } } return(true); } }
protected override void AddMethod(DefFunction f) { if (f.HasAttribute <CustomIncDeclarationAttribute>()) { string txt = f.GetAttribute <CustomIncDeclarationAttribute>().DeclarationText; txt = ReplaceCustomVariables(txt, f); _sb.AppendLine(txt); _sb.AppendLine(); return; } int defcount = 0; if (!f.HasAttribute <NoDefaultParamOverloadsAttribute>()) { foreach (DefParam param in f.Parameters) { if (param.DefaultValue != null) { defcount++; } } } bool methodIsVirtual = DeclareAsVirtual(f); // The main method AddComments(f); if (AllowMethodIndexAttributes && f.IsVirtual && !f.IsAbstract) { AddMethodIndexAttribute(f); } _sb.AppendIndent(""); if (f.IsStatic) { _sb.Append("static "); } if (methodIsVirtual) { _sb.Append("virtual "); } _sb.Append(GetCLRTypeName(f) + " " + f.CLRName); AddMethodParameters(f, f.Parameters.Count); if (DeclareAsOverride(f)) { _sb.Append(" override"); } else if (f.IsAbstract && AllowSubclassing) { _sb.Append(" abstract"); } _sb.Append(";\n"); if (AllowMethodOverloads) { // The overloads (because of default values) for (int dc = 1; dc <= defcount; dc++) { if (dc < defcount && f.HasAttribute <HideParamsWithDefaultValuesAttribute>()) { continue; } AddComments(f); _sb.AppendIndent(""); if (f.IsStatic) { _sb.Append("static "); } _sb.Append(GetCLRTypeName(f) + " " + f.CLRName); AddMethodParameters(f, f.Parameters.Count - dc); _sb.Append(";\n"); } } }
public static void AddNativeProxyMethodBody(DefFunction f, string managedTarget, IndentStringBuilder sb) { string managedCall; string fullPostConv = null; if (f.IsGetProperty) { sb.AppendLine(f.CLRTypeName + " mp_return = " + managedTarget + "->" + f.CLRName + ";"); managedCall = "mp_return"; } else if (f.IsSetProperty) { DefParam param = f.Parameters[0]; managedCall = managedTarget + "->" + f.CLRName + " = " + param.Type.GetNativeCallConversion(param.Name, param); } else { string pre, post, conv; foreach (DefParam param in f.Parameters) { param.Type.GetNativeParamConversion(param, out pre, out conv, out post); if (!String.IsNullOrEmpty(pre)) { sb.AppendLine(pre); } if (!String.IsNullOrEmpty(post)) { fullPostConv += post + "\n"; } } bool explicitCast = f.HasAttribute <ExplicitCastingForParamsAttribute>(); if (!f.IsVoid) { sb.AppendIndent(f.CLRTypeName + " mp_return = " + managedTarget + "->" + f.CLRName + "("); for (int i = 0; i < f.Parameters.Count; i++) { DefParam param = f.Parameters[i]; param.Type.GetNativeParamConversion(param, out pre, out conv, out post); sb.Append(" "); if (explicitCast) { sb.Append("(" + param.CLRTypeName + ")"); } sb.Append(conv); if (i < f.Parameters.Count - 1) { sb.Append(","); } } sb.Append(" );\n"); managedCall = "mp_return"; if (!String.IsNullOrEmpty(fullPostConv)) { sb.AppendLine(fullPostConv); } } else { managedCall = managedTarget + "->" + f.CLRName + "("; for (int i = 0; i < f.Parameters.Count; i++) { DefParam param = f.Parameters[i]; param.Type.GetNativeParamConversion(param, out pre, out conv, out post); managedCall += " "; if (explicitCast) { managedCall += "(" + param.CLRTypeName + ")"; } managedCall += conv; if (i < f.Parameters.Count - 1) { managedCall += ","; } } managedCall += " )"; } } if (!f.IsVoid) { if (f.Type is IDefString) { sb.AppendLine("SET_NATIVE_STRING( Mogre::Implementation::cachedReturnString, " + managedCall + " )"); sb.AppendLine("return Mogre::Implementation::cachedReturnString;"); } else { string returnExpr; string newname, expr, postcall; DefParam param = new DefParam(f, managedCall); expr = f.Type.GetPreCallParamConversion(param, out newname); postcall = f.Type.GetPostCallParamConversionCleanup(param); if (!String.IsNullOrEmpty(expr)) { sb.AppendLine(expr); if (String.IsNullOrEmpty(postcall)) { returnExpr = newname; } else { throw new Exception("Unexpected"); } } else { returnExpr = newname; } if (IsCachedFunction(f)) { sb.AppendLine("STATIC_ASSERT( sizeof(" + f.Type.FullNativeName + ") <= CACHED_RETURN_SIZE )"); sb.AppendLine("memcpy( Mogre::Implementation::cachedReturn, &" + returnExpr + ", sizeof(" + f.Type.FullNativeName + ") );"); sb.AppendLine("return *reinterpret_cast<" + f.Type.FullNativeName + "*>(Mogre::Implementation::cachedReturn);"); } else { sb.AppendLine("return " + returnExpr + ";"); } } } else { sb.AppendLine(managedCall + ";"); if (!String.IsNullOrEmpty(fullPostConv)) { sb.AppendLine(fullPostConv); } } }
protected override void AddOverridableFunction(DefFunction f) { _wrapper.CppCheckTypeForDependancy(f.Type); foreach (DefParam param in f.Parameters) { _wrapper.CppCheckTypeForDependancy(param.Type); } _sb.AppendIndent(""); _sb.Append(f.NativeTypeName + " " + ProxyName + "::" + f.Name + "("); AddNativeMethodParams(f); _sb.Append(" )"); if (f.IsConstFunctionCall) { _sb.Append(" const"); } _sb.Append("\n"); _sb.AppendLine("{"); _sb.IncreaseIndent(); if (!f.IsAbstract) { _sb.AppendLine("if (_overriden[ " + _methodIndices[f] + " ])"); _sb.AppendLine("{"); _sb.IncreaseIndent(); } if (f.HasAttribute <CustomNativeProxyDeclarationAttribute>()) { string txt = f.GetAttribute <CustomNativeProxyDeclarationAttribute>().DeclarationText; txt = ReplaceCustomVariables(txt, f).Replace("@MANAGED@", "_managed"); _sb.AppendLine(txt); } else { AddNativeProxyMethodBody(f, "_managed", _sb); } if (!f.IsAbstract) { _sb.DecreaseIndent(); _sb.AppendLine("}"); _sb.AppendLine("else"); _sb.AppendIndent("\t"); if (!f.IsVoid) { _sb.Append("return "); } _sb.Append(f.Class.Name + "::" + f.Name + "("); for (int i = 0; i < f.Parameters.Count; i++) { DefParam param = f.Parameters[i]; _sb.Append(" " + param.Name); if (i < f.Parameters.Count - 1) { _sb.Append(","); } } _sb.Append(" );\n"); } _sb.DecreaseIndent(); _sb.AppendLine("}"); }
protected override void AddMethod(DefFunction f) { if (f.HasAttribute <CustomCppDeclarationAttribute>()) { if (f.IsAbstract && AllowSubclassing) { return; } else { string txt = f.GetAttribute <CustomCppDeclarationAttribute>().DeclarationText; txt = ReplaceCustomVariables(txt, f); _sb.AppendLine(txt); _sb.AppendLine(); return; } } int defcount = 0; if (!f.HasAttribute <NoDefaultParamOverloadsAttribute>()) { foreach (DefParam param in f.Parameters) { if (param.DefaultValue != null) { defcount++; } } } bool methodIsVirtual = DeclareAsVirtual(f); for (int dc = 0; dc <= defcount; dc++) { if (dc == 0 && f.IsAbstract && AllowSubclassing) { //It's abstract, no body definition continue; } if (!AllowMethodOverloads && dc > 0) { continue; } if (dc < defcount && f.HasAttribute <HideParamsWithDefaultValuesAttribute>()) { continue; } _sb.AppendIndent(GetCLRTypeName(f) + " " + GetClassName() + "::" + f.CLRName); AddMethodParameters(f, f.Parameters.Count - dc); _sb.Append("\n"); _sb.AppendLine("{"); _sb.IncreaseIndent(); bool isVirtualOverload = dc > 0 && methodIsVirtual && AllowVirtualMethods; if (isVirtualOverload) { // Overloads (because of default values) // main method is virtual, call it with CLR default values if _isOverriden=true, // else do a normal native call _sb.AppendLine("if (_isOverriden)"); _sb.AppendLine("{"); _sb.IncreaseIndent(); bool hasPostConversions = false; for (int i = f.Parameters.Count - dc; i < f.Parameters.Count; i++) { DefParam p = f.Parameters[i]; if (!String.IsNullOrEmpty(p.CLRDefaultValuePreConversion)) { _sb.AppendLine(p.CLRDefaultValuePreConversion); } if (!String.IsNullOrEmpty(p.CLRDefaultValuePostConversion)) { hasPostConversions = true; } string n1, n2, n3; DefType dependancy; p.Type.GetDefaultParamValueConversion(p, out n1, out n2, out n3, out dependancy); if (dependancy != null) { AddTypeDependancy(dependancy); } } _sb.AppendIndent(""); if (!f.IsVoid) { if (hasPostConversions) { _sb.Append(GetCLRTypeName(f) + " mp_return = "); } else { _sb.Append("return "); } } _sb.Append(f.CLRName + "("); for (int i = 0; i < f.Parameters.Count; i++) { DefParam p = f.Parameters[i]; _sb.Append(" "); if (i < f.Parameters.Count - dc) { _sb.Append(p.Name); } else { _sb.Append(p.CLRDefaultValue); } if (i < f.Parameters.Count - 1) { _sb.Append(","); } } _sb.Append(" );\n"); for (int i = f.Parameters.Count - dc; i < f.Parameters.Count; i++) { DefParam p = f.Parameters[i]; if (!String.IsNullOrEmpty(p.CLRDefaultValuePostConversion)) { _sb.AppendLine(p.CLRDefaultValuePostConversion); } } if (!f.IsVoid && hasPostConversions) { _sb.AppendLine("return mp_return;"); } _sb.DecreaseIndent(); _sb.AppendLine("}"); _sb.AppendLine("else"); _sb.AppendLine("{"); _sb.IncreaseIndent(); } AddMethodBody(f, f.Parameters.Count - dc); if (isVirtualOverload) { _sb.DecreaseIndent(); _sb.AppendLine("}"); } _sb.DecreaseIndent(); _sb.AppendLine("}"); } }