//do-while文 public override bool Visit(UnifiedDoWhile element, VisitorArgument arg) { Writer.Write("do"); element.Body.TryAccept(this, arg.Set(ForBlock)); Writer.Write("while("); element.Condition.TryAccept(this, arg.Set(CommaDelimiter)); Writer.Write(");"); //TODO なぜここでセミコロンを打つのか確認 return(false); }
//while文 public override bool Visit(UnifiedWhile element, VisitorArgument arg) { Writer.Write("while("); element.Condition.TryAccept(this, arg.Set(CommaDelimiter)); Writer.Write(")"); element.Body.TryAccept(this, arg.Set(ForBlock)); return(false); }
public override bool Visit(UnifiedNew element, VisitorArgument arg) { Writer.Write("new "); element.GenericArguments.TryAccept(this, arg); element.Target.TryAccept(this, arg); element.Arguments.TryAccept(this, arg.Set(Paren)); element.InitialValue.TryAccept(this, arg.Set(Brace)); element.Body.TryAccept(this, arg); return(false); }
public override bool Visit(UnifiedIf ifStatement, VisitorArgument arg) { Writer.Write("if ("); ifStatement.Condition.TryAccept(this, arg); Writer.Write(")"); ifStatement.Body.TryAccept(this, arg.Set(ForBlock)); ifStatement.ElseBody.TryAccept( this, arg.Set(ForBlock), GetIndent(arg) + "else"); return(false); }
public override bool Visit(UnifiedFor element, VisitorArgument arg) { element.Initializer.TryAccept(this, arg.Set(CommaDelimiter)); Writer.Write("while "); element.Condition.TryAccept(this, arg); Writer.WriteLine(":"); arg = arg.IncrementDepth(); element.Body.TryAccept(this, arg); WriteIndent(arg.IndentDepth); element.Step.TryAccept(this, arg.Set(SemiColonDelimiter)); return(false); }
public override bool Visit(UnifiedForeach element, VisitorArgument arg) { Writer.Write(ForeachKeyword); Writer.Write("("); element.Element.TryAccept(this, arg); Writer.Write(ForeachDelimiter); element.Set.TryAccept(this, arg.Set(CommaDelimiter)); Writer.Write(")"); element.Body.TryAccept(this, arg.Set(ForBlock)); return(false); }
public override bool Visit(UnifiedFor element, VisitorArgument arg) { Writer.Write("for("); element.Initializer.TryAccept(this, arg.Set(CommaDelimiter)); Writer.Write("; "); element.Condition.TryAccept(this, arg.Set(CommaDelimiter)); Writer.Write(";"); element.Step.TryAccept(this, arg.Set(CommaDelimiter)); Writer.Write(")"); element.Body.TryAccept(this, arg.Set(ForBlock)); return(false); }
protected bool Visit( UnifiedClassLikeDefinition element, VisitorArgument arg, string keyword) { element.Annotations.TryAccept(this, arg); element.Modifiers.TryAccept(this, arg); Writer.Write(keyword + " "); element.Name.TryAccept(this, arg); element.GenericParameters.TryAccept(this, arg); element.Constrains.TryAccept(this, arg.Set(CommaDelimiter)); element.Body.TryAccept(this, arg.Set(ForBlock)); return(false); }
//if文 public override bool Visit(UnifiedIf ifStatement, VisitorArgument arg) { Writer.Write("if ("); ifStatement.Condition.TryAccept(this, arg.Set(CommaDelimiter)); Writer.Write(")"); ifStatement.Body.TryAccept(this, arg.Set(ForBlock)); if (ifStatement.ElseBody != null) { WriteIndent(arg.IndentDepth); Writer.WriteLine("else"); ifStatement.ElseBody.TryAccept(this, arg.Set(ForBlock)); } return(false); }
//配列orオブジェクトのインスタンス化式 public override bool Visit(UnifiedNew element, VisitorArgument arg) { //配列 : e.g. var a = [1, 2, 3] の [1, 2, 3]; if (element.InitialValue != null) { element.InitialValue.TryAccept(this, arg.Set(Brace)); return(true); } //オブジェクト : e.g. var a = new X(); Writer.Write("new "); element.Target.TryAccept(this, arg); element.Arguments.TryAccept(this, arg.Set(Paren)); return(true); }
public override bool Visit( UnifiedBinaryExpression element, VisitorArgument arg) { var paren = GetRequiredParen(element); Writer.Write(paren.Item1); element.LeftHandSide.TryAccept(this, arg.Set(Paren)); Writer.Write(" "); element.Operator.TryAccept(this, arg); Writer.Write(" "); element.RightHandSide.TryAccept(this, arg.Set(Paren)); Writer.Write(paren.Item2); return(false); }
public override bool Visit( UnifiedTernaryExpression element, VisitorArgument arg) { var paren = GetRequiredParen(element); Writer.Write(paren.Item1); element.Condition.TryAccept(this, arg.Set(Paren)); Writer.Write(" ? "); element.TrueExpression.TryAccept(this, arg.Set(Paren)); Writer.Write(" : "); element.FalseExpression.TryAccept(this, arg.Set(Paren)); Writer.Write(paren.Item2); return(false); }
public override bool Visit( UnifiedVariableDefinitionList element, VisitorArgument arg) { var klass = element.GrandParent() as UnifiedEnumDefinition; if (klass != null) { VisitCollection(element, arg.Set(CommaDelimiter)); } else { VisitCollection(element, arg.Set(SemiColonDelimiter)); } return(true); }
public override bool Visit( UnifiedGenericParameter element, VisitorArgument arg) { element.Type.TryAccept(this, arg); element.Constrains.TryAccept(this, arg.Set(AndDelimiter)); return(false); }
//変数宣言リスト : e.g. var a = 1, b = 2; public override bool Visit( UnifiedVariableDefinitionList element, VisitorArgument arg) { //for文の初期条件内では変数宣言を分解して出力できないため、 //あらかじめ'var'を出力しておいて各UnifiedVariableDefinitionでは'var'を出力しない if (element.Parent.GetType() == typeof(UnifiedFor)) { Writer.Write("var "); VisitCollection(element, arg.Set(CommaDelimiter)); } else { VisitCollection(element, arg.Set(SemiColonDelimiter)); } return(true); }
public override bool Visit(UnifiedAssert element, VisitorArgument arg) { Writer.Write("assert "); element.Value.TryAccept(this, arg); element.Message.TryAccept(this, arg.Set(CommaMostLeft)); return(true); }
public override bool Visit( UnifiedStaticInitializer element, VisitorArgument arg) { Writer.Write("static "); element.Body.TryAccept(this, arg.Set(ForBlock)); return(false); }
public override bool Visit( UnifiedGenericArgument element, VisitorArgument arg) { element.Modifiers.TryAccept(this, arg); element.Value.TryAccept(this, arg); element.Constrains.TryAccept(this, arg.Set(AndDelimiter)); return(false); }
// e.g. (Int)a or (int)(a + b) public override bool Visit(UnifiedCast element, VisitorArgument arg) { Writer.Write("("); element.Type.TryAccept(this, arg); Writer.Write(")"); element.Expression.TryAccept(this, arg.Set(Paren)); return(false); }
//with文 public override bool Visit(UnifiedWith element, VisitorArgument arg) { Writer.Write("with ("); element.Value.TryAccept(this, arg); Writer.Write(")"); element.Body.TryAccept(this, arg.Set(ForBlock)); return(false); }
// e.g. try{...}catch(E e){...}finally{...} public override bool Visit(UnifiedTry element, VisitorArgument arg) { Writer.Write("try"); element.Body.TryAccept(this, arg.Set(ForBlock)); element.Catches.TryAccept(this, arg); element.FinallyBody.TryAccept(this, arg, "finally"); return(false); }
public override bool Visit( UnifiedAnnotation element, VisitorArgument arg) { Writer.Write("@"); element.Name.TryAccept(this, arg); element.Arguments.TryAccept(this, arg.Set(Paren)); Writer.WriteLine(); return(false); }
public override bool Visit( UnifiedUnaryExpression element, VisitorArgument arg) { if (element.Operator.Kind == UnifiedUnaryOperatorKind.PostIncrementAssign || element.Operator.Kind == UnifiedUnaryOperatorKind.PostDecrementAssign) { element.Operand.TryAccept(this, arg.Set(Paren)); element.Operator.TryAccept(this, arg); } else { element.Operator.TryAccept(this, arg); element.Operand.TryAccept(this, arg.Set(Paren)); } return(false); }
public override bool Visit( UnifiedVariableDefinition element, VisitorArgument arg) { element.Annotations.TryAccept(this, arg); element.Modifiers.TryAccept(this, arg); Writer.Write(" "); element.Type.TryAccept(this, arg); Writer.Write(" "); element.Name.TryAccept(this, arg); if (element.InitialValue != null) { Writer.Write(" = "); element.InitialValue.TryAccept(this, arg.Set(Brace)); } element.Arguments.TryAccept(this, arg.Set(Paren)); element.Body.TryAccept(this, arg); return(false); }
public override bool Visit( UnifiedArrayType element, VisitorArgument arg) { element.Type.TryAccept(this, arg); Writer.Write("["); element.Arguments.TryAccept(this, arg.Set(CommaDelimiter)); Writer.Write("]"); return(false); }
public override bool Visit( UnifiedVariableDefinition element, VisitorArgument arg) { //for文の場合'var'は1つしか記述できないため、UnifiedVariableDefinitionListで'var'を出力済み if (arg.Decoration.Delimiter != ", ") { Writer.Write("var "); } element.Name.TryAccept(this, arg); if (element.InitialValue != null) { Writer.Write(" = "); element.InitialValue.TryAccept(this, arg.Set(Brace)); } element.Arguments.TryAccept(this, arg.Set(Paren)); element.Body.TryAccept(this, arg.Set(ForBlock)); return(false); }
// e.g. Foo<T1, T2> where T1 : string public override bool Visit( UnifiedSet <UnifiedGenericParameter> element, VisitorArgument arg) { VisitCollection(element, arg.Set(InequalitySignParen)); foreach (var genericParameter in element) { if (genericParameter.Constrains != null) { foreach (var constrain in genericParameter.Constrains) { Writer.Write(" where "); genericParameter.Type.TryAccept(this, arg); constrain.TryAccept(this, arg.Set(ColonDelimiter)); } } } return(false); }
//キャスト式 public override bool Visit(UnifiedCast element, VisitorArgument arg) { Writer.Write("("); element.Type.TryAccept(this, arg); Writer.Write(")"); //TODO ここのarg.Set(Paren)が不要な気がするので、後ではずしてテストしてみる element.Expression.TryAccept(this, arg.Set(Paren)); return(true); }
//TODO 辞書リテラル : JavaScriptでは出現しない? public override bool Visit( UnifiedMapLiteral element, VisitorArgument arg) { Writer.Write("{"); VisitCollection(element, arg.Set(CommaDelimiter)); WriteIndent(arg.IndentDepth); Writer.Write("}"); return(false); }
public override bool Visit(UnifiedDoWhile element, VisitorArgument arg) { Writer.Write("do"); element.Body.TryAccept(this, arg.Set(ForBlock)); WriteIndent(arg); Writer.Write("while("); element.Condition.TryAccept(this, arg); Writer.Write(");"); return(false); }