Example #1
0
        /// <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);
        }