Exemple #1
0
        public List <AnalysisResult> RunAnalysis(string source, AnalysisType analysisType, WorklistType worklistType)
        {
            var ast = Parser.Util.StringToAst(source);
            List <AnalysisResult> res = new List <AnalysisResult>();

            switch (analysisType)
            {
            case AnalysisType.ReachingDefinitions:
            {
                var analysis      = new RDAnalysis(ast, worklistType.ToString());
                var filledLattice = analysis.GetFilledLattice();
                var circlelattice = analysis.GetCircleLattice();
                _iterationSteps = analysis.GetIterationSteps();

                string htmlFormat = "<kbd>{0}</kbd> <span class='oi oi-arrow-right' aria-hidden='true'></span> {{ <var>{1}</var> }}<br/>";

                int label = 0;

                var zipped = circlelattice.Zip(filledLattice, (entry, exit) => new AnalysisResult {
                        Label     = (label++).ToString(),
                        NodeEntry = entry.GetDomain().ToHashSet().Select(x => new AnalysisIdentifier(x, htmlFormat)).ToList()
                                    .GroupBy(a => new { a.ID, a.Name, a.FormatString })
                                    .Select(b => new AnalysisIdentifier  {
                            Name         = b.Key.Name,
                            ID           = b.Key.ID,
                            Label        = b.SelectMany(a => a.Label).ToList(),
                            FormatString = b.Key.FormatString,
                        }).ToList(),
                        NodeExit = exit.GetDomain().ToHashSet().Select(x => new AnalysisIdentifier(x, htmlFormat)).ToList()
                                   .GroupBy(a => new { a.ID, a.Name, a.FormatString })
                                   .Select(b => new AnalysisIdentifier  {
                            Name         = b.Key.Name,
                            ID           = b.Key.ID,
                            Label        = b.SelectMany(a => a.Label).ToList(),
                            FormatString = b.Key.FormatString,
                        }).ToList(),
                    }).ToList();

                return(zipped);
            }

            case AnalysisType.LiveVariables:
            {
                var analysis      = new LVAnalysis(ast, worklistType.ToString());
                var filledLattice = analysis.GetFilledLattice();
                var circlelattice = analysis.GetCircleLattice();
                _iterationSteps = analysis.GetIterationSteps();

                int    label      = 0;
                string htmlFormat = "<kbd>{0}</kbd> <span class='oi oi-arrow-right' aria-hidden='true'></span> Live <br/>";

                var zipped = circlelattice.Zip(filledLattice, (entry, exit) => new AnalysisResult {
                        Label     = (label++).ToString(),
                        NodeEntry = entry.GetDomain().ToHashSet().Select(x => new AnalysisIdentifier(x, htmlFormat)).ToList()
                                    .GroupBy(a => new { a.ID, a.Name, a.FormatString })
                                    .Select(b => new AnalysisIdentifier  {
                            Name         = b.Key.Name,
                            ID           = b.Key.ID,
                            Label        = b.SelectMany(a => a.Label).ToList(),
                            FormatString = b.Key.FormatString
                        }).ToList(),
                        NodeExit = exit.GetDomain().ToHashSet().Select(x => new AnalysisIdentifier(x, htmlFormat)).ToList()
                                   .GroupBy(a => new { a.ID, a.Name, a.FormatString })
                                   .Select(b => new AnalysisIdentifier  {
                            Name         = b.Key.Name,
                            ID           = b.Key.ID,
                            Label        = b.SelectMany(a => a.Label).ToList(),
                            FormatString = b.Key.FormatString
                        }).ToList(),
                    }).ToList();

                return(zipped);
            }

            case AnalysisType.FaintVariables:
            {
                var analysis      = new FVAnalysis(ast, worklistType.ToString());
                var filledLattice = analysis.GetFilledLattice();
                var circlelattice = analysis.GetCircleLattice();
                _iterationSteps = analysis.GetIterationSteps();

                int    label      = 0;
                string htmlFormat = "<kbd>{0}</kbd> <span class='oi oi-arrow-right' aria-hidden='true'></span> Strongly Live<br/>";

                var zipped = circlelattice.Zip(filledLattice, (entry, exit) => new AnalysisResult {
                        Label     = (label++).ToString(),
                        NodeEntry = entry.GetDomain().ToHashSet().Select(x => new AnalysisIdentifier(x, htmlFormat)).ToList()
                                    .GroupBy(a => new { a.ID, a.Name, a.FormatString })
                                    .Select(b => new AnalysisIdentifier  {
                            Name         = b.Key.Name,
                            ID           = b.Key.ID,
                            Label        = b.SelectMany(a => a.Label).ToList(),
                            FormatString = b.Key.FormatString
                        }).ToList(),
                        NodeExit = exit.GetDomain().ToHashSet().Select(x => new AnalysisIdentifier(x, htmlFormat)).ToList()
                                   .GroupBy(a => new { a.ID, a.Name, a.FormatString })
                                   .Select(b => new AnalysisIdentifier  {
                            Name         = b.Key.Name,
                            ID           = b.Key.ID,
                            Label        = b.SelectMany(a => a.Label).ToList(),
                            FormatString = b.Key.FormatString
                        }).ToList(),
                    }).ToList();

                return(zipped);
            }

            case AnalysisType.DetectionOfSigns:
            {
                var analysis      = new DSAnalysis(ast, worklistType.ToString());
                var filledLattice = analysis.GetFilledLattice();
                var circlelattice = analysis.GetCircleLattice();
                _iterationSteps = analysis.GetIterationSteps();

                int    label      = 0;
                string htmlFormat = "<kbd>{0}</kbd> <span class='oi oi-arrow-right' aria-hidden='true'></span> {{ <var>{1}</var> }}<br/>";

                var zipped = circlelattice.Zip(filledLattice, (entry, exit) => new AnalysisResult {
                        Label     = (label++).ToString(),
                        NodeEntry = entry.GetDomain().Select(x => new AnalysisIdentifier(x, htmlFormat)).ToList()
                                    .GroupBy(a => new { a.ID, a.Name, a.FormatString })
                                    .Select(b => new AnalysisIdentifier  {
                            Name         = b.Key.Name,
                            ID           = b.Key.ID,
                            Label        = b.SelectMany(a => a.Label).ToList(),
                            FormatString = b.Key.FormatString
                        }).ToList(),
                        NodeExit = exit.GetDomain().ToHashSet().Select(x => new AnalysisIdentifier(x, htmlFormat)).ToList()
                                   .GroupBy(a => new { a.ID, a.Name, a.FormatString })
                                   .Select(b => new AnalysisIdentifier  {
                            Name         = b.Key.Name,
                            ID           = b.Key.ID,
                            Label        = b.SelectMany(a => a.Label).ToList(),
                            FormatString = b.Key.FormatString
                        }).ToList(),
                    }).ToList();

                return(zipped);
            }

            case AnalysisType.IntervalAnalysis:
            {
                var analysis      = new IAAnalysis(ast, worklistType.ToString());
                var filledLattice = analysis.GetFilledLattice();
                var circlelattice = analysis.GetCircleLattice();
                _iterationSteps = analysis.GetIterationSteps();

                int    label      = 0;
                string htmlFormat = "<kbd>{0}</kbd> <span class='oi oi-arrow-right' aria-hidden='true'></span> {{ <var>{1}</var> }}<br/>";

                var zipped = circlelattice.Zip(filledLattice, (entry, exit) => new AnalysisResult {
                        Label     = (label++).ToString(),
                        NodeEntry = entry.GetDomain().Select(x => new AnalysisIdentifier(x, htmlFormat)).ToList()
                                    .GroupBy(a => new { a.ID, a.Name, a.FormatString })
                                    .Select(b => new AnalysisIdentifier  {
                            Name         = b.Key.Name,
                            ID           = b.Key.ID,
                            Label        = b.SelectMany(a => a.Label).ToList(),
                            FormatString = b.Key.FormatString
                        }).ToList(),
                        NodeExit = exit.GetDomain().ToHashSet().Select(x => new AnalysisIdentifier(x, htmlFormat)).ToList()
                                   .GroupBy(a => new { a.ID, a.Name, a.FormatString })
                                   .Select(b => new AnalysisIdentifier  {
                            Name         = b.Key.Name,
                            ID           = b.Key.ID,
                            Label        = b.SelectMany(a => a.Label).ToList(),
                            FormatString = b.Key.FormatString
                        }).ToList(),
                    }).ToList();

                return(zipped);
            }

            default:
            {
                break;
            }
            }

            return(res);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var val3    = new ExtendedZ(3);
            var val4    = new ExtendedZ(4);
            var posinf  = ExtendedZ.PositiveInfinity();
            var negainf = ExtendedZ.NegativeInfinity();

            Console.WriteLine($"3 <= 4: {val3 <= val4}");
            Console.WriteLine($"4 <= 3: {val4 <= val3}");
            Console.WriteLine($"3 <= 3: {val3 <= val3}");
            Console.WriteLine($"negaInf <= 4: {negainf <= val4}");
            Console.WriteLine($"4 <= negaInf: {val4 <= negainf}");
            Console.WriteLine($"negainf <= posinf: {negainf <= posinf}");
            Console.WriteLine($"negainf <= negainf: {negainf <= negainf}");
            Console.WriteLine($"posinf <= 4: {posinf <= val4}");
            Console.WriteLine($"4 <= posinf: {val4 <= posinf}");
            Console.WriteLine($"posinf <= negainf: {posinf <= negainf}");
            Console.WriteLine($"posinf <= posinf: {posinf <= posinf}");

            var input = @"
{
    int x;
    x := 1;
    while (x > 0) {
        x := x - 1;
    }
}
";

            var input2 = @"
{
    int x;
    int[1] a;
    read a[0];
    a[0] := 1;
    read a[0];
    if (x > 0) {
        a[-1] := 0;
    }
    read a[0];
}
";

            var input3 = @"
{
int x;
x := -1;
while (x > 0) {
    x := x - 1;
}
x := x * x;
}
";

            var input4 = @"
{
    int x;
    y := 0;
}
";

            var input5 = @"
{
  { int fst; int snd } r;
  int x;
  r := (0,1);
  read x;
  while (x > 0) {
    r.fst := r.fst + x;
    r.snd := r.snd + x;
    x := x-1;
  }
  r := (0,0);
}
";
            //var result = Parser.Util.StringToAst(input);
            //var analysis = new IAAnalysis(result);
            //Console.WriteLine(analysis);
            //var result2 = Parser.Util.StringToAst(input2);
            //var analysis2 = new IAAnalysis(result2);
            //Console.WriteLine(analysis2);
            //var result3 = Parser.Util.StringToAst(input3);
            //var analysis3 = new IAAnalysis(result3, "FIFOWorklist");
            //Console.WriteLine(analysis3);
            //var result4 = Parser.Util.StringToAst(input4);
            //var analysis4 = new IAAnalysis(result4, "FIFOWorklist");
            //Console.WriteLine(analysis4);
            var result5   = Parser.Util.StringToAst(input5);
            var analysis5 = new RDAnalysis(result5, "FIFOWorklist");

            Console.WriteLine(analysis5);
        }