Exemple #1
0
 /// <summary>
 /// Constructor, only factory can instantiates nodes.
 /// </summary>
 /// <param name="nodeId">[in] The id of the node.</param>
 /// <param name="factory">[in] Poiter to the Factory the node belongs to.</param>
 public Method(uint nodeId, Factory factory) : base(nodeId, factory)
 {
     m_distinctOperands           = 0;
     m_distinctOperators          = 0;
     m_isAbstract                 = false;
     m_isVirtual                  = false;
     m_methodKind                 = Types.MethodKind.mekAdd;
     m_nestingLevel               = 0;
     m_nestingLevelElseIf         = 0;
     m_numberOfBranches           = 0;
     m_numberOfStatements         = 0;
     m_totalOperands              = 0;
     m_totalOperators             = 0;
     accessesAttributeContainer   = new LinkedList <uint>();
     callsContainer               = new LinkedList <uint>();
     canThrowContainer            = new LinkedList <uint>();
     hasControlFlowBlockContainer = new LinkedList <uint>();
     hasParameterContainer        = new LinkedList <uint>();
     instantiatesContainer        = new LinkedList <uint>();
     returnsContainer             = new LinkedList <uint>();
     throwsContainer              = new LinkedList <uint>();
 }
Exemple #2
0
        /// <summary>
        /// Loads the node.
        /// </summary>
        /// <param name="io">[in] The node is read from io.</param>
        /// <exception cref="Columbus.ColumbusIOException">Throws ColumbusIOException if there is something wrong with the file.</exception>
        public override void load(IO binIo)
        {
            base.load(binIo);

            byte boolValues = binIo.readUByte1();

            m_isVirtual          = Convert.ToBoolean(boolValues & 1);
            boolValues         >>= 1;
            m_isAbstract         = Convert.ToBoolean(boolValues & 1);
            boolValues         >>= 1;
            m_distinctOperands   = binIo.readUInt4();
            m_distinctOperators  = binIo.readUInt4();
            m_methodKind         = (Types.MethodKind)binIo.readUByte1();
            m_nestingLevel       = binIo.readUShort2();
            m_nestingLevelElseIf = binIo.readUShort2();
            m_numberOfBranches   = binIo.readUInt4();
            m_numberOfStatements = binIo.readUInt4();
            m_totalOperands      = binIo.readUInt4();
            m_totalOperators     = binIo.readUInt4();

            uint _id;

            _id = binIo.readUInt4();
            while (_id != 0)
            {
                accessesAttributeContainer.AddLast(_id);
                _id = binIo.readUInt4();
            }

            _id = binIo.readUInt4();
            while (_id != 0)
            {
                callsContainer.AddLast(_id);
                _id = binIo.readUInt4();
            }

            _id = binIo.readUInt4();
            while (_id != 0)
            {
                canThrowContainer.AddLast(_id);
                _id = binIo.readUInt4();
            }

            _id = binIo.readUInt4();
            while (_id != 0)
            {
                hasControlFlowBlockContainer.AddLast(_id);
                setParentEdge(_id, (uint)Types.EdgeKind.edkMethod_HasControlFlowBlock);
                _id = binIo.readUInt4();
            }

            _id = binIo.readUInt4();
            while (_id != 0)
            {
                hasParameterContainer.AddLast(_id);
                setParentEdge(_id, (uint)Types.EdgeKind.edkMethod_HasParameter);
                _id = binIo.readUInt4();
            }

            _id = binIo.readUInt4();
            while (_id != 0)
            {
                instantiatesContainer.AddLast(_id);
                _id = binIo.readUInt4();
            }

            _id = binIo.readUInt4();
            while (_id != 0)
            {
                returnsContainer.AddLast(_id);
                _id = binIo.readUInt4();
            }

            _id = binIo.readUInt4();
            while (_id != 0)
            {
                throwsContainer.AddLast(_id);
                _id = binIo.readUInt4();
            }
        }
Exemple #3
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
        }