コード例 #1
0
            private void UpdateStateCopy(ConstantPropagationDomain state, IFieldAccess dest, IVariable src)
            {
                /*
                 * When we set a field of an object O to a constant, we also need to set the same field
                 * to objects that are must aliased to O. We know that all field accesses corresponding
                 * to closure fields must alias each other since they are compiler generated. That is,
                 * a user cannot instantiate such class nor does the compiler instantiate it inside the class itself.
                 */

                var faccess           = GetAccessRef(dest);
                IFieldDefinition fdef = faccess.Item2.Resolve(parent.Host);

                // We know that closure field accesses must alias each other.
                if (IsClosureField(fdef))
                {
                    foreach (var pair in parent.Fields)
                    {
                        var fresolved = pair.Item2.Resolve(parent.Host);

                        if (fresolved == fdef || fresolved.Equals(fdef))
                        {
                            state.Set(GetAccess(pair.Item1), state.Constants(src).Clone());
                        }
                    }
                }
                else
                {
                    // TODO: refine this by type of the field.
                    state.SetFieldNonConstant();
                }
            }
コード例 #2
0
            /// <summary>
            /// Method that conservatively checks if the current method is string concatenation
            /// and parameters are known string constants.
            /// </summary>
            /// <param name="instruction"></param>
            /// <param name="state"></param>
            /// <returns></returns>
            private bool IsStringConcatenationPossible(MethodCallInstruction instruction, ConstantPropagationDomain state)
            {
                if (!instruction.HasResult)
                {
                    return(false);
                }

                if (instruction.Arguments.Count != 2)
                {
                    return(false);
                }

                if (instruction.Method.ContainingType.FullName() != "System.String")
                {
                    return(false);
                }

                if (instruction.Method.Name.Value != "Concat")
                {
                    return(false);
                }

                var arg0 = instruction.Arguments.ElementAt(0);
                var arg1 = instruction.Arguments.ElementAt(1);

                if (arg0.Type.FullName() != "System.String" || arg1.Type.FullName() != "System.String")
                {
                    return(false);
                }

                var cons1 = state.Constants(arg0);
                var cons2 = state.Constants(arg1);

                if (cons1.IsBottom || cons2.IsBottom || cons1.IsTop || cons2.IsTop)
                {
                    return(false);
                }

                return(true);
            }
コード例 #3
0
        public void Join(ConstantPropagationDomain other)
        {
            if (VarCount != other.VarCount)
            {
                throw new IncompatibleConstantPropagationDomains("Not the same variable set!");
            }

            for (int i = 0; i < varMapping.Keys.Count; i++)
            {
                var v = varMapping.Keys.ElementAt(i);
                if (!other.Contains(v))
                {
                    throw new IncompatibleConstantPropagationDomains("Not the same variable set! " + v.ToString());
                }
                var ncsd = Constants(v).Clone();
                ncsd.Join(other.Constants(v));
                Set(v, ncsd);
            }

            if (FieldCount != other.FieldCount)
            {
                throw new IncompatibleConstantPropagationDomains("Not the same field set!");
            }

            for (int i = 0; i < fieldMapping.Keys.Count; i++)
            {
                var f = fieldMapping.Keys.ElementAt(i);
                if (!other.Contains(f))
                {
                    throw new IncompatibleConstantPropagationDomains("Not the same field set! " + f.ToString());
                }
                var ncsd = Constants(f).Clone();
                ncsd.Join(other.Constants(f));
                Set(f, ncsd);
            }
        }
コード例 #4
0
            private void UpdateStateCopy(ConstantPropagationDomain state, IVariable dest, IFieldAccess src)
            {
                var cl = state.Constants(GetAccess(src)).Clone();

                state.Set(dest, cl);
            }