protected override void OptimizePre() { // Removes excessive levels of nesting. for (int i = 0; i < this.Statements.Count; i++) { StatementSilvernode thisStatement = this.Statements[i]; // Blocks cannot happen with blocks. Remove nested blocks (deeply)! if (thisStatement is BlockSilvernode) { BlockSilvernode block = (BlockSilvernode)thisStatement; this.Statements.RemoveAt(i); this.Statements.InsertRange(i, block.Statements); i--; } else if (thisStatement is StatementsSequenceSilvernode) { StatementsSequenceSilvernode sequence = (StatementsSequenceSilvernode)thisStatement; sequence.OptimizeRecursively(); List <StatementSilvernode> points = sequence.List; this.Statements.RemoveAt(i); this.Statements.InsertRange(i, points); i--; } } }
public WhileSilvernode( Silvernode condition, List <ContractSilvernode> verificationConditions, BlockSilvernode statementBlock, SyntaxNode originalNode) : base(originalNode) { this.condition = condition; this.verificationConditions = verificationConditions; this.statementBlock = statementBlock; }
protected SubroutineSilvernode(SyntaxNode originalNode, IdentifierSilvernode identifier, List <ParameterSilvernode> parameters, string returnValueName, TypeSilvernode returnType, List <ContractSilvernode> verificationConditions, BlockSilvernode block) : base(originalNode) { this.Identifier = identifier; this.Parameters = parameters; this.ReturnValueName = returnValueName; this.ReturnType = returnType; this.VerificationConditions = verificationConditions; this.Block = block; }
public FunctionSilvernode(SyntaxNode methodDeclarationSyntax, IdentifierSilvernode identifierSilvernode, List <ParameterSilvernode> parameters, string returnName, TypeSilvernode returnType, List <ContractSilvernode> verificationConditions, BlockSilvernode block) : base(methodDeclarationSyntax, identifierSilvernode, parameters, returnName, returnType, verificationConditions, block) { }
protected override void OptimizePost() { // Removes the "goto end ; label end" sequence at the end if it's possible. BlockSilvernode block = this.Children.FirstOrDefault(s => s is BlockSilvernode) as BlockSilvernode; if (block != null) { int howManyGotos = block.Descendants.Count(sn => sn is GotoSilvernode && ((GotoSilvernode)sn).Label == Constants.SilverMethodEndLabel); StatementSilvernode lastStatement = block.Statements.Count >= 1 ? block.Statements[block.Statements.Count - 1] : null; StatementSilvernode preLastStatement = block.Statements.Count >= 2 ? block.Statements[block.Statements.Count - 2] : null; if (lastStatement != null && (lastStatement.GetType() == typeof(LabelSilvernode) && ((LabelSilvernode)lastStatement).Label == Constants.SilverMethodEndLabel) && preLastStatement != null && (preLastStatement.GetType() == typeof(GotoSilvernode) && ((GotoSilvernode)preLastStatement).Label == Constants.SilverMethodEndLabel) && howManyGotos == 1) { block.Statements.RemoveRange(block.Statements.Count - 2, 2); } else if (howManyGotos == 0 && (lastStatement.GetType() == typeof(LabelSilvernode) && ((LabelSilvernode)lastStatement).Label == Constants.SilverMethodEndLabel)) { block.Statements.RemoveAt(block.Statements.Count - 1); } } }