protected virtual bool AllowProperty(DefProperty p) { if (p.Function.HasAttribute<IgnoreAttribute>() || IsUnhandledType(p)) return false; else if (p.Class.IsSingleton && (p.Name == "Singleton" || p.Name == "SingletonPtr")) return false; else return true; }
protected override void AddProperty(DefProperty p) { if (p.Function.IsVirtual) base.AddProperty(p); }
protected override bool AllowProperty(DefProperty p) { if (base.AllowProperty(p)) { if (p.Name == "Singleton" || p.Name == "SingletonPtr") return false; else return true; } else return false; }
protected DefProperty EnhanceProperty(DefProperty property) { DefProperty prop = property.Clone(); if (_t.BaseClass != null) { if (!prop.CanWrite) { // There's a chance the class overrides only the get function. If the // property is not declared virtual then it will be read-only, so if // it's not virtual check if a base class contains the set property // and if it does, include it. // If it's virtual and its base function will be declared virtual, this // function will be declared virtual too, so it's not necessary to add // the set function. if (!DeclareAsVirtual(prop.GetterFunction)) { DefProperty bp = _t.BaseClass.GetProperty(prop.Name, true); if (bp != null && bp.CanWrite) { prop.CanWrite = true; prop.SetterFunction = bp.SetterFunction; } } } if (!prop.CanRead) { // There's a chance the class overrides only the set function. If the // property is not declared virtual then it will be write-only, so if // it's not virtual check if a base class contains the set property // and if it does, include it. // If it's virtual and its base function will be declared virtual, this // function will be declared virtual too, so it's not necessary to add // the get function. if (!DeclareAsVirtual(prop.SetterFunction)) { DefProperty bp = _t.BaseClass.GetProperty(prop.Name, true); if (bp != null && bp.CanRead) { prop.CanRead = true; prop.GetterFunction = bp.GetterFunction; } } } } return prop; }
protected virtual void AddProperty(DefProperty prop) { }
protected virtual void AddInterfaceProperty(DefProperty prop) { AddProperty(prop); }
public static DefProperty[] GetPropertiesFromFunctions(List<DefFunction> funcs) { SortedList<string, DefProperty> props = new SortedList<string, DefProperty>(); foreach (DefFunction f in funcs) { if (f.IsProperty) { DefProperty p = null; if (props.ContainsKey(f.CLRName)) p = props[f.CLRName]; else { p = new DefProperty(); p.Name = f.CLRName; if (f.IsGetProperty) { p.TypeName = f.TypeName; p.PassedByType = f.PassedByType; } else { p.TypeName = f.Parameters[0].TypeName; p.PassedByType = f.Parameters[0].PassedByType; } props.Add(f.CLRName, p); } if (f.IsGetProperty) { p.CanRead = true; p.GetterFunction = f; } else if (f.IsSetProperty) { p.CanWrite = true; p.SetterFunction = f; } } } DefProperty[] parr = new DefProperty[props.Count]; for (int i = 0; i < props.Count; i++) parr[i] = props.Values[i]; return parr; }
protected override void AddProperty(DefProperty p) { string ptype = GetCLRTypeName(p); string pname = GetClassName() + "::" + p.Name; if (p.CanRead) { if (!(p.GetterFunction.IsAbstract && AllowSubclassing)) { if (AllowProtectedMembers || p.GetterFunction.ProtectionType != ProtectionType.Protected) { string managedType = GetMethodNativeCall(p.GetterFunction, 0); _sb.AppendLine(ptype + " " + pname + "::get()"); _sb.AppendLine("{"); if (_cachedMembers.Contains(p.GetterFunction)) { string priv = NameToPrivate(p.Name); _sb.AppendLine("\treturn ( CLR_NULL == " + priv + " ) ? (" + priv + " = " + managedType + ") : " + priv + ";"); } else { _sb.AppendLine("\treturn " + managedType + ";"); } _sb.AppendLine("}"); } } } if (p.CanWrite) { if (!(p.SetterFunction.IsAbstract && AllowSubclassing)) { if (AllowProtectedMembers || p.SetterFunction.ProtectionType != ProtectionType.Protected) { _sb.AppendLine("void " + pname + "::set( " + ptype + " " + p.SetterFunction.Parameters[0].Name + " )"); _sb.AppendLine("{"); _sb.IncreaseIndent(); string preCall = GetMethodPreNativeCall(p.SetterFunction, 1); string nativeCall = GetMethodNativeCall(p.SetterFunction, 1); string postCall = GetMethodPostNativeCall(p.SetterFunction, 1); if (!String.IsNullOrEmpty(preCall)) _sb.AppendLine(preCall); _sb.AppendLine(nativeCall + ";"); if (!String.IsNullOrEmpty(postCall)) _sb.AppendLine(postCall); _sb.DecreaseIndent(); _sb.AppendLine("}"); } } } }
protected override void AddProperty(DefProperty p) { //TODO comments for properties //AddComments(p); string ptype = GetCLRTypeName(p); _sb.AppendFormatIndent("property {0} {1}\n{{\n", ptype, p.Name); if (p.CanRead) { DefFunction f = p.GetterFunction; bool methodIsVirtual = DeclareAsVirtual(f); if (p.GetterFunction.ProtectionType == ProtectionType.Public || (AllowProtectedMembers && p.GetterFunction.ProtectionType == ProtectionType.Protected) ) { _sb.AppendLine(GetProtectionString(p.GetterFunction.ProtectionType) + ":"); if (AllowMethodIndexAttributes && f.IsVirtual && !f.IsAbstract) { _sb.Append("\t"); AddMethodIndexAttribute(f); } _sb.AppendIndent("\t"); if (p.GetterFunction.IsStatic) _sb.Append("static "); if (methodIsVirtual) _sb.Append("virtual "); _sb.Append(ptype + " get()"); if (DeclareAsOverride(p.GetterFunction)) { _sb.Append(" override"); } else if (f.IsAbstract && AllowSubclassing) { _sb.Append(" abstract"); } _sb.Append(";\n"); } } if (p.CanWrite) { DefFunction f = p.SetterFunction; bool methodIsVirtual = DeclareAsVirtual(f); if (p.SetterFunction.ProtectionType == ProtectionType.Public || (AllowProtectedMembers && p.SetterFunction.ProtectionType == ProtectionType.Protected) ) { _sb.AppendLine(GetProtectionString(p.SetterFunction.ProtectionType) + ":"); if (AllowMethodIndexAttributes && f.IsVirtual && !f.IsAbstract) { _sb.Append("\t"); AddMethodIndexAttribute(f); } _sb.AppendIndent("\t"); if (p.SetterFunction.IsStatic) _sb.Append("static "); if (methodIsVirtual) _sb.Append("virtual "); _sb.Append("void set(" + ptype + " " + p.SetterFunction.Parameters[0].Name + ")"); if (DeclareAsOverride(p.SetterFunction)) { _sb.Append(" override"); } else if (f.IsAbstract && AllowSubclassing) { _sb.Append(" abstract"); } _sb.Append(";\n"); } } _sb.AppendLine("}"); }