コード例 #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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        public static void fillCollectedMethodData(Method method, MethodInfo methodInfo)
        {
            method.NestingLevel       = (ushort)methodInfo.NL;
            method.NestingLevelElseIf = (ushort)methodInfo.NLE;
            method.NumberOfBranches   = (ushort)methodInfo.NOB;
            method.NumberOfStatements = (ushort)methodInfo.NOS;

            foreach (KeyValuePair <uint, bool> call in methodInfo.Calls)
            {
                if (call.Value)
                {
                    MainDeclaration.Instance.LimFactory.setFiltered(call.Key);
                }
                Commons.Common.Safe_Edge(method, "Calls", call.Key);
            }
            foreach (KeyValuePair <uint, bool> throws in methodInfo.Throws)
            {
                if (throws.Value)
                {
                    MainDeclaration.Instance.LimFactory.setFiltered(throws.Key);
                }
                Commons.Common.Safe_Edge(method, "Throws", throws.Key);
            }
            foreach (KeyValuePair <uint, bool> canThrows in methodInfo.CanThrow)
            {
                if (canThrows.Value)
                {
                    MainDeclaration.Instance.LimFactory.setFiltered(canThrows.Key);
                }
                Commons.Common.Safe_Edge(method, "CanThrow", canThrows.Key);
            }
            foreach (KeyValuePair <uint, bool> instantiates in methodInfo.Instantiates)
            {
                if (instantiates.Value)
                {
                    MainDeclaration.Instance.LimFactory.setFiltered(instantiates.Key);
                }
                Commons.Common.Safe_Edge(method, "Instantiates", instantiates.Key);
            }
            foreach (KeyValuePair <uint, bool> accessAttribute in methodInfo.AccessAttribute)
            {
                if (accessAttribute.Value)
                {
                    MainDeclaration.Instance.LimFactory.setFiltered(accessAttribute.Key);
                }
                Commons.Common.Safe_Edge(method, "AccessesAttribute", accessAttribute.Key);
            }

            if (!method.ReturnsIsEmpty)
            {
                Lim.Asg.Nodes.Type.Type returnType = method.ReturnsListIteratorBegin.getValue();
                if (returnType != null)
                {
                    MainDeclaration.Instance.UsesStack.Peek().Remove(returnType.Id);
                }
            }

            if (!method.HasParameterIsEmpty)
            {
                ListIterator <Lim.Asg.Nodes.Logical.Parameter> paramIt = method.HasParameterListIteratorBegin;
                while (paramIt.getValue() != null)
                {
                    MainDeclaration.Instance.UsesStack.Peek().Remove(paramIt.getValue().getHasType());
                    paramIt = paramIt.getNext();
                }
            }

            IEnumerable <uint> _throws       = methodInfo.Throws.Select(t => t.Key);
            IEnumerable <uint> _canThrows    = methodInfo.CanThrow.Select(t => t.Key);
            IEnumerable <uint> _instantiates = methodInfo.Instantiates.Select(t => t.Key);

            Commons.Common.Remove(ref _throws);
            Commons.Common.Remove(ref _canThrows);
            Commons.Common.Remove(ref _instantiates);

            Commons.Common.AddUses(method);
        }
コード例 #4
0
        private void fillData(Parameter limNode, IParameterSymbol roslynNode, bool setHasMember)
        {
            switch (roslynNode.RefKind)
            {
            case RefKind.None:
                limNode.ParamKind = Types.ParameterKind.pmkIn;
                break;

            case RefKind.Ref:
                limNode.ParamKind = Types.ParameterKind.pmkInOut;
                break;

            case RefKind.Out:
                limNode.ParamKind = Types.ParameterKind.pmkOut;
                break;
            }
            if (roslynNode.Type != null)
            {
                SyntaxNode _m;
                Lim.Asg.Nodes.Type.Type type = null;
                if (!roslynNode.Type.IsInMetadata())
                {
                    var original = roslynNode.Type.GetDefinition(out _m);
                    if (original != null && original.Kind == roslynNode.Type.Kind)
                    {
                        var namedType = roslynNode.Type as INamedTypeSymbol;
                        if (namedType != null && namedType.IsGenericType)
                        {
                            type = roslynNode.Type.GetLimType(original);
                        }
                        else
                        {
                            type = original.GetLimType();
                        }
                    }
                }
                else
                {
                    type = roslynNode.Type.GetLimType();
                    if (roslynNode.Type.TypeKind != TypeKind.Array)
                    {
                        MainDeclaration.Instance.LimFactory.setFiltered(type.Id);
                    }
                }
                if (type != null)
                {
                    limNode.setHasType(type);
                }
            }
            else
            {
                limNode.setHasType(Commons.Common.UnknownType);
            }

            if (MainDeclaration.Instance.MethodStack.Count > 0)
            {
                //hasParameter
                Method parent = (Method)MainDeclaration.Instance.LimFactory.getRef(
                    MainDeclaration.Instance.MethodStack.Peek().Id
                    );
                Commons.Common.Safe_Edge(parent, "HasParameter", limNode.Id);
            }
        }
コード例 #5
0
        private void fillData(Attribute limNode, IFieldSymbol roslynNode, bool setHasMember)
        {
            fillMemberData(limNode, roslynNode, setHasMember);

            if (MainDeclaration.Instance.ClassStack.Count > 0)
            {
                Class parnetClass = (Class)MainDeclaration.Instance.LimFactory.getRef(MainDeclaration.Instance.ClassStack.Peek().Id);
                if (parnetClass.ClassKind == Types.ClassKind.clkInterface)
                {
                    limNode.Accessibility = Types.AccessibilityKind.ackPublic;
                }
            }

            var roslynType = roslynNode.Type;

            if (roslynType != null)
            {
                if (roslynType is ITypeParameterSymbol)
                {
                    GenericParameter limReturnType = (GenericParameter)roslynType.ConvertToLimNode();
                    if (limReturnType == null)
                    {
                        return;
                    }

                    fillData(limReturnType, roslynType as ITypeParameterSymbol, setHasMember);
                }
                else
                {
                    SyntaxNode syntaxNode           = null;
                    var        originalType         = roslynType.GetDefinition(out syntaxNode);
                    Lim.Asg.Nodes.Type.Type limType = null;
                    if (originalType != null && originalType.Kind == roslynType.Kind)
                    {
                        if (((INamedTypeSymbol)originalType).IsGenericType)
                        {
                            limType = roslynType.GetLimType(originalType);
                        }
                        else
                        {
                            limType = originalType.GetLimType();
                        }
                    }
                    else if (roslynType.IsInMetadata())
                    {
                        limType = roslynType.GetLimType();
                        if (roslynType.TypeKind != TypeKind.Array)
                        {
                            MainDeclaration.Instance.LimFactory.setFiltered(limType.Id);
                        }
                    }
                    if (limNode.HasTypeIsEmpty)
                    {
                        limNode.addHasType(limType);
                    }
                }
            }
            else
            {
                limNode.addHasType(Commons.Common.UnknownType);
            }
            limNode.MangledName  += ' ' + roslynType.ToString();
            limNode.DemangledName = limNode.MangledName;
        }
コード例 #6
0
        private void fillData(Method limNode, IMethodSymbol roslynNode, bool setHasMember)
        {
            MainDeclaration.Instance.MethodStack.Push(new MethodInfo(limNode.Id));

            fillScopeData(limNode, roslynNode, setHasMember);

            limNode.IsAbstract = roslynNode.IsAbstract;

            if (roslynNode.ContainingType != null && roslynNode.ContainingType.TypeKind == TypeKind.Interface)
            {
                limNode.Accessibility = Types.AccessibilityKind.ackPublic;
                limNode.IsAbstract    = true;
            }

            #region MethodKind
            Types.MethodKind limKind = Types.MethodKind.mekNormal;
            switch (roslynNode.MethodKind)
            {
            case MethodKind.Constructor:
                limKind = Types.MethodKind.mekConstructor;
                break;

            case MethodKind.Conversion:
                limKind = Types.MethodKind.mekOperator;
                break;

            case MethodKind.Destructor:
                limKind = Types.MethodKind.mekDestructor;
                break;

            case MethodKind.UserDefinedOperator:
                limKind = Types.MethodKind.mekOperator;
                break;

            default:
                break;
            }

            if (roslynNode.Name.Length >= 3)
            {
                string firstThree = roslynNode.Name.Substring(0, 3);
                if (firstThree == "get")
                {
                    limKind = Types.MethodKind.mekGet;
                }
                else if (firstThree == "set")
                {
                    limKind = Types.MethodKind.mekSet;
                }
                else if (firstThree == "add")
                {
                    limKind = Types.MethodKind.mekAdd;
                }
                if (roslynNode.Name.Length >= "remove".Length)
                {
                    firstThree = roslynNode.Name.Substring(0, "remove".Length);
                    if (firstThree == "remove")
                    {
                        limKind = Types.MethodKind.mekRemove;
                    }
                }
            }

            limNode.MethodKind = limKind;

            #endregion MethodKind

            limNode.IsVirtual = roslynNode.IsVirtual;

            #region returns
            var returnType = roslynNode.ReturnType;
            if (returnType != null)
            {
                SyntaxNode _m;
                if (!returnType.IsInMetadata())
                {
                    var originalDef = returnType.GetDefinition(out _m);
                    if (originalDef != null && originalDef.Kind == returnType.Kind)
                    {
                        Commons.Common.Safe_Edge(limNode, "Returns", originalDef.GetLimType().Id);
                    }
                }
                else
                {
                    Lim.Asg.Nodes.Type.Type node = returnType.GetLimType();
                    MainDeclaration.Instance.LimFactory.setFiltered(node.Id);
                    Commons.Common.Safe_Edge(limNode, "Returns", node.Id);
                }
                limNode.MangledName  += returnType.ToString();
                limNode.DemangledName = limNode.MangledName;
            }
            #endregion


            #region hasParamter
            foreach (var roslynParameter in roslynNode.Parameters)
            {
                Base limParameter = roslynParameter.ConvertToLimNode();
                if (limParameter == null)
                {
                    return;
                }

                FillData(limParameter, roslynParameter, setHasMember);
            }
            #endregion

            //canThrow
            //already handling in visitor
        }