/// <summary> /// Create MethodGenericInstance and connect to the Method, through the Instance edge. /// Furthermore, added GenericParameter to the MethodGenericInstance. /// </summary> /// <param name="symbol">Called method</param> /// <param name="refersTo">Called method definition</param> /// <returns>MethodGenericInstance node from the LIM</returns> public static MethodGenericInstance GetMGI(this ISymbol symbol, IMethodSymbol refersTo) { string uName = symbol.ToString(); MethodGenericInstance mgi; if (MainDeclaration.Instance.MgiMap.TryGetValue(uName, out mgi)) { return(mgi); } mgi = MainDeclaration.Instance.LimFactory.createMethodGenericInstanceNode(); mgi.IsRealInstance = true; mgi.Name = symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); mgi.MangledName = uName; mgi.DemangledName = uName; mgi.Language = Types.LanguageKind.lnkCsharp; IMethodSymbol roslynNode = symbol as IMethodSymbol; Base owner = refersTo != null?refersTo.ConvertToLimNode() : symbol.OriginalDefinition.ConvertToLimNode(); if (owner == null) { return(null); } if (Lim.Asg.Common.getIsMethod(owner)) { Method ownerMethod = owner as Method; Commons.Common.Safe_Edge(ownerMethod, "Instance", mgi.Id); if (roslynNode.Arity > 0) { int i = 0; foreach (var argument in roslynNode.TypeArguments) { ITypeSymbol arg = null; if (!argument.IsInMetadata() && argument.TypeKind != TypeKind.TypeParameter) { SyntaxNode _tmp = null; arg = (INamedTypeSymbol)argument.GetDefinition(out _tmp); } Columbus.Lim.Asg.Nodes.Type.Type param = (arg != null) ? arg.GetLimType() : argument.GetLimType(); MainDeclaration.Instance.UsesStack.Peek().Remove(param.Id); Types.TypeArgumentConstraintKind tack = Types.TypeArgumentConstraintKind.tackUpperBounded; if (roslynNode.TypeParameters[i].ConstraintTypes.Any()) { tack = Types.TypeArgumentConstraintKind.tackUnbounded; } bool found = false; ListIteratorAssocTypeArgumentConstraintKind <Columbus.Lim.Asg.Nodes.Type.Type> cIt = mgi.HasArgumentsListIteratorAssocBegin; while (cIt.getValue() != null) { Lim.Asg.Nodes.Type.Type value = cIt.getValue(); if (param.Id == value.Id) { found = true; break; } cIt = cIt.getNext(); } if (!found) { mgi.addHasArguments(param, tack); } i++; } } } MainDeclaration.Instance.MgiMap.Add(uName, mgi); return(mgi); }
/// <summary> /// Create ClassGenericInstance and connect to the Class, through the Instance edge. /// Furthermore, added GenericParameter to the ClassGenericInstance. /// </summary> /// <param name="symbol">Instanced class</param> /// <param name="refersTo">Instanced class definiton</param> /// <returns>ClassGenericInstnace from the LIM</returns> public static ClassGenericInstance GetCGI(this ISymbol symbol, INamedTypeSymbol refersTo) { string uName = symbol.ToString(); ClassGenericInstance cgi; if (MainDeclaration.Instance.CgiMap.TryGetValue(uName, out cgi)) { return(cgi); } cgi = MainDeclaration.Instance.LimFactory.createClassGenericInstanceNode(); cgi.IsRealInstance = true; cgi.Name = symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); cgi.MangledName = uName; cgi.DemangledName = uName; cgi.Language = Types.LanguageKind.lnkCsharp; INamedTypeSymbol roslynNode = symbol as INamedTypeSymbol; bool isInMeta = false; if (refersTo == null) { refersTo = (INamedTypeSymbol)symbol.OriginalDefinition; isInMeta = true; } if (refersTo != null) { Base owner = refersTo.ConvertToLimNode(); if (isInMeta) { Commons.Common.MetaDataNameFiller(symbol, (Member)owner); } if (Lim.Asg.Common.getIsClass(owner)) { Class ownerClass = owner as Class; Commons.Common.Safe_Edge(ownerClass, "Instance", cgi.Id); int i = 0; foreach (var argument in roslynNode.TypeArguments) { ITypeSymbol arg = null; if (!argument.IsInMetadata() && argument.TypeKind != TypeKind.TypeParameter) { SyntaxNode tmp; arg = (INamedTypeSymbol)argument.GetDefinition(out tmp); } Lim.Asg.Nodes.Type.Type param = (arg != null) ? arg.GetLimType() : argument.GetLimType(); MainDeclaration.Instance.UsesStack.Peek().Remove(param.Id); Types.TypeArgumentConstraintKind tack = Types.TypeArgumentConstraintKind.tackUpperBounded; if (roslynNode.TypeParameters[i].ConstraintTypes.Length > 0) { tack = Types.TypeArgumentConstraintKind.tackUnbounded; } bool found = false; ListIteratorAssocTypeArgumentConstraintKind <Lim.Asg.Nodes.Type.Type> cIt = cgi.HasArgumentsListIteratorAssocBegin; while (cIt.getValue() != null) { Lim.Asg.Nodes.Type.Type value = cIt.getValue(); if (param.Id == value.Id) { found = true; break; } cIt = cIt.getNext(); } if (!found) { cgi.addHasArguments(param, tack); } i++; } } } MainDeclaration.Instance.CgiMap.Add(uName, cgi); return(cgi); }