public LuaElseClauseSyntax Transpile(JassElseClauseSyntax elseClause) { var luaElseClause = new LuaElseClauseSyntax(); luaElseClause.Body.Statements.AddRange(Transpile(elseClause.Body)); return(luaElseClause); }
internal void Render(LuaElseClauseSyntax node) { Write(node.ElseKeyword); node.Body.Render(this); }
private LuaTryAdapterExpressionSyntax VisitTryCatchesExpress(SyntaxList <CatchClauseSyntax> catches) { LuaTryAdapterExpressionSyntax functionExpress = new LuaTryAdapterExpressionSyntax(); PushFunction(functionExpress); var temp = GetTempIdentifier(catches.First()); functionExpress.CatchTemp = temp; functionExpress.AddParameter(temp); LuaIfStatementSyntax ifStatement = null; bool hasCatchRoot = false; foreach (var catchNode in catches) { bool isRootExceptionDeclaration = false; LuaExpressionSyntax ifCondition = null; if (catchNode.Filter != null) { ifCondition = (LuaExpressionSyntax)catchNode.Filter.Accept(this); } if (catchNode.Declaration != null) { var typeName = (LuaIdentifierNameSyntax)catchNode.Declaration.Type.Accept(this); if (typeName.ValueText != "System.Exception") { var mathcTypeInvocation = new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.Is, temp, typeName); if (ifCondition != null) { ifCondition = new LuaBinaryExpressionSyntax(ifCondition, LuaSyntaxNode.Tokens.And, mathcTypeInvocation); } else { ifCondition = mathcTypeInvocation; } } else { if (!catchNode.Declaration.Identifier.IsKind(SyntaxKind.None)) { isRootExceptionDeclaration = true; } hasCatchRoot = true; } } else { hasCatchRoot = true; } var block = (LuaBlockSyntax)catchNode.Block.Accept(this); if (ifCondition != null) { LuaBlockSyntax body; if (ifStatement == null) { ifStatement = new LuaIfStatementSyntax(ifCondition); body = ifStatement.Body; } else { LuaElseIfStatementSyntax elseIfStatement = new LuaElseIfStatementSyntax(ifCondition); body = elseIfStatement.Body; ifStatement.ElseIfStatements.Add(elseIfStatement); } if (catchNode.Declaration != null && !catchNode.Declaration.Identifier.IsKind(SyntaxKind.None)) { var variableDeclarator = (LuaVariableDeclaratorSyntax)catchNode.Declaration.Accept(this); variableDeclarator.Initializer = new LuaEqualsValueClauseSyntax(temp); body.Statements.Add(new LuaLocalVariableDeclaratorSyntax(variableDeclarator)); } body.Statements.AddRange(block.Statements); } else { if (isRootExceptionDeclaration) { var variableDeclarator = (LuaVariableDeclaratorSyntax)catchNode.Declaration.Accept(this); variableDeclarator.Initializer = new LuaEqualsValueClauseSyntax(temp); block.Statements.Insert(0, new LuaLocalVariableDeclaratorSyntax(variableDeclarator)); } if (ifStatement != null) { LuaElseClauseSyntax elseClause = new LuaElseClauseSyntax(); elseClause.Body.Statements.AddRange(block.Statements); ifStatement.Else = elseClause; } else { functionExpress.AddStatements(block.Statements); } break; } } if (ifStatement != null) { if (!hasCatchRoot) { Contract.Assert(ifStatement.Else == null); LuaMultipleReturnStatementSyntax rethrowStatement = new LuaMultipleReturnStatementSyntax(); rethrowStatement.Expressions.Add(LuaIdentifierNameSyntax.One); rethrowStatement.Expressions.Add(temp); LuaBlockSyntax block = new LuaBlockSyntax(); block.Statements.Add(rethrowStatement); LuaElseClauseSyntax elseClause = new LuaElseClauseSyntax(); elseClause.Body.Statements.AddRange(block.Statements); ifStatement.Else = elseClause; } functionExpress.AddStatement(ifStatement); } PopFunction(); return(functionExpress); }