Esempio n. 1
0
        private static void _ListFunc(LuaProto p, ListFuncDelegate outputEvent)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            string s = (p.Source != null) ? p.Source : "=?";

            if (s[0] == '@' || s[0] == '=')
            {
                s = s.Substring(1);
            }
            else if ((int)s[0] == 27)
            {
                s = "(bstring)";
            }
            else
            {
                s = "(string)";
            }
            sb.Append(string.Format("{0} <{1}:{2},{3}> ({4} instructions)",
                                    p.LineDefined == 0 ? "main" : "function",
                                    s,
                                    p.LineDefined,
                                    p.LastLineDefined,
                                    p.Code.Count)).Append("\n");
            sb.Append(string.Format(
                          "{0}{1} params, {2} slots, {3} upvalue, {4} locals, {5} constants, {6} functions",
                          p.NumParams,
                          p.IsVarArg ? "+" : "",
                          p.MaxStackSize,
                          p.Upvalues.Count,
                          p.LocVars.Count,
                          p.K.Count,
                          p.P.Count)).Append("\n");
            for (int i = 0; i < p.Code.Count; ++i)
            {
                var ins  = p.Code[i];
                var line = p.LineInfo[i];
                sb.Append((i + 1).ToString()).Append("\t")
                .Append("[" + line + "]").Append("\t")
                .Append(ins.ToString()).Append("\t")
                .Append("; ").Append(line).Append("\n");
            }
            if (outputEvent != null)
            {
                outputEvent(sb.ToString());
            }

            //foreach( var child in p.P )
            for (int i = 0; i < p.P.Count; i++)
            {
                //_ListFunc( child, outputEvent );
                _ListFunc(p.P[i], outputEvent);
            }
        }
Esempio n. 2
0
        private static void _ListFunc( LuaProto p, ListFuncDelegate outputEvent )
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            string s = (p.Source != null) ? p.Source : "=?";
            if( s[0] == '@' || s[0] == '=' )
                s = s.Substring(1);
            else if( (int)s[0] == 27 )
                s = "(bstring)";
            else
                s = "(string)";
            sb.Append( string.Format("{0} <{1}:{2},{3}> ({4} instructions)",
                p.LineDefined==0 ? "main" : "function",
                s,
                p.LineDefined,
                p.LastLineDefined,
                p.Code.Count) ).Append("\n");
            sb.Append( string.Format(
                "{0}{1} params, {2} slots, {3} upvalue, {4} locals, {5} constants, {6} functions",
                p.NumParams,
                p.IsVarArg ? "+" : "",
                p.MaxStackSize,
                p.Upvalues.Count,
                p.LocVars.Count,
                p.K.Count,
                p.P.Count ) ).Append("\n");
            for( int i=0; i<p.Code.Count; ++i )
            {
                var ins = p.Code[i];
                var line = p.LineInfo[i];
                sb.Append( (i+1).ToString() ).Append( "\t" )
                  .Append( "["+line+"]" ).Append( "\t" )
                  .Append( ins.ToString() ).Append( "\t" )
                  .Append( "; " ).Append(line).Append("\n");
            }
            if( outputEvent != null )
                outputEvent( sb.ToString() );

            foreach( var child in p.P )
            {
                _ListFunc( child, outputEvent );
            }
        }
Esempio n. 3
0
            private void Log_ProblemHandler(Microsoft.ExtendedReflection.Logging.ProblemEventArgs e)
            {
                RecordFlipCount(e);

                if (e.Result == TryGetModelResult.Success)
                {
                    Host.GetService <ProblemTrackDatabase>().SimpleLog.AppendLine("flipped result: " + e.Result);
                    Host.GetService <ProblemTrackDatabase>().CurrentSuccessfulFlippedPathCondition = e;
                    return;
                }
                if (e.Result != TryGetModelResult.Success)
                {
                    Host.GetService <ProblemTrackDatabase>().SimpleLog.AppendLine("flipped result: " + e.Result);
//                    return;
                }
                try
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    CodeLocation location        = e.FlippedLocation;
                    var          database        = Host.GetService <ProblemTrackDatabase>();
                    database.PexProblemEventArgsList.Add(e);

//                e.Result == TryGetModelResult.
                    this.Host.Log.Dump("My Category", "flipped location: " + location, null);
                    SequencePoint sp;
                    Host.Services.SymbolManager.TryGetSequencePoint(location.Method, location.Offset, out sp);
                    sb.AppendLine("flipped location: " + sp.Document + " line: " + sp.Line + " offset: " +
                                  location.Offset);
                    sb.AppendLine("e.ParentOfFlipped.InCodeBranch: " + e.ParentOfFlipped.InCodeBranch);
                    e.ParentOfFlipped.OutCodeBranches.ToList().ForEach(x => sb.AppendLine("out: " + x));
                    var flippedCondition = e.Suffix;
                    var parentOfFlipped  = e.ParentOfFlipped.CodeLocation;
                    Host.Services.SymbolManager.TryGetSequencePoint(parentOfFlipped.Method, parentOfFlipped.Offset,
                                                                    out sp);
                    sb.AppendLine("parent flipped location: " + sp.Document + " line: " + sp.Line + " offset: " +
                                  parentOfFlipped.Offset);

                    var stringWriter = new StringWriter();
                    var bodyWriter   = this.Host.Services.LanguageManager.DefaultLanguage.CreateBodyWriter(stringWriter,
                                                                                                           VisibilityContext
                                                                                                           .
                                                                                                           Private);
                    var emitter = new TermEmitter(e.TermManager, new NameCreator());
                    if (emitter.TryEvaluate(Indexable.One(flippedCondition), 1000, bodyWriter))
                    {
                        bodyWriter.Return(SystemTypes.Bool);
                    }
                    string flippedTerm = stringWriter.ToString();
                    stringWriter.WriteLine();
                    stringWriter.WriteLine("Feasible prefixes:");
                    if (e.FeasiblePrefix != null && e.FeasiblePrefix.Length > 0)
                    {
                        var bodyWriter2 =
                            this.Host.Services.LanguageManager.DefaultLanguage.CreateBodyWriter(stringWriter,
                                                                                                VisibilityContext
                                                                                                .
                                                                                                Private);
                        foreach (Term prefix in e.FeasiblePrefix)
                        {
                            if (emitter.TryEvaluate(Indexable.One(prefix), 1000, bodyWriter2))
                            {
                                bodyWriter2.Return(SystemTypes.Bool);
                            }
                        }
                    }
                    else
                    {
                        stringWriter.WriteLine("No feasible prefixes.");
                    }

                    string feasiblePrefix =
                        stringWriter.ToString().Substring(stringWriter.ToString().IndexOf("Feasible prefixes:"));
                    this.Host.Log.Dump("My Category", "condition", stringWriter.ToString());
                    sb.AppendLine(stringWriter.ToString());

                    int returnIndex = flippedTerm.IndexOf("return");
                    sb.AppendLine("flipped term: " + flippedTerm.Substring(returnIndex));
                    string targetObjectType = null;
                    bool   infeasible       = false;
                    if (flippedTerm.Contains("!=") && flippedTerm.Contains("null"))
                    {
                        targetObjectType = flippedTerm.Substring(flippedTerm.IndexOf("(") + 1,
                                                                 flippedTerm.IndexOf(")") - flippedTerm.IndexOf("(") -
                                                                 1);
                        sb.AppendLine("targetObjectType: " + targetObjectType);

                        int index  = flippedTerm.IndexOf("!=") - 2;
                        int length = 0;
                        while (flippedTerm[index] != ' ')
                        {
                            index--;
                            length++;
                        }
                        string variable = flippedTerm.Substring(index + 1, length);
                        sb.AppendLine("variable for targetObjectType: " + variable);

                        string infeasibleCheck = variable + ".GetType() != typeof(" + targetObjectType + ")";
                        string conflictCheck   = variable + " == (" + targetObjectType + ")null";
                        sb.AppendLine("test for infeasible: " + infeasibleCheck);
                        if (feasiblePrefix.Contains(infeasibleCheck))
                        {
                            sb.AppendLine("found infeasible constraint: " + infeasibleCheck);
                            infeasible = true;
                        }
                        else if (feasiblePrefix.Contains(conflictCheck))
                        {
                            sb.AppendLine("found conflict constraint: " + conflictCheck);
                            infeasible = true;
                        }
                        else if (targetObjectType.Contains("(") || targetObjectType.Contains(")") || targetObjectType.Contains("="))
                        {
                            sb.AppendLine("found wrong object type: " + targetObjectType);
                            infeasible = true;
                        }
                        else
                        {
                            var branchInfo = new BranchInfo(sp.Document, sp.Line, sp.Column, sp.EndColumn,
                                                            location.Method.FullName, location.Offset);
                            if (database.TargetObjectTypes.ContainsKey(targetObjectType))
                            {
                                database.TargetObjectTypes[targetObjectType].Add(branchInfo);
                            }
                            else
                            {
                                database.TargetObjectTypes.Add(targetObjectType,
                                                               new HashSet <BranchInfo> {
                                    branchInfo
                                });
                            }
                        }
                    }

                    IEnumerable <Field>  fields = GetInvolvedFields(e.TermManager, flippedCondition);
                    IEnumerable <TypeEx> types  = GetInvolvedObjectTypes(e.TermManager, flippedCondition);
                    var    simpleLog            = database.SimpleLog;
                    var    errorLog             = database.ErrorLog;
                    Field  target;
                    TypeEx declaringType;
                    simpleLog.AppendLine("============Log Problem================");
                    simpleLog.AppendLine("result: " + e.Result);
                    simpleLog.AppendLine(sb.ToString());

                    TypeEx targetType;
                    if (
                        !ObjectCreationProblemAnalyzer.GetTargetExplorableField(fields.Reverse(), out target,
                                                                                out declaringType,
                                                                                Host, out targetType))
                    {
                        simpleLog.AppendLine("can not analyze");
                    }


                    simpleLog.AppendLine("failed term: \n" + stringWriter.ToString());
                    fields.ToList().ForEach(x => simpleLog.AppendLine("involved field: " + x));
                    foreach (var f in fields)
                    {
                        simpleLog.AppendLine("involved field: ");
                        simpleLog.AppendLine("f.FullName:" + f.FullName);
                        simpleLog.AppendLine("f.Definition.FullName" + f.Definition.FullName);
                        simpleLog.AppendLine("f.InstanceFieldMapType:" + f.InstanceFieldMapType.FullName);
                        TypeEx type;
                        //                        type.
                        f.TryGetDeclaringType(out type);
                        simpleLog.AppendLine("f.TryGetDeclaringType: " + type.FullName);
                    }

                    types.ToList().ForEach(x => simpleLog.AppendLine("found object type: " + x));
                    types.ToList().ForEach(x => Host.GetService <ProblemTrackDatabase>().FoundTypes.Add(x.FullName));
                    fields.ToList().ForEach(x => Host.GetService <ProblemTrackDatabase>().FoundTypes.Add(x.Type.FullName));
                    fields.ToList().ForEach(x =>
                    {
                        TypeEx decType;
                        if (x.TryGetDeclaringType(out decType))
                        {
                            Host.GetService <ProblemTrackDatabase>().FoundTypes.Add(
                                decType.FullName);
                        }
                        ;
                    });
                    simpleLog.AppendLine("target field: " + target);

                    if (fields != null && fields.Count() > 0)
                    {
                        CreateCandidateObjectCreationProblem(database, location, sp, stringWriter, simpleLog, fields,
                                                             target,
                                                             errorLog, targetType, targetObjectType);
                    }

                    if (fields == null || fields.Count() == 0 && targetObjectType != null && !infeasible)
                    {
                        CreateCandidateObjectCreationProblemForSingleType(stringWriter, sp, location, targetObjectType,
                                                                          database, simpleLog, errorLog);
                    }

                    simpleLog.AppendLine("============end Log Problem================");
                    simpleLog.AppendLine();
                }
                catch (Exception ex)
                {
                    Host.GetService <ProblemTrackDatabase>().ErrorLog.AppendLine("Error in problem observer: " + ex);
                }
//                DumpInfoToDebugFile(sb.ToString(),outputFile);
            }