private void UpdateState(ConstantPropagationDomain state, IVariable v, Constant c) { var cpd = ConstantSetDomain.Bottom; cpd.Add(c); state.Set(v, cpd); }
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(); } }
public ConstantPropagationDomain Clone() { var clone = new ConstantPropagationDomain(); foreach (var v in varMapping.Keys) { clone.Set(v, varMapping[v].Clone()); } foreach (var f in fieldMapping.Keys) { clone.Set(f, fieldMapping[f].Clone()); } return(clone); }
public static ConstantPropagationDomain Top(IEnumerable <IVariable> vars, IEnumerable <IFieldAccess> fields) { var cpd = new ConstantPropagationDomain(); foreach (var v in vars) { cpd.Set(v, ConstantSetDomain.Top); } foreach (var f in fields) { cpd.Set(f, ConstantSetDomain.Top); } return(cpd); }
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); } }
/// <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); }
public ConstantPropagationTransferVisitor(ConstantPropagationDomain start, ConstantPropagationSetAnalysis dad) { parent = dad; SetCurrent(start); }
private void UpdateStateCopy(ConstantPropagationDomain state, IVariable dest, IFieldAccess src) { var cl = state.Constants(GetAccess(src)).Clone(); state.Set(dest, cl); }
private void UpdateStateNotConstant(ConstantPropagationDomain state) { state.SetNonConstant(); }
private void UpdateStateNotConstant(ConstantPropagationDomain state, IFieldAccess f) { state.SetNonConstant(GetAccess(f)); }
private void UpdateStateNotConstant(ConstantPropagationDomain state, IVariable v) { state.SetNonConstant(v); }
private void SavePostState(Instruction instruction, ConstantPropagationDomain cpd) { postState[instruction] = cpd; }
private void SetCurrent(ConstantPropagationDomain curr) { current = curr; }