Beispiel #1
0
            VariableReferenceNode GetStatementEndNode(VariableReferenceNode currentNode, Statement statement)
            {
                var expressions = statement.AcceptVisitor(getExpr);
                VariableReferenceNode endNode;

                ExpressionNodeCreationVisitor.CreateNode(references, resolver, expressions, currentNode, out endNode);
                return(endNode);
            }
		object ConvertStatementInternal(Statement stmt)
		{
			Statement oldStatement = currentStatement;
			currentStatement = stmt;
			try {
				return stmt.AcceptVisitor(this, null);
			} finally {
				currentStatement = oldStatement;
			}
		}
Beispiel #3
0
 /// <summary>
 /// Generates the code for the statement node.
 /// </summary>
 /// <param name="node">The statement node.</param>
 public void GenerateCode(Statement node)
 {
     try
     {
         node.AcceptVisitor(this);
     }
     catch (AnalizeException e)
     {
         generator.SwallowException(e);
     }
 }
Beispiel #4
0
        object ConvertStatementInternal(Statement stmt)
        {
            Statement oldStatement = currentStatement;

            currentStatement = stmt;
            try {
                return(stmt.AcceptVisitor(this, null));
            } finally {
                currentStatement = oldStatement;
            }
        }
Beispiel #5
0
            ControlFlowNode HandleEmbeddedStatement(Statement embeddedStatement, ControlFlowNode source)
            {
                if (embeddedStatement == null || embeddedStatement.IsNull)
                {
                    return(source);
                }
                ControlFlowNode bodyStart = builder.CreateStartNode(embeddedStatement);

                if (source != null)
                {
                    Connect(source, bodyStart);
                }
                return(embeddedStatement.AcceptVisitor(this, bodyStart));
            }
Beispiel #6
0
        public IList <ControlFlowNode> BuildControlFlowGraph(Statement statement, CSharpAstResolver resolver, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (statement == null)
            {
                throw new ArgumentNullException("statement");
            }
            if (resolver == null)
            {
                throw new ArgumentNullException("resolver");
            }

            NodeCreationVisitor nodeCreationVisitor = new NodeCreationVisitor();

            nodeCreationVisitor.builder = this;
            try {
                this.nodes             = new List <ControlFlowNode>();
                this.labels            = new Dictionary <string, ControlFlowNode>();
                this.gotoStatements    = new List <ControlFlowNode>();
                this.rootStatement     = statement;
                this.resolver          = resolver;
                this.cancellationToken = cancellationToken;

                ControlFlowNode entryPoint = CreateStartNode(statement);
                statement.AcceptVisitor(nodeCreationVisitor, entryPoint);

                // Resolve goto statements:
                foreach (ControlFlowNode gotoStmt in gotoStatements)
                {
                    string          label = ((GotoStatement)gotoStmt.NextStatement).Label;
                    ControlFlowNode labelNode;
                    if (labels.TryGetValue(label, out labelNode))
                    {
                        nodeCreationVisitor.Connect(gotoStmt, labelNode, ControlFlowEdgeType.Jump);
                    }
                }

                AnnotateLeaveEdgesWithTryFinallyBlocks();

                return(nodes);
            } finally {
                this.nodes             = null;
                this.labels            = null;
                this.gotoStatements    = null;
                this.rootStatement     = null;
                this.resolver          = null;
                this.cancellationToken = CancellationToken.None;
            }
        }
Beispiel #7
0
 B.MacroStatement CreateMacro(INode node, string name, Statement embedded, params Expression[] arguments)
 {
     B.MacroStatement macro = new B.MacroStatement(GetLexicalInfo(node));
     macro.Name = name;
     ConvertExpressions(arguments, macro.Arguments);
     if (embedded is BlockStatement)
     {
         macro.Body = ConvertBlock((BlockStatement)embedded);
     }
     else
     {
         macro.Body = new B.Block();
         macro.Body.Add((B.Statement)embedded.AcceptVisitor(this, null));
     }
     return(macro);
 }
Beispiel #8
0
        internal IList <ControlFlowNode> BuildControlFlowGraph(Statement statement, Func <AstNode, CancellationToken, ResolveResult> resolver, CSharpTypeResolveContext typeResolveContext, CancellationToken cancellationToken)
        {
            NodeCreationVisitor nodeCreationVisitor = new NodeCreationVisitor();

            nodeCreationVisitor.builder = this;
            try
            {
                this.nodes              = new List <ControlFlowNode>();
                this.labels             = new Dictionary <string, ControlFlowNode>();
                this.gotoStatements     = new List <ControlFlowNode>();
                this.rootStatement      = statement;
                this.resolver           = resolver;
                this.typeResolveContext = typeResolveContext;
                this.cancellationToken  = cancellationToken;

                ControlFlowNode entryPoint = CreateStartNode(statement);
                statement.AcceptVisitor(nodeCreationVisitor, entryPoint);

                // Resolve goto statements:
                foreach (ControlFlowNode gotoStmt in gotoStatements)
                {
                    string          label = ((GotoStatement)gotoStmt.NextStatement).Label;
                    ControlFlowNode labelNode;
                    if (labels.TryGetValue(label, out labelNode))
                    {
                        nodeCreationVisitor.Connect(gotoStmt, labelNode, ControlFlowEdgeType.Jump);
                    }
                }

                AnnotateLeaveEdgesWithTryFinallyBlocks();

                return(nodes);
            }
            finally
            {
                this.nodes              = null;
                this.labels             = null;
                this.gotoStatements     = null;
                this.rootStatement      = null;
                this.resolver           = null;
                this.typeResolveContext = null;
                this.cancellationToken  = CancellationToken.None;
            }
        }
Beispiel #9
0
		void WriteEmbeddedStatement(Statement embeddedStatement)
		{
			if (embeddedStatement.IsNull) {
				NewLine();
				return;
			}
			BlockStatement block = embeddedStatement as BlockStatement;
			if (block != null) {
				VisitBlockStatement(block);
			} else {
				NewLine();
				formatter.Indent();
				embeddedStatement.AcceptVisitor(this);
				formatter.Unindent();
			}
		}
		public JsBlockStatement Compile(Statement statement) {
			SetRegion(statement.GetRegion());
			try {
				_result = new List<JsStatement>();
				statement.AcceptVisitor(this);
				if (_result.Count == 1 && _result[0] is JsBlockStatement)
					return (JsBlockStatement)_result[0];
				else
					return JsStatement.Block(_result);
			}
			catch (Exception ex) {
				_errorReporter.InternalError(ex);
				return JsStatement.EmptyBlock;
			}
		}
		/// <summary>
		/// Writes an embedded statement.
		/// </summary>
		/// <param name="embeddedStatement">The statement to write.</param>
		/// <param name="nlp">Determines whether a trailing newline should be written following a block.
		/// Non-blocks always write a trailing newline.</param>
		/// <remarks>
		/// Blocks may or may not write a leading newline depending on StatementBraceStyle.
		/// Non-blocks always write a leading newline.
		/// </remarks>
		protected virtual void WriteEmbeddedStatement(Statement embeddedStatement, NewLinePlacement nlp = NewLinePlacement.NewLine)
		{
			if (embeddedStatement.IsNull) {
				NewLine();
				return;
			}
			BlockStatement block = embeddedStatement as BlockStatement;
			if (block != null) {
				WriteBlock(block, policy.StatementBraceStyle);
				if (nlp == NewLinePlacement.SameLine) {
					Space(); // if not a trailing newline, then at least a trailing space
				} else {
					NewLine();
				}
			} else {
				NewLine();
				writer.Indent();
				embeddedStatement.AcceptVisitor(this);
				writer.Unindent();
			}
		}
Beispiel #12
0
 private void WriteEmbeddedStatement(Statement statement)
 {
     var blockStatement = statement as BlockStatement;
     if (blockStatement != null)
     {
         VisitBlockStatement(blockStatement);
     }
     else
     {
         Formatter.WriteLine();
         Formatter.Indent();
         statement.AcceptVisitor(this);
         Formatter.Unindent();
     }
 }
 public JsBlockStatement Compile(Statement statement)
 {
     _filename = statement.GetRegion().FileName;
     try {
         _result = new List<JsStatement>();
         statement.AcceptVisitor(this);
         if (_result.Count == 1 && _result[0] is JsBlockStatement)
             return (JsBlockStatement)_result[0];
         else
             return new JsBlockStatement(_result);
     }
     catch (Exception ex) {
         _errorReporter.InternalError(ex, _filename, _location);
         return new JsBlockStatement();
     }
 }
Beispiel #14
0
 bool IsRecursive(Statement statement)
 {
     return(recursiveDetectorVisitor != null && statement.AcceptVisitor(recursiveDetectorVisitor));
 }
		B.MacroStatement CreateMacro(INode node, string name, Statement embedded, params Expression[] arguments)
		{
			B.MacroStatement macro = new B.MacroStatement(GetLexicalInfo(node));
			macro.Name = name;
			ConvertExpressions(arguments, macro.Arguments);
			if (embedded is BlockStatement) {
				macro.Body = ConvertBlock((BlockStatement)embedded);
			} else {
				macro.Body = new B.Block();
				macro.Body.Add((B.Statement)embedded.AcceptVisitor(this, null));
			}
			return macro;
		}