Ejemplo n.º 1
0
        protected override bool Step(
            GraphStructuredProgram <TNode> targetProgram,
            ResolvedMethod <TNode> targetMethod,
            TNode source,
            Statement statement,
            TNode target,
            Func <TNode> nodeCreator)
        {
            if (statement is AssignmentStatement assignment)
            {
                var sourceEntity = ReferenceResolver.Resolve(targetProgram, targetMethod, assignment.Source);
                var targetEntity = ReferenceResolver.Resolve(targetProgram, targetMethod, assignment.Target);

                var targetSecondaryEntity = targetEntity as SecondaryEntity;
                Trace.Assert(targetSecondaryEntity != null);

                var referencedByThis =
                    assignment.Target is ClassFieldReference classFieldReference &&
                    classFieldReference.Owner is ClassReference classReference &&
                    classReference.ThisClassReference;

                var newStatement = new ResolvedAssignmentStatement(
                    assignment.Location, sourceEntity, targetSecondaryEntity, referencedByThis);

                targetProgram.AddEdge(new OperationEdge <TNode>(source, newStatement, target));

                return(false);
            }

            return(true);
        }
        private Dictionary <SecondaryEntity, ParameterIndex> AddIntermediateEdgesIfNeeded(
            GraphStructuredProgram <TNode> targetProgram,
            Dictionary <Entity, ParameterIndex> passedParameters,
            TNode currentSource,
            Func <TNode> nodeCreator,
            Func <SecondaryEntity> variableCreator,
            out TNode newSource)
        {
            var processedParameters = passedParameters.ToDictionary(
                pair =>
            {
                if (!(pair.Key is ResolvedLocalVariable))
                {
                    var newTarget   = nodeCreator();
                    var newVariable = variableCreator();
                    var statement   = new ResolvedAssignmentStatement(null, pair.Key, newVariable);
                    var edge        = new OperationEdge <TNode>(currentSource, statement, newTarget);

                    targetProgram.AddEdge(edge);
                    currentSource = newTarget;

                    return(newVariable);
                }

                return((SecondaryEntity)pair.Key);
            },
                pair => pair.Value);

            newSource = currentSource;
            return(processedParameters);
        }