/// <summary> /// Check whether the specified name and namespace is mapped to a LogicalType /// object. Returns true if there is a mapping. Otherwise, false is returned. /// </summary> /// <param name="typeOrigin">Specifies whether /// the type that was found is either intrinsic or user defined. /// </param> public bool ContainsType(XmlQualifiedName qname, bool encoded, TypeOrigin originsToSearch, out TypeOrigin typeOrigin) { Dictionary <XmlQualifiedName, LogicalType> nameTable; lock (_lookUpLock) { nameTable = encoded ? _userEncodedTypesByQName : _userLiteralTypesByQName; if (0 != (originsToSearch & TypeOrigin.Intrinsic) && s_intrinsicsByName.ContainsKey(qname)) { typeOrigin = TypeOrigin.Intrinsic; return(true); } if (0 != (originsToSearch & TypeOrigin.User) && nameTable.ContainsKey(qname)) { typeOrigin = TypeOrigin.User; return(true); } typeOrigin = TypeOrigin.None; return(false); } }
/// <summary> /// Retrieves the LogicalType mapped to the specified Type object. Null is /// returned if no LogicalType is mapped to the specified Type. /// </summary> /// <param name="typeOrigin"> /// The TypeOrigin out parameter specifies whether the type that was found is /// either intrinsic or user defined. /// </param> internal LogicalType GetType(XmlQualifiedName qname, bool encoded, TypeOrigin originsToSearch, out TypeOrigin typeOrigin) { Dictionary <XmlQualifiedName, LogicalType> typeTable; lock (_lookUpLock) { typeTable = encoded ? _userEncodedTypesByQName : _userLiteralTypesByQName; if (0 != (originsToSearch & TypeOrigin.Intrinsic) && s_intrinsicsByName.ContainsKey(qname)) { typeOrigin = TypeOrigin.Intrinsic; return(s_intrinsicsByName[qname]); } else if (0 != (originsToSearch & TypeOrigin.User) && typeTable.ContainsKey(qname)) { typeOrigin = TypeOrigin.User; return(typeTable[qname]); } else { typeOrigin = TypeOrigin.None; return(null); } } }
public static void StripUnreferencedTypes(this AST.Definition def, TypeOrigin includeOrigin) { var unref = new HashSet <AST.Type>(); foreach (var type in def.AllTypes.Where(t => t.ConstructType == AST.Construct.Object || t.ConstructType == AST.Construct.Struct || t.ConstructType == AST.Construct.Enum)) { unref.Add(type); } foreach (var rootType in def.AllTypes.SelectGeneratedTypes(includeOrigin)) { if (unref.Contains(rootType)) { unref.Remove(rootType); } foreach (var refType in rootType.SelectReferencedTypes()) { if (unref.Contains(refType)) { unref.Remove(refType); } } } foreach (var t in unref) { def.AllTypes.Remove(t); } }
public static void RenameParametersToClarifyContext(this AST.Definition def, TypeOrigin includeOrigin = TypeOrigin.Gluon) { foreach (var t in def.AllTypes.SelectGeneratedTypes(includeOrigin).OfType <AST.Object>()) { foreach (var c in t.Constructors) { foreach (var p in c.Parameters) { if (p.IsOut) { p.Name = "out" + p.Name.Capitalize(); } else if (p.IsRef) { p.Name = "inout" + p.Name.Capitalize(); } } } foreach (var m in t.Methods) { foreach (var p in m.Parameters) { if (p.IsOut) { p.Name = "out" + p.Name.Capitalize(); } else if (p.IsRef) { p.Name = "inout" + p.Name.Capitalize(); } } } } }
public static void PutDefaultConstructorsFirst(this AST.Definition def, TypeOrigin includedOrigin = TypeOrigin.Gluon) { foreach (var t in def.AllTypes.SelectGeneratedTypes(includedOrigin).OfType <AST.Object>()) { var dc = t.Constructors.FirstOrDefault(c => c.Parameters.Count == 0); if (dc == null || t.Constructors[0] == dc) { continue; } t.Constructors.Remove(dc); t.Constructors.Insert(0, dc); } }
private LogicalType GetType(TypeAndNamespace typeAndNamespace, bool encoded, TypeOrigin originsToSearch, out TypeOrigin typeOrigin) { // If a specific namespace is needed, check to see whether the type sought after is // a one-namespace-fits-all and has already been reflected. if (typeAndNamespace.DefaultNamespace != null) { // looking for a specific namespace // does a one-size-fits-all exist? LogicalType lType = GetTypeInternal(new TypeAndNamespace(typeAndNamespace.Type, null), encoded, originsToSearch, out typeOrigin); if (lType != null) { return(lType); } } // The sought for type either hasn't been reflected over, or must be prepared // for each namespace it appears in. Search for the specific one and return result. return(GetTypeInternal(typeAndNamespace, encoded, originsToSearch, out typeOrigin)); }
/// <summary> /// Retrieves the LogicalType mapped to the specified Type object. Null is /// returned if no LogicalType is mapped to the specified Type. /// </summary> /// <param name="typeOrigin"> /// The TypeOrigin out parameter specifies whether the type that was found is /// either intrinsic or user defined. /// </param> internal LogicalType GetType(XmlQualifiedName qname, bool encoded, out TypeOrigin typeOrigin) { return(GetType(qname, encoded, TypeOrigin.All, out typeOrigin)); }
private LogicalType GetTypeInternal(TypeAndNamespace typeAndNamespace, bool encoded, TypeOrigin originsToSearch, out TypeOrigin typeOrigin) { Dictionary <TypeAndNamespace, LogicalType> typeTable; lock (_lookUpLock) { typeTable = encoded ? _userEncodedTypesByType : _userLiteralTypesByType; if (0 != (originsToSearch & TypeOrigin.Intrinsic) && s_intrinsicsByType.ContainsKey(typeAndNamespace.Type)) { typeOrigin = TypeOrigin.Intrinsic; return(s_intrinsicsByType[typeAndNamespace.Type]); } else if (0 != (originsToSearch & TypeOrigin.User) && typeTable.ContainsKey(typeAndNamespace)) { typeOrigin = TypeOrigin.User; return(typeTable[typeAndNamespace]); } else { typeOrigin = TypeOrigin.None; return(null); } } }
/// <summary> /// Retrieves the LogicalType mapped to the specified Type object. Null is /// returned if no LogicalType is mapped to the specified Type. /// </summary> /// <param name="typeOrigin"> /// The TypeOrigin out parameter specifies whether the type that was found is /// either intrinsic or user defined. /// </param> public LogicalType GetType(Type type, string ns, bool encoded, TypeOrigin originsToSearch, out TypeOrigin typeOrigin) { return(GetType(new TypeAndNamespace(type, ns), encoded, originsToSearch, out typeOrigin)); }
/// <summary> /// Check whether the specified name and namespace is mapped to a LogicalType /// object. Returns true if there is a mapping. Otherwise, false is returned. /// </summary> /// <param name="typeOrigin">Specifies whether /// the type that was found is either intrinsic or user defined. /// </param> public bool ContainsType(XmlQualifiedName qname, bool encoded, out TypeOrigin typeOrigin) { return(ContainsType(qname, encoded, TypeOrigin.All, out typeOrigin)); }
/// <summary> /// Check whether the specified Type object is mapped to a LogicalType object. /// Returns true if there is a mapping. Otherwise, false is returned. /// </summary> /// <param name="typeOrigin">Specifies whether the type that was found is either /// intrinsic or user defined.</param> public bool ContainsType(Type type, string ns, bool encoded, TypeOrigin originsToSearch, out TypeOrigin typeOrigin) { return(ContainsType(new TypeAndNamespace(type, ns), encoded, originsToSearch, out typeOrigin)); }
public static IEnumerable <Type> SelectGeneratedTypes(this IEnumerable <Type> types, TypeOrigin includedNonGluonOrigin = TypeOrigin.Gluon) { return(types.Where(t => t.Origin == TypeOrigin.Gluon || t.Origin == includedNonGluonOrigin)); }
public static void InsertDefaultConstructorsWhereNoneAreDefined(this AST.Definition def, TypeOrigin includedOrigin = TypeOrigin.Gluon) { foreach (var t in def.AllTypes.SelectGeneratedTypes(includedOrigin).OfType <AST.Object>().Where(t => !t.IsAbstract && t.Constructors.Count == 0)) { t.Constructors.Add(new AST.Constructor { Access = AST.Access.Public, Name = t.Name, Nature = AST.MemberNature.Instance, }); } }