Esempio n. 1
0
        /// <summary>
        /// Find all possible undefined members of a object within the variable-like expression.
        /// </summary>
        /// <param name="x">Variable-like expression possibly using members of a object.</param>
        /// <remarks>
        /// Every access to a field or method call can be seen as duck typing, because the type
        /// is not known without run-time information.
        /// </remarks>
        private void FindUndefinedMembersUse(VarLikeConstructUse x)
        {
            if (x.IsMemberOf != null)
            {
                // The type of x is known to be proper.
                occurrenceNodes.Enqueue(x);
            }
            else
            {
                return;
            }

            for (x = x.IsMemberOf; x.IsMemberOf != null; x = x.IsMemberOf)
            {
                // CompoundVarUse is supertype of DirectVarUse, IndirectVarUse and ItemUse
                // DirectVarUse can be $this, detect by DirectVarUse.VarName.IsThisVariableName.
                if ((x is CompoundVarUse) ||
                    (x is DirectFcnCall) ||
                    (x is IndirectFcnCall))
                {
                    // Variable-like construct is possible member of a object.
                    occurrenceNodes.Enqueue(x);
                }
            }

            if (x is IndirectFcnCall)
            {
                // __invoke method call if call is not member of a object. Otherwise call of __invoke
                // declared within object stored in a field is handled as method call.
                occurrenceNodes.Enqueue(x);
            }
        }
Esempio n. 2
0
        private static VarLikeConstructUse /*!*/ CreatePropertyVariables(VarLikeConstructUse chain, VarLikeConstructUse /*!*/ member)
        {
            // dereference function array access:
            var element = DereferenceFunctionArrayAccess(member);

            //
            if (chain != null)
            {
                IndirectFcnCall ifc = element as IndirectFcnCall;

                if (ifc != null && ifc.NameExpr as ItemUse != null)
                {
                    // we know that FcNAme is VLCU and not Expression, because chain is being parsed:
                    ((VarLikeConstructUse)ifc.NameExpr).IsMemberOf = chain;
                }
                else
                {
                    element.IsMemberOf = chain;
                }
            }
            else
            {
                element.IsMemberOf = null;
            }

            return(member);
        }
Esempio n. 3
0
        private void copyInfoFromInToOutSnapshot(VarLikeConstructUse variable, AssumePoint p, EvaluationLog log)
        {
            var variableInfo = log.GetSnapshotEntry(variable);

            if (variableInfo != null)
            {
                var vals = variableInfo.ReadMemory(p.InSnapshot).PossibleValues;
                variableInfo.WriteMemory(Output, new MemoryEntry(vals));
            }
        }
Esempio n. 4
0
        private static VarLikeConstructUse /*!*/ DereferenceFunctionArrayAccess(VarLikeConstructUse /*!*/ varUse)
        {
            ItemUse itemUse;

            while ((itemUse = varUse as ItemUse) != null && itemUse.IsFunctionArrayDereferencing)
            {
                varUse = itemUse.Array;
            }

            return(varUse);
        }
Esempio n. 5
0
        /// <summary>
        /// Identify a function call in l-value expression.
        /// </summary>
        /// <param name="x">Variable-like, l-value expression.</param>
        private void FindFunctionCall(VarLikeConstructUse x)
        {
            // Function is not member of anything
            while (x.IsMemberOf != null)
            {
                x = x.IsMemberOf;
            }

            var call = x as DirectFcnCall;

            if (call != null)
            {
                AddCoupling(call);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Get member of value point for given element if possible. Forced member of points are prioritized
        /// </summary>
        /// <param name="el">Element which member of is needed</param>
        /// <returns>Value point of MemberOf if available</returns>
        private ValuePoint GetMemberOf(VarLikeConstructUse el)
        {
            var forcedMemberOf = _forcedThisObjects.Peek();

            if (forcedMemberOf != null)
            {
                return(forcedMemberOf);
            }

            var memberEl = el.IsMemberOf;

            if (memberEl == null)
            {
                return(null);
            }

            return(CreateRValue(memberEl));
        }
Esempio n. 7
0
        private void checkDefiniteVariableInAssumption(VarLikeConstructUse variable, AssumePoint p)
        {
            var variableInfo = p.Log.ReadSnapshotEntry(variable);

            if (variableInfo != null)
            {
                Input.SetMode(SnapshotMode.MemoryLevel);
                MemoryEntry memoryEntry = variableInfo.ReadMemory(Input);
                Input.SetMode(SnapshotMode.InfoLevel);
                if (memoryEntry != null && memoryEntry.PossibleValues != null)
                {
                    if (memoryEntry.PossibleValues.Count() == 1 && !(memoryEntry.PossibleValues.First() is AnyValue))
                    {
                        //AnalysisWarningHandler.SetWarning(Output, new AnalysisWarning(p.OwningScriptFullName, String.Format("Variable has just single possible value ({0}) and it is used in the assumption.", memoryEntry.PossibleValues.First().ToString()), variable, p, AnalysisWarningCause.OTHER));
                    }
                }
                else
                {
                    //AnalysisWarningHandler.SetWarning(Output, new AnalysisWarning(p.OwningScriptFullName, "Variable is not defined and it is used in the assumption.", variable, p, AnalysisWarningCause.OTHER));
                }
            }
        }
Esempio n. 8
0
 public sealed override void VisitVarLikeConstructUse(VarLikeConstructUse x)
 {
     throw new InvalidOperationException();  // visit specific AST element
 }
Esempio n. 9
0
 virtual public void VisitVarLikeConstructUse(VarLikeConstructUse x)
 {
     VisitElement(x.IsMemberOf);
 }
Esempio n. 10
0
 private void AssumeFalseElementUse(VarLikeConstructUse directVarUse, MemoryContext memoryContext, SnapshotBase flowOutputSet)
 {
     memoryContext.AssignFalseEvaluable(directVarUse);
 }
Esempio n. 11
0
 override public void VisitVarLikeConstructUse(VarLikeConstructUse x)
 {
     SerializeOptionalProperty("IsMemberOf", x.IsMemberOf);
 }
Esempio n. 12
0
        private static VarLikeConstructUse /*!*/ CreateVariableUse(Position pos, VarLikeConstructUse /*!*/ variable, VarLikeConstructUse /*!*/ property,
                                                                   FcnParam parameters, VarLikeConstructUse chain)
        {
            if (parameters != null)
            {
                if (property is ItemUse)
                {
                    property.IsMemberOf = variable;
                    property            = new IndirectFcnCall(pos, property, (List <ActualParam>)parameters.Item2, (List <TypeRef>)parameters.Item1);
                }
                else
                {
                    DirectVarUse direct_use;
                    if ((direct_use = property as DirectVarUse) != null)
                    {
                        QualifiedName method_name = new QualifiedName(new Name(direct_use.VarName.Value), Name.EmptyNames);
                        property = new DirectFcnCall(pos, method_name, null, property.Position, (List <ActualParam>)parameters.Item2, (List <TypeRef>)parameters.Item1);
                    }
                    else
                    {
                        IndirectVarUse indirect_use = (IndirectVarUse)property;
                        property = new IndirectFcnCall(pos, indirect_use.VarNameEx, (List <ActualParam>)parameters.Item2, (List <TypeRef>)parameters.Item1);
                    }

                    property.IsMemberOf = variable;
                }

                // wrap into ItemUse
                property = CreateFcnArrayDereference(pos, property, parameters.Item3);
            }
            else
            {
                property.IsMemberOf = variable;
            }

            if (chain != null)
            {
                // finds the first variable use in the chain and connects it to the property

                VarLikeConstructUse first_in_chain = chain;
                for (;;)
                {
                    first_in_chain = DereferenceFunctionArrayAccess(first_in_chain);

                    if (first_in_chain.IsMemberOf != null)
                    {
                        first_in_chain = first_in_chain.IsMemberOf;
                    }
                    else
                    {
                        break;
                    }
                }

                first_in_chain.IsMemberOf = property;
                return(chain);
            }
            else
            {
                return(property);
            }
        }
Esempio n. 13
0
        private static VarLikeConstructUse /*!*/ CreateFcnArrayDereference(Position pos, VarLikeConstructUse /*!*/ varUse, List <Expression> arrayKeysExpression)
        {
            if (arrayKeysExpression != null && arrayKeysExpression.Count > 0)
            {
                // wrap fcnCall into ItemUse
                foreach (var keyExpr in arrayKeysExpression)
                {
                    varUse = new ItemUse(pos, varUse, keyExpr, true);
                }
            }

            return(varUse);
        }