示例#1
0
		private Node TransformTry(TryStatement node)
		{
			decompiler.AddToken(Token.TRY);
			decompiler.AddEOL(Token.LC);
			Node tryBlock = Transform(node.GetTryBlock());
			decompiler.AddEOL(Token.RC);
			Node catchBlocks = new Block();
			foreach (CatchClause cc in node.GetCatchClauses())
			{
				decompiler.AddToken(Token.CATCH);
				decompiler.AddToken(Token.LP);
				string varName = cc.GetVarName().GetIdentifier();
				decompiler.AddName(varName);
				Node catchCond = null;
				AstNode ccc = cc.GetCatchCondition();
				if (ccc != null)
				{
					decompiler.AddName(" ");
					decompiler.AddToken(Token.IF);
					catchCond = Transform(ccc);
				}
				else
				{
					catchCond = new EmptyExpression();
				}
				decompiler.AddToken(Token.RP);
				decompiler.AddEOL(Token.LC);
				Node body = Transform(cc.GetBody());
				decompiler.AddEOL(Token.RC);
				catchBlocks.AddChildToBack(CreateCatch(varName, catchCond, body, cc.GetLineno()));
			}
			Node finallyBlock = null;
			if (node.GetFinallyBlock() != null)
			{
				decompiler.AddToken(Token.FINALLY);
				decompiler.AddEOL(Token.LC);
				finallyBlock = Transform(node.GetFinallyBlock());
				decompiler.AddEOL(Token.RC);
			}
			return CreateTryCatchFinally(tryBlock, catchBlocks, finallyBlock, node.GetLineno());
		}
示例#2
0
		private Node TransformSwitch(SwitchStatement node)
		{
			// The switch will be rewritten from:
			//
			// switch (expr) {
			//   case test1: statements1;
			//   ...
			//   default: statementsDefault;
			//   ...
			//   case testN: statementsN;
			// }
			//
			// to:
			//
			// {
			//     switch (expr) {
			//       case test1: goto label1;
			//       ...
			//       case testN: goto labelN;
			//     }
			//     goto labelDefault;
			//   label1:
			//     statements1;
			//   ...
			//   labelDefault:
			//     statementsDefault;
			//   ...
			//   labelN:
			//     statementsN;
			//   breakLabel:
			// }
			//
			// where inside switch each "break;" without label will be replaced
			// by "goto breakLabel".
			//
			// If the original switch does not have the default label, then
			// after the switch he transformed code would contain this goto:
			//     goto breakLabel;
			// instead of:
			//     goto labelDefault;
			decompiler.AddToken(Token.SWITCH);
			decompiler.AddToken(Token.LP);
			Node switchExpr = Transform(node.GetExpression());
			decompiler.AddToken(Token.RP);
			node.AddChildToBack(switchExpr);
			Node block = new Node(Token.BLOCK, node, node.GetLineno());
			decompiler.AddEOL(Token.LC);
			foreach (SwitchCase sc in node.GetCases())
			{
				AstNode expr = sc.GetExpression();
				Node caseExpr = null;
				if (expr != null)
				{
					decompiler.AddToken(Token.CASE);
					caseExpr = Transform(expr);
				}
				else
				{
					decompiler.AddToken(Token.DEFAULT);
				}
				decompiler.AddEOL(Token.COLON);
				IList<AstNode> stmts = sc.GetStatements();
				Node body = new Block();
				if (stmts != null)
				{
					foreach (AstNode kid in stmts)
					{
						body.AddChildToBack(Transform(kid));
					}
				}
				AddSwitchCase(block, caseExpr, body);
			}
			decompiler.AddEOL(Token.RC);
			CloseSwitch(block);
			return block;
		}