/// <summary>
        /// Initializes a new instance of the <see cref="ProcedureDescription"/> class.
        /// </summary>
        /// <param name="methodDefinition">The <see cref="MethodDefinition"/> from which to create
        /// the description.</param>
        /// <param name="cfg">The CFG with which this procedure description is associated.</param>
        public ProcedureDescription(MethodDefinition methodDefinition, Cfg cfg)
        {
            PdId = NextId;

            var parameters = methodDefinition.Parameters.Select(
                p => new VariableDescription(p.Name, Typ.FromTypeReference(p.ParameterType)));

            if (!methodDefinition.IsStatic)
            {
                parameters = parameters.Prepend(
                    new VariableDescription(Identifier.ThisIdentifier,
                                            Typ.FromTypeReference(
                                                methodDefinition.DeclaringType)));
            }

            var location = Location.FromSequencePoint(
                methodDefinition.DebugInformation.SequencePoints.FirstOrDefault());

            PdAttributes = new ProcedureAttributes()
            {
                Access = methodDefinition.IsPublic ?
                         ProcedureAttributes.ProcedureAccessKind.Public :
                         methodDefinition.IsPrivate ?
                         ProcedureAttributes.ProcedureAccessKind.Private :
                         ProcedureAttributes.ProcedureAccessKind.Default,
                Formals  = parameters.ToList(),
                RetType  = Typ.FromTypeReference(methodDefinition.ReturnType),
                Loc      = location,
                ProcName = new ProcedureName(methodDefinition)
            };

            Nodes     = new List <CfgNode>();
            StartNode = new StartNode(location, this);
            ExitNode  = new ExitNode(Location.FromSequencePoint(methodDefinition
                                                                .DebugInformation
                                                                .SequencePoints
                                                                .FirstOrDefault()),
                                     this);
            ExceptionSinkNode = new StatementNode(location,
                                                  StatementNode.StatementNodeKind.ExceptionsSink,
                                                  proc: this);

            cfg.RegisterNode(StartNode);
            cfg.RegisterNode(ExitNode);
            cfg.RegisterNode(ExceptionSinkNode);
        }
Пример #2
0
 /// <summary>
 /// Adds the node to the CFG's aggregated <see cref="Nodes"/> list.
 /// </summary>
 /// <param name="node">The node to register.</param>
 public void RegisterNode(CfgNode node) => Nodes.Add(node);