private StatementSyntax GenStatement() { while (true) { StatementKind kind = (StatementKind)Options.StatementTypeDist.Sample(Random.Rng); if ((kind == StatementKind.Block || kind == StatementKind.If) && ShouldRejectRecursion()) { continue; } switch (kind) { case StatementKind.Block: return(GenBlock(false)); case StatementKind.Assignment: return(GenAssignmentStatement()); case StatementKind.Call: return(GenCallStatement(tryExisting: ShouldRejectRecursion())); case StatementKind.If: return(GenIf()); case StatementKind.Return: return(GenReturn()); default: throw new Exception("Unreachable"); } } }
private static Document OpenTemplate(StatementKind kind) { return(Word.Documents.Open( FileName: Path.Combine(WordExport.TemplateFolder, kind.ToString() + ".docx"), ReadOnly: true, AddToRecentFiles: false )); }
public Statement(bool initializeAtZero, StatementKind kind, ElementExpression left, ElementExpression right) { InitializeAtZero = initializeAtZero; Kind = kind; Left = left; Right = right; }
private StatementSyntax GenStatement(bool allowReturn = true) { if (_finallyCount > 0) { allowReturn = false; } while (true) { StatementKind kind = (StatementKind)Options.StatementTypeDist.Sample(Random.Rng); if ((kind == StatementKind.Block || kind == StatementKind.If || kind == StatementKind.TryFinally) && ShouldRejectRecursion()) { continue; } if (kind == StatementKind.Return && !allowReturn) { continue; } switch (kind) { case StatementKind.Block: return(GenBlock(false)); case StatementKind.Assignment: return(GenAssignmentStatement()); case StatementKind.Call: return(GenCallStatement(tryExisting: ShouldRejectRecursion())); case StatementKind.If: return(GenIf()); case StatementKind.TryFinally: return(GenTryFinally()); case StatementKind.Return: return(GenReturn()); default: throw new Exception("Unreachable"); } } bool ShouldRejectRecursion() => Options.StatementRejection.Reject(_level, Random.Rng); }
private static IEnumerable <Singularity.TableSchema> GetSchemas(StatementKind kind) { Document sd = null; try { sd = OpenTemplate(kind); var p = (dynamic)sd.CustomDocumentProperties; string[] tableNames = p["Singularity-Tables"]?.Value?.ToString().Split(',') ?? new string[0]; return(tableNames .Select(typeof(Person).Assembly.GetType) .Select(t => t.InvokeMember("Schema", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Static, null, null, null)) .Cast <Singularity.TableSchema>()); } catch { // The CustomDocumentProperties indexer can mysteriously fail. // When that happens, let the user load things by hand instead // of making it impossible to generate statements. return(Enumerable.Empty <Singularity.TableSchema>()); } finally { sd?.CloseDoc(); } }
public StatementInfo(Person person, DateTime startDate, StatementKind kind) { if (person == null) { throw new ArgumentNullException("person"); } Person = person; data = person.Table.Context; if (data == null) { throw new ArgumentException("The person must be attached to a DataContext (for now)", "person"); } switch (kind) { case StatementKind.Bill: if (person.Pledges.Any() && !person.Pledges.Any(p => p.Date >= startDate)) { startDate = new DateTime(person.Pledges.OrderBy(p => p.Date).Last().Date.Year, 1, 1); } StartDate = startDate; EndDate = DateTime.MaxValue; break; case StatementKind.Receipt: StartDate = new DateTime(startDate.Year, 1, 1); EndDate = new DateTime(startDate.Year + 1, 1, 1).AddTicks(-1); break; } Kind = kind; Recalculate(); }
: super(StatementKind.Continue) { }
public StatementNode(StatementKind statementKind) { this.StatementKind = statementKind; }
: super(StatementKind.If) { }
public FStatement(FElement left, StatementKind kind, FElementExpression expression) { }
: super(StatementKind.GotoCase) { this.Label = label; }
: super(StatementKind.Expression) { }
public static bool IsNeverRoot(StatementKind kind) { return kind == StatementKind.Constant || kind == StatementKind.New || kind == StatementKind.Variable; }
: super(StatementKind.While) { }
: super(StatementKind.Do) { }
protected Statement(StatementKind statementKind) { this.StatementKind = statementKind; }
SimpleStatement(StatementKind statementKind) : super(statementKind)
: super(StatementKind.Foreach) { }
: super(StatementKind.Return) { this.Value = value; }
: super(StatementKind.Throw) { }
public StatementInfo(Person person, DateTime startDate, StatementKind kind) { if (person == null) throw new ArgumentNullException("person"); Person = person; data = person.Table.Context; if (data == null) throw new ArgumentException("The person must be attached to a DataContext (for now)", "person"); switch (kind) { case StatementKind.Bill: if (person.Pledges.Any() && !person.Pledges.Any(p => p.Date >= startDate)) startDate = new DateTime(person.Pledges.OrderBy(p => p.Date).Last().Date.Year, 1, 1); StartDate = startDate; EndDate = DateTime.MaxValue; break; case StatementKind.Receipt: StartDate = new DateTime(startDate.Year, 1, 1); EndDate = new DateTime(startDate.Year + 1, 1, 1).AddTicks(-1); break; } Kind = kind; Recalculate(); }
public static bool CreatesContext(StatementKind kind) { return false; }
: super(StatementKind.Try) { this.CatchClauses = new ArrayList<CatchClauseNode>(); }
public static bool IsRootOnly(StatementKind kind) { return kind == StatementKind.Declaration || kind == StatementKind.Assignment; }
SimpleStatement(StatementKind statementKind) : super(statementKind) {
: super(StatementKind.Try) { this.Body = body; this.CatchClauses = (catchClauses == null) ? Query.empty<CatchClause>() : Query.asIterable((CatchClause[])catchClauses.clone()); this.Finally = finallyBlock; }
: super(StatementKind.Synchronized) { this.Lock = lock; this.Body = body; }
public Statement(StatementKind kind, Element left, ElementExpression right) { Kind = kind; Left = left ?? throw new ArgumentNullException(nameof(left)); Right = right ?? throw new ArgumentNullException(nameof(right)); }
: super(StatementKind.LocalDeclaration) { this.Declarators = new ArrayList<VariableDeclaratorNode>(); }
: super(StatementKind.Return) { }
: super(StatementKind.Expression) { this.Expression = expression; }
: super(StatementKind.Block) { this.Statements = (statements == null) ? Query.empty<Statement>() : Query.asIterable((Statement[])statements.clone()); }
: super(StatementKind.Foreach) { this.Variable = variable; this.Expression = expression; this.Body = body; }
: super(StatementKind.For) { this.Initializer = (initializer == null) ? Query.empty<Statement>() : Query.asIterable((Statement[])initializer.clone()); this.Condition = condition; this.Iterator = (iterator == null) ? Query.empty<Statement>() : Query.asIterable((Statement[])iterator.clone()); this.Body = body; }
: super(StatementKind.Labeled) { this.Label = label; this.Statement = statement; }
public WordStatementInfo(Person person, DateTime startDate, StatementKind kind, bool resendExistingReceipts) : base(person, startDate, kind) { this.resendExistingReceipts = resendExistingReceipts; }
: super(StatementKind.Labeled) { }
: super(StatementKind.Break) { }
: super(StatementKind.For) { this.Initializer = new ArrayList<StatementNode>(); this.Iterator = new ArrayList<StatementNode>(); }
: super(StatementKind.Empty) { }
LoopStatement(StatementKind statementKind, Expression condition, Statement body) : super(statementKind)