public override void Verify(string fileName, TransHelper.TransEnv env, Microsoft.FSharp.Collections.FSharpList <CAST.Top> decls) { // this really only dumps the code to the .bpl file Init(env, fileName); decls = env.ApplyTransformers(decls); if (options.NoVerification) { return; } if (env.ShouldContinue) { if (env.Options.AggressivePruning && env.Options.Functions.Count() > 0) { decls = TransUtil.pruneBy(env, env.Options.Functions.First(), decls); } var boogieDecls = Translator.translate(null, env, () => VccCommandLineHost.StandardPrelude(options), decls); var p = TranslateToBoogie(boogieDecls); if (env.ShouldContinue) { try { swSaveBPL.Start(); CommandLineOptions.Install(new CommandLineOptions()); using (var writer = new TokenTextWriter(AddOutputDirIfRequested(Path.ChangeExtension(fileName, ".bpl")))) { p.Emit(writer); } } finally { swSaveBPL.Stop(); } } } }
private Program TranslateToBoogie(Microsoft.FSharp.Collections.FSharpList <BoogieAST.Decl> boogieDecls) { try { swBoogieAST.Start(); return(BoogieAST.trProgram(boogieDecls)); } finally { swBoogieAST.Stop(); } }
public override FScheme.Value Evaluate(Microsoft.FSharp.Collections.FSharpList <FScheme.Value> args) { var text = ((FScheme.Value.String)args[0]).Item; var position = (XYZ)((FScheme.Value.Container)args[1]).Item; var normal = (XYZ)((FScheme.Value.Container)args[2]).Item; var up = (XYZ)((FScheme.Value.Container)args[3]).Item; var depth = ((FScheme.Value.Number)args[4]).Item; var textTypeName = ((FScheme.Value.String)args[5]).Item; //find a text type in the document to use var fec = new FilteredElementCollector(dynRevitSettings.Doc.Document); fec.OfClass(typeof(ModelTextType)); ModelTextType mtt; if (fec.ToElements().Cast <ModelTextType>().Any(x => x.Name == textTypeName)) { mtt = fec.ToElements().First() as ModelTextType; } else { throw new Exception(string.Format("A model text type named {0} could not be found in the document.", textTypeName)); } Autodesk.Revit.DB.ModelText mt; if (Elements.Any()) { if (dynUtils.TryGetElement(Elements[0], out mt)) { //if the position or normal are different //we have to recreate var currPos = mt.Location as LocationPoint; if (!position.IsAlmostEqualTo(currPos.Point)) { dynRevitSettings.Doc.Document.Delete(Elements[0]); mt = CreateModelText(normal, position, -up, text, mtt, depth); Elements.Add(mt.Id); } else { //reset the text and the depth mt.Text = text; mt.Depth = depth; Elements[0] = mt.Id; } } } else { mt = CreateModelText(normal, position, -up, text, mtt, depth); Elements.Add(mt.Id); } return(FScheme.Value.NewContainer(mt)); }
internal VccFunctionVerifier(VccPlugin parent, Microsoft.FSharp.Collections.FSharpList <CAST.Top> currentDecls, TransHelper.TransEnv env) : base(env, currentDecls) { this.currentDecls = currentDecls; this.parent = parent; this.env = env; if (!this.InitBoogie()) { this.env.Error(Token.NoToken, 1000, "Boogie initialization failed."); } }
private static Ast.smv_module CreateTimeModule(string name) { List <Tuple <string, Tuple <Int64, Int64> > > vars; List <Tuple <string, Ast.types> > varwithtpyes; Ast.expr init; Ast.expr transrel; Ast.expr resetident = Ast.expr.NewIdent("reset"); List <string> parameters = new List <string>(); List <Ast.section> secs = new List <Ast.section>(); // vars = TimerVars(); varwithtpyes = ConvertRngTupleToTypes(vars); init = TimerInit(vars); transrel = TimerTransitions(vars, resetident); Debug.Assert(transrel != null); // Create sections Ast.section trans = Ast.section.NewTrans(transrel); Ast.section inits = Ast.section.NewInit(init); Ast.section varbls = Ast.section.NewVar(FSharpInteropExtensions.ToFSharplist <Tuple <string, Ast.types> >(varwithtpyes)); // Dirty conversions Microsoft.FSharp.Collections.FSharpList <Ast.section> sections = FSharpInteropExtensions.ToFSharplist <Ast.section>(secs); Microsoft.FSharp.Collections.FSharpList <string> pars = FSharpInteropExtensions.ToFSharplist <string>(parameters); // Create module Ast.smv_module timermodule = new Ast.smv_module(name, pars, sections); //Fill memory representation //Trans List <Ast.expr> transrels = new List <Ast.expr>(); transrels.Add(transrel); _trans.Add(timermodule, transrels); //init List <Ast.expr> initials = new List <Ast.expr>(); initials.Add(init); _init.Add(timermodule, initials); //params _params.Add(timermodule, parameters); //vars _rvars.Add(timermodule, vars); //_mvars _mvars.Add(timermodule, new List <Tuple <string, Tuple <string, List <List <string> > > > >()); //_svars _svars.Add(timermodule, new List <Tuple <string, List <string> > >()); //iassigns _iassigns.Add(timermodule, new List <Tuple <string, Ast.expr> >()); //nassigns _nassigns.Add(timermodule, new List <Tuple <string, Ast.expr> >()); return(timermodule); }
public bool csvConnection() { string filename = textBox1.Text; if (filename == "") { return(false); } else { alldata = Library5.HW5P2.readfile(filename); return(true); } }
internal Boogie.Program GetBoogieProgram(Microsoft.FSharp.Collections.FSharpList <BoogieAST.Decl> boogieDecls) { var p = BoogieAST.trProgram(boogieDecls); try { swBoogie.Start(); var pp = new Boogie.Program(); pp.TopLevelDeclarations.AddRange(VccCommandLineHost.StandardPrelude(options).TopLevelDeclarations); pp.TopLevelDeclarations.AddRange(p.TopLevelDeclarations); return(pp); } finally { swBoogie.Stop(); } }
private void button15_Click(object sender, EventArgs e) { if (csvConnection()) { textBox8.Clear(); Microsoft.FSharp.Collections.FSharpList <string> countryNames = Library5.HW5P2.countries(alldata); textBox8.AppendText("Unique Countries: "); textBox8.Text += System.Environment.NewLine; textBox8.AppendText(String.Join(Environment.NewLine, countryNames)); textBox8.Text += System.Environment.NewLine; } else { textBox8.Clear(); textBox8.Text = "Error. Not a Valid CSV File Name"; } }
private void cmdLoadExam03_Click(object sender, EventArgs e) { this.lstScores.Items.Clear(); this.lstAnalysis.Items.Clear(); this.lstTrend.Items.Clear(); string folder = this.txtFolderPath.Text; string filepath = System.IO.Path.Combine(folder, "Exam03.txt"); scores = MyLibrary.InputScores(filepath); foreach (var score in scores) { this.lstScores.Items.Add(score); } this.cmdAnalysis.Enabled = true; this.cmdTrend.Enabled = true; }
public override FScheme.Value Evaluate(Microsoft.FSharp.Collections.FSharpList <FScheme.Value> args) { var matName = ((FScheme.Value.String)args[0]).Item; var fec = new FilteredElementCollector(dynRevitSettings.Doc.Document); Autodesk.Revit.DB.Material foundMat; fec.OfClass(typeof(Autodesk.Revit.DB.Material)); try { foundMat = (Autodesk.Revit.DB.Material)fec.ToElements().First(x => x.Name == matName); } catch (InvalidOperationException) { throw new Exception("A material with that name could not be found."); } return(FScheme.Value.NewContainer(foundMat.Id)); }
public override FScheme.Value Evaluate(Microsoft.FSharp.Collections.FSharpList <FScheme.Value> args) { //if we're in a family document, don't even try to add a floor if (dynRevitSettings.Doc.Document.IsFamilyDocument) { throw new Exception("Floors can not be created in family documents."); } var edges = ((Value.List)args[0]).Item; var floorType = (FloorType)((Value.Container)args[1]).Item; var level = (Autodesk.Revit.DB.Level)((Value.Container)args[2]).Item; Autodesk.Revit.DB.Floor floor = null; //convert the edges to a curveArray if (edges.Count() < 3) { throw new Exception("The edge list provided does not have an adequate number of edges to create a floor."); } if (this.Elements.Any()) { if (dynUtils.TryGetElement(this.Elements[0], out floor)) { //Delete the existing floor. Revit API does not allow update of floor sketch. dynRevitSettings.Doc.Document.Delete(floor.Id); } floor = CreateFloor(edges, floorType, level); this.Elements[0] = floor.Id; } else { floor = CreateFloor(edges, floorType, level); Elements.Add(floor.Id); } return(Value.NewContainer(floor)); }
private void button17_Click(object sender, EventArgs e) { if (csvConnection()) { Microsoft.FSharp.Collections.FSharpList <Tuple <string, int> > nArticles = Library5.HW5P2.numberOfArticlesEachMonth(alldata); textBox8.Clear(); textBox8.AppendText("Number of Articles for Each Month:"); textBox8.Text += System.Environment.NewLine; string output = Library5.HW5P2.buildHistogram(nArticles, alldata.Length, ""); output = output.Replace("/n", System.Environment.NewLine); textBox8.AppendText(output); textBox8.Text += System.Environment.NewLine; } else { textBox8.Clear(); textBox8.Text = "Error. Not a Valid CSV File Name"; } }
private void button18_Click(object sender, EventArgs e) { if (csvConnection()) { Microsoft.FSharp.Collections.FSharpList <Tuple <string, double> > reliablepct = Library5.HW5P2.reliableArticlePercentEachPublisher(alldata); textBox8.Clear(); textBox8.AppendText("Percentage of Articles That Are Reliable for Each Publisher: "); textBox8.Text += System.Environment.NewLine; Microsoft.FSharp.Collections.FSharpList <string> lines1 = Library5.HW5P2.printNamesAndPercentages(reliablepct); foreach (string line in lines1) { textBox8.AppendText(line); textBox8.Text += System.Environment.NewLine; } } else { textBox8.Clear(); textBox8.Text = "Error. Not a Valid CSV File Name"; } }
private void button19_Click(object sender, EventArgs e) { if (csvConnection()) { Microsoft.FSharp.Collections.FSharpList <Tuple <string, double> > result = Library5.HW5P2.averageguardscore(alldata); Microsoft.FSharp.Collections.FSharpList <string> lines1 = Library5.HW5P2.printNamesAndFloats(result); textBox8.Clear(); textBox8.AppendText("Average News Guard Score for Each Country: "); textBox8.Text += System.Environment.NewLine; // Call the library function transforming the list of pairs into a list of strings // Output the list of strings, one per line foreach (string line in lines1) { textBox8.AppendText(line); textBox8.Text += System.Environment.NewLine; } } else { textBox8.Clear(); textBox8.Text = "Error. Not a Valid CSV File Name"; } }
public override FunctionVerifier GetFunctionVerifier(string fileName, TransHelper.TransEnv env, Microsoft.FSharp.Collections.FSharpList <CAST.Top> decls) { Init(env, fileName); decls = env.ApplyTransformers(decls); return(new VccFunctionVerifier(this, decls, env)); }
public override FScheme.Value Evaluate(Microsoft.FSharp.Collections.FSharpList <FScheme.Value> args) { //if we're in a family document, don't even try to add a floor if (dynRevitSettings.Doc.Document.IsFamilyDocument) { throw new Exception("Walls can not be created in family documents."); } var curve = (Curve)((FScheme.Value.Container)args[0]).Item; var level = (Autodesk.Revit.DB.Level)((FScheme.Value.Container)args[1]).Item; var wallType = (WallType)((FScheme.Value.Container)args[2]).Item; var height = ((FScheme.Value.Number)args[3]).Item; Wall wall = null; if (this.Elements.Any()) { bool bSuccess = false; if (dynUtils.TryGetElement(this.Elements[0], out wall)) { if (wall.Location is LocationCurve) { var wallLocation = wall.Location as LocationCurve; if ((wallLocation.Curve is Line == curve is Line) || (wallLocation.Curve is Arc == curve is Arc)) { wallLocation.Curve = curve; Parameter baseLevelParameter = wall.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_BASE_CONSTRAINT); Parameter topOffsetParameter = wall.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM); Parameter wallTypeParameter = wall.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ELEM_TYPE_PARAM); if (baseLevelParameter.AsElementId() != level.Id) { baseLevelParameter.Set(level.Id); } if (Math.Abs(topOffsetParameter.AsDouble() - height) > 1.0e-10) { topOffsetParameter.Set(height); } if (wallTypeParameter.AsElementId() != wallType.Id) { wallTypeParameter.Set(wallType.Id); } bSuccess = true; } } if (!bSuccess) { dynRevitSettings.Doc.Document.Delete(wall.Id); } //Delete the existing floor. Revit API does not allow update of floor sketch. } if (!bSuccess) { wall = Wall.Create(dynRevitSettings.Doc.Document, curve, wallType.Id, level.Id, height, 0.0, false, false); this.Elements[0] = wall.Id; } } else { wall = Wall.Create(dynRevitSettings.Doc.Document, curve, wallType.Id, level.Id, height, 0.0, false, false); Elements.Add(wall.Id); } return(FScheme.Value.NewContainer(wall)); }
internal VccFunctionVerifier(VccPlugin parent, Microsoft.FSharp.Collections.FSharpList<CAST.Top> currentDecls, TransHelper.TransEnv env) : base(env, currentDecls) { this.currentDecls = currentDecls; this.parent = parent; this.env = env; if (!this.InitBoogie()) this.env.Error(Token.NoToken, 1000, "Boogie initialization failed."); }
public static void Parse2() { { // best way to get result var x = Many1(Digit).AndR(Upper).Run("123a"); //// throws exception //var rx = x.GetResult(); } { // get as string var y = Many1(Digit).AndR(Many1(Upper)).Run("123A"); Microsoft.FSharp.Collections.FSharpList <char> ry1 = y.GetResult(); var ry2 = new string(ry1.ToArray()); } { var x = Many1(Digit).AndR(Upper).Run("123a"); // does not throw var rx = x.UnwrapResult(); } // arithmetic expressions { var basicExprParser = new OPPBuilder <Unit, int, Unit>() .WithOperators(ops => ops .AddInfix("+", 1, (x, y) => x + y) .AddInfix("*", 2, (x, y) => x * y)) .WithTerms(Natural) .Build() .ExpressionParser; var recursiveExprParser = new OPPBuilder <Unit, int, Unit>() .WithOperators(ops => ops .AddInfix("+", 1, (x, y) => x + y) .AddInfix("*", 2, (x, y) => x * y)) .WithTerms(term => Choice(Natural, Between('(', term, ')'))) .Build() .ExpressionParser; var calculated = recursiveExprParser.Run("4*(2+3*2)").GetResult(); } // save expr tree as graph { var naturalTermToBasicElt = Natural.Map(i => new BasicValue { Val = i } as IBasicElt); var basicExprParser = new OPPBuilder <Unit, IBasicElt, Unit>() .WithOperators(ops => ops .AddInfix("+", 1, (x, y) => new BasicExprTree("PLUS", x, y)) .AddInfix("*", 2, (x, y) => new BasicExprTree("TIMES", x, y))) //.WithTerms(Natural.Map(i => new BasicValue { Val = i } as IBasicElt)) .WithTerms(naturalTermToBasicElt) .Build() .ExpressionParser ; var recursiveExprParser = new OPPBuilder <Unit, IBasicElt, Unit>() .WithOperators(ops => ops .AddInfix("+", 1, (x, y) => new BasicExprTree("PLUS", x, y)) .AddInfix("*", 2, (x, y) => new BasicExprTree("TIMES", x, y))) .WithTerms(term => Choice(naturalTermToBasicElt, Between('(', term, ')'))) .Build() .ExpressionParser; var calculated = recursiveExprParser.Run("4*(2+3*2)").GetResult(); var calculatedVal = calculated.Calculate(); } }
private Program PrepareBoogie(Microsoft.FSharp.Collections.FSharpList <BoogieAST.Decl> boogieDecls) { var boogieProgram = parent.GetBoogieProgram(boogieDecls); CloseVcGen(); CommandLineOptions.Clo.Parse(standardBoogieOptions); IErrorSink errorSink = new BoogieErrorSink(parent.options.NoPreprocessor); int numErrors; try { parent.swBoogieResolve.Start(); numErrors = boogieProgram.Resolve(errorSink); } finally { parent.swBoogieResolve.Stop(); } if (numErrors == 0) { try { parent.swBoogieTypecheck.Start(); numErrors = boogieProgram.Typecheck(errorSink); } finally { parent.swBoogieTypecheck.Stop(); } } if (numErrors == 0) { try { parent.swBoogieAI.Start(); AbstractInterpretation.RunAbstractInterpretation(boogieProgram); } finally { parent.swBoogieAI.Stop(); } } if (Boogie.CommandLineOptions.Clo.ExpandLambdas && numErrors == 0) { Boogie.LambdaHelper.ExpandLambdas(boogieProgram); } if (numErrors != 0) { VccCommandLineHost.IncreaseErrorCount(); if (!parent.options.RunTestSuite) { Logger.Instance.Error("attempting to dump BPL to buggy.bpl"); var filename = "buggy.bpl"; if (parent.options.OutputDir != null) { filename = Path.Combine(parent.options.OutputDir, filename); } CommandLineOptions.Install(new CommandLineOptions()); using (TokenTextWriter writer = new TokenTextWriter(filename)) boogieProgram.Emit(writer); } errorMode = true; } return(boogieProgram); }