public bool LookupState(IMethodResult <Variable> mr, APC pc, out SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> astate) { astate = null; StringValueAnalysis an = mr as StringValueAnalysis; if (an == null) { return(false); } return(an.PreStateLookup(pc, out astate)); }
public bool AssignInParallel(IMethodResult <Variable> mr, ref SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> astate, Dictionary <BoxedVariable <Variable>, FList <BoxedVariable <Variable> > > mapping, Converter <BoxedVariable <Variable>, BoxedExpression> convert) { StringValueAnalysis an = mr as StringValueAnalysis; if (an == null) { return(false); } astate.AssignInParallel(mapping, convert); return(true); }
public List <BoxedExpression> ExtractAssertions( IMethodResult <Variable> mr, SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> astate, IExpressionContext <Local, Parameter, Method, Field, Type, Expression, Variable> context, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> metaDataDecoder) { StringValueAnalysis an = mr as StringValueAnalysis; if (an == null) { return(null); } BoxedExpressionReader <Local, Parameter, Method, Field, Property, Event, Type, Variable, Expression, Attribute, Assembly> br = new BoxedExpressionReader <Local, Parameter, Method, Field, Property, Event, Type, Variable, Expression, Attribute, Assembly>(context, metaDataDecoder); return(an.ToListOfBoxedExpressions(astate, br)); }
/// <summary> /// It runs the analysis. /// It is there because so we can use the typebinding, and make the code less verbose /// </summary> internal static IMethodResult <Variable> HelperForStringAnalysis(string methodName, IMethodDriver <APC, Local, Parameter, Method, Field, Property, Type, Attribute, Assembly, ExternalExpression, Variable, ILogOptions> driver, IValueAnalysisOptions options) { StringValueAnalysis analysis; analysis = new StringValueAnalysis(methodName, driver, options); // *** The next lines must be strictly sequential *** Action <SimpleStringAbstractDomain <BoxedExpression> > closure = driver.CreateForward <SimpleStringAbstractDomain <BoxedExpression> >(analysis); // At this point, CreateForward has called the Visitor, so the context has been created, so that now we can call initValue SimpleStringAbstractDomain <BoxedExpression> initValue = analysis.InitialValue; closure(initValue); // Do the analysis return(analysis); }
/// <summary> /// Here we catch the calls to methods of String, so that we can apply operations on string, as concatenations. etc. /// </summary> public override SimpleStringAbstractDomain <BoxedExpression> Call <TypeList, ArgList>(APC pc, Method method, bool tail, bool virt, TypeList extraVarargs, Variable dest, ArgList args, SimpleStringAbstractDomain <BoxedExpression> data) // where ArgList : IIndexable<int> { string methodName = this.DecoderForMetaData.FullName(method); ALog.BeginTransferFunction(StringClosure.For("call"), StringClosure.For(methodName), StringClosure.For(pc), StringClosure.For(data)); SimpleStringAbstractDomain <BoxedExpression> result; SimpleStringAbstractDomain <BoxedExpression> baseResult = base.Call <TypeList, ArgList>(pc, method, tail, virt, extraVarargs, dest, args, data); if (IsACallToString(methodName)) { result = HandleCallToString(pc, methodName, dest, args, baseResult); } else { result = baseResult; } ALog.EndTransferFunction(StringClosure.For(result)); return(result); }
private SimpleStringAbstractDomain <BoxedExpression> /*!*/ HandleCallToString <ArgList>(APC pc, string /*!*/ fullMethodName, Variable /*!*/ dest, ArgList /*!*/ args, SimpleStringAbstractDomain <BoxedExpression> /*!*/ state) where ArgList : IIndexable <Variable> { string method = fullMethodName.Substring(System_String.Length); method = method.Contains("(")? method.Substring(0, method.IndexOf("(")) : method;// removes the arguments BoxedExpression one, two, three; BoxedExpression x = BoxedExpression.For(this.Context.Refine(pc, dest), this.decoderForExpressions.Outdecoder); switch (method) { case "CompareTo": ExtractActualParameters(pc, args[0], args[1], out one, out two); /* does nothing */ state.CompareTo(one, two); // does nothing as it returns a FlatAbstractDomain<bool> break; case "Contains": // does nothing as it returns a FlatAbstractDomain<bool> ExtractActualParameters(pc, args[0], args[1], out one, out two); /* does nothing */ state.Contains(one, two); break; case "Concat": if (args.Count == 2) { ExtractActualParameters(pc, args[0], args[1], out one, out two); state.Concat(x, one, two); } else { // It is a call to String.Concat(String[]) which we ignore } break; case "Insert": ExtractActualParameters(pc, args[0], args[1], args[2], out one, out two, out three); state.Insert(x, one, two, three); // !!!!!! Here I am switching the params, I think is a bug, ask Manuel break; case "StartsWith": ExtractActualParameters(pc, args[0], args[1], out one, out two); /* does nothing */ state.StartsWith(one, two); // does nothing, as it returns a FlatAbstractDomain<bool> break; case "Trim": ExtractActualParameters(pc, args[0], out one); state.Trim(x, one); break; default: break; } return(state); }
public SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> Join(IMethodResult <Variable> mr, SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> astate1, SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> astate2) { StringValueAnalysis an = mr as StringValueAnalysis; if (an == null) { return(null); } bool bWeaker; return(an.Join(new Pair <APC, APC>(), astate1, astate2, out bWeaker, false)); }
/// <summary> /// Here we catch the calls to methods of String, so that we can apply operations on string, as concatenations. etc. /// </summary> public override SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> Call <TypeList, ArgList>(APC pc, Method method, bool tail, bool virt, TypeList extraVarargs, Variable dest, ArgList args, SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> data) // where ArgList : IIndexable<int> { string methodName = this.DecoderForMetaData.FullName(method); SimpleStringAbstractDomain <BoxedVariable <Variable>, BoxedExpression> result; var baseResult = base.Call <TypeList, ArgList>(pc, method, tail, virt, extraVarargs, dest, args, data); if (IsACallToString(methodName)) { result = HandleCallToString(pc, methodName, dest, args, baseResult); } else { result = baseResult; } return(result); }