示例#1
0
        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");
                }
            }
        }
示例#2
0
 private static Document OpenTemplate(StatementKind kind)
 {
     return(Word.Documents.Open(
                FileName: Path.Combine(WordExport.TemplateFolder, kind.ToString() + ".docx"),
                ReadOnly: true,
                AddToRecentFiles: false
                ));
 }
示例#3
0
 public Statement(bool initializeAtZero, StatementKind kind,
                  ElementExpression left, ElementExpression right)
 {
     InitializeAtZero = initializeAtZero;
     Kind             = kind;
     Left             = left;
     Right            = right;
 }
示例#4
0
        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);
        }
示例#5
0
        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();
            }
        }
示例#6
0
        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) {
		}
示例#10
0
 public FStatement(FElement left, StatementKind kind, FElementExpression expression)
 {
 }
			: super(StatementKind.GotoCase) {
			this.Label = label;
		}
			: super(StatementKind.Expression) {
		}
示例#13
0
 public static bool IsNeverRoot(StatementKind kind)
 {
     return kind == StatementKind.Constant || kind == StatementKind.New || kind == StatementKind.Variable;
 }
			: super(StatementKind.While) {
		}
			: super(StatementKind.Do) {
		}
示例#16
0
 protected Statement(StatementKind statementKind)
 {
     this.StatementKind = statementKind;
 }
示例#17
0
 SimpleStatement(StatementKind statementKind)
     : super(statementKind)
			: super(StatementKind.Foreach) {
		}
     : super(StatementKind.Return) {
     this.Value = value;
 }
			: super(StatementKind.Throw) {
		}
示例#21
0
        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();
        }
示例#22
0
 public static bool CreatesContext(StatementKind kind)
 {
     return false;
 }
			: super(StatementKind.Try) {
			this.CatchClauses = new ArrayList<CatchClauseNode>();
		}
示例#24
0
 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;
		}
示例#28
0
 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;
 }
 protected Statement(StatementKind statementKind) {
     this.StatementKind = statementKind;
 }
     : 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;
 }
示例#36
0
 public StatementNode(StatementKind statementKind)
 {
     this.StatementKind = statementKind;
 }
     : super(StatementKind.Labeled) {
     this.Label = label;
     this.Statement = statement;
 }
示例#38
0
 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)