4 using System.Collections.Generic;
7 using System.Threading.Tasks;
9 using SiliconStudio.Shaders.Ast;
10 using SiliconStudio.Shaders.Parser;
11 using SiliconStudio.Shaders.Visitor;
13 namespace SiliconStudio.Shaders.Convertor
25 private string keyword;
30 private List<List<Statement>> scopeList =
new List<List<Statement>>();
35 private Stack<Statement> containerStack =
new Stack<Statement>();
37 public BreakContinueVisitor()
45 keyword = keywordName;
47 Visit(forStatement.
Body);
50 parserResult.CopyTo(logger);
52 if (parserResult.HasErrors)
55 TransformBreaks(breakFlag);
57 return scopeList.Count > 0;
65 var list =
new List<Statement>(containerStack);
68 list.Add(ParentNode as ExpressionStatement);
70 parserResult.Error(
"{0} keyword detected, but outside of an ExpressionStatement. It is impossible to unroll the loop", expression.Span, keyword);
79 containerStack.Push(blockStatement);
80 Visit((
Node)blockStatement);
93 containerStack.Push(statementList);
94 Visit((
Node)statementList);
101 containerStack.Push(ifStatement);
102 Visit((
Node)ifStatement);
103 containerStack.Pop();
110 protected void TransformBreaks(
Variable breakFlag)
114 foreach (var breakScope
in scopeList)
116 for (
int i = 0; i < breakScope.Count - 1; ++i)
118 var currentScope = breakScope[i];
119 var nextScope = breakScope[i+1];
123 var typedScope = currentScope as StatementList;
124 var index = typedScope.Statements.IndexOf(nextScope);
127 parserResult.Error(
"unable to find the next scope when replacing break/continue", nextScope.Span);
132 testBlock.Condition = breakTest;
133 var thenBlock =
new StatementList();
134 for (
int j = index + 1; j < typedScope.Statements.Count; ++j)
135 thenBlock.Add(typedScope.Statements[j]);
136 testBlock.Then = thenBlock;
138 typedScope.Statements.RemoveRange(index + 1, typedScope.Statements.Count - index - 1);
139 if (typedScope.Statements.Count > 0 && i != breakScope.Count - 2)
140 typedScope.Statements.Add(testBlock);
Statement Body
Gets or sets the body.
UnaryOperator
Unary operator used in all binary expressions (except assignment expression).
Keyword expression statement like continue; break; discard;
string Text
Gets or sets the name.
While and Do-While statement.
AssignmentOperator
Assignment operator used in assignment expression (a = b) or statements (a = b;)
Identifier Name
Gets or sets the name.
A reference to a variable.