public virtual CppType GetMangleType(ICustomAttributeProvider icap, Type managedType) { CppType mangleType = new CppType(); MangleAsAttribute maa = (MangleAsAttribute)icap.GetCustomAttributes(typeof(MangleAsAttribute), false).FirstOrDefault(); if (maa != null) { mangleType = maa.MangleType; } // this means that either no MangleAsAttribute was defined, or // only CppModifiers were applied .. apply CppType from managed parameter type if (mangleType.ElementType == CppTypes.Unknown && mangleType.ElementTypeName == null) { mangleType.CopyTypeFrom(CppType.ForManagedType(managedType)); } else if (typeof(Delegate).IsAssignableFrom(managedType)) { mangleType.ElementType = CppTypes.Delegate; mangleType.Modifiers.Add(CppModifiers.Delegate); } else if (mangleType.ElementType == CppTypes.Unknown) { // FIXME: otherwise, we just assume it's CppTypes.Class for now. mangleType.ElementType = CppTypes.Class; } return(mangleType); }
CppType GetType(Node n, CppType modifiers) { var fundamental = CppTypes.Unknown; switch (n.Type) { case "Typedef": return(GetType(GetTypeNode(n), modifiers)); case "ArrayType": CppModifiers mod = null; var max = n.Attributes ["max"]; var min = n.Attributes ["min"]; if (max != null && min != null) { var l = GetLongValue(max) - GetLongValue(min); mod = new CppModifiers.ArrayModifier((int)l + 1); } else { mod = CppModifiers.Array; } return(GetType(GetTypeNode(n), modifiers.Modify(mod))); case "PointerType": return(GetType(GetTypeNode(n), modifiers.Modify(CppModifiers.Pointer))); case "ReferenceType": return(GetType(GetTypeNode(n), modifiers.Modify(CppModifiers.Reference))); case "FundamentalType": return(modifiers.CopyTypeFrom(new CppType(n.Name))); case "CvQualifiedType": if (n.IsTrue("const")) { return(GetType(GetTypeNode(n), modifiers.Modify(CppModifiers.Const))); } else { throw new NotImplementedException(); } case "Class": fundamental = CppTypes.Class; break; case "Struct": fundamental = CppTypes.Struct; break; case "Enumeration": fundamental = CppTypes.Enum; break; case "FunctionType": fundamental = CppTypes.Delegate; break; default: return(CppTypes.Unknown); } if (!NodeToNamespace.ContainsKey(n)) { // FIXME: Do something better if (string.IsNullOrEmpty(n.Name)) { Console.WriteLine("WARNING: Could not find type with id '{0}'", n.Id); } else { Console.WriteLine("WARNING: Could not find type '{0}'", n.Name); } return(CppTypes.Unknown); } return(modifiers.CopyTypeFrom(new CppType(fundamental, string.Join("::", NodeToNamespace [n].FullyQualifiedName)))); }
CppType GetType(Node n, CppType modifiers) { var fundamental = CppTypes.Unknown; switch (n.Type) { case "Typedef": return(GetType(GetTypeNode(n), modifiers)); case "ArrayType": CppModifiers mod = null; if (n.Attributes ["max"] != null && n.Attributes ["min"] != null) { mod = new CppModifiers.ArrayModifier(int.Parse(n.Attributes ["max"].TrimEnd('u')) - int.Parse(n.Attributes ["min"].TrimEnd('u')) + 1); } else { mod = CppModifiers.Array; } return(GetType(GetTypeNode(n), modifiers.Modify(mod))); case "PointerType": return(GetType(GetTypeNode(n), modifiers.Modify(CppModifiers.Pointer))); case "ReferenceType": return(GetType(GetTypeNode(n), modifiers.Modify(CppModifiers.Reference))); case "FundamentalType": return(modifiers.CopyTypeFrom(new CppType(n.Name))); case "CvQualifiedType": if (n.IsTrue("const")) { return(GetType(GetTypeNode(n), modifiers.Modify(CppModifiers.Const))); } else { throw new NotImplementedException(); } case "Class": fundamental = CppTypes.Class; break; case "Struct": fundamental = CppTypes.Struct; break; case "Enumeration": fundamental = CppTypes.Enum; break; default: return(CppTypes.Unknown); } if (!NodeToNamespace.ContainsKey(n)) { // FIXME: Do something better return(CppTypes.Unknown); } return(modifiers.CopyTypeFrom(new CppType(fundamental, string.Join("::", NodeToNamespace [n].FullyQualifiedName)))); }