public override void VisitUsingStatement(IUsingStatement operation) { LogString(nameof(IUsingStatement)); LogCommonPropertiesAndNewLine(operation); base.VisitUsingStatement(operation); }
public virtual void VisitUsingStatement(IUsingStatement value) { //TODO: remove //this.VisitExpression(value.Variable); VisitExpression(value.Expression); VisitStatement(value.Body); }
public override void VisitUsingStatement <TExpression, TStatement>(IUsingStatement <TExpression, TStatement> usingStatement) { Value = new Statement() { UsingStatement = new UsingStatementFactory(usingStatement).Value }; }
/// <inheritdoc /> public override Expression VisitUsingStatement(IUsingStatement operation, LocalBinder argument) { // TODO: Declarations in new binder return(Expressive.Using( Visit(operation.Declaration ?? operation.Value, argument), operation.Body.Accept(this, argument) )); }
public static void VisitUsingStatementChildren <TExpression, TStatement>( IUsingStatement <TExpression, TStatement> usingStatement, IGenericStatementVisitor visitor) where TExpression : IExpression where TStatement : IStatement { VisitIfNotNull(usingStatement.Statement, visitor); }
public override void VisitUsingStatement <TExpression, TStatement>(IUsingStatement <TExpression, TStatement> usingStatement) { Steps.Add(new WriteUsingKeyword()); Steps.Add(new WriteWhitespace()); Steps.Add(new WriteStartParenthesis()); Steps.Add(new WriteExpression <TExpression>(usingStatement.Expression)); Steps.Add(new WriteEndParenthesis()); Steps.AddIndentedStatementSteps(usingStatement.Statement); }
public override void VisitUsingStatement(IUsingStatement operation) { LogString(nameof(IUsingStatement)); LogCommonPropertiesAndNewLine(operation); Visit(operation.Declaration, "Declaration"); Visit(operation.Value, "Value"); Visit(operation.Body, "Body"); }
public NamespaceContext GetChildContext(string name, IUsingStatement[] @using) { string newName = (Name != null ? Name + "." : "") + name; IUsingStatement[] statements = new IUsingStatement[UsingStatements.Length + @using.Length]; Array.Copy(UsingStatements, 0, statements, 0, UsingStatements.Length); Array.Copy(@using, 0, statements, UsingStatements.Length, @using.Length); return(new NamespaceContext(newName, statements)); }
public override bool Equals(object obj) { if (this == obj) { return(true); } IUsingStatement statement = obj as IUsingStatement; if (statement == null) { return(false); } return (this.Body.Equals(statement.Body) && this.Expression.Equals(statement.Expression)); }
public override void VisitUsingStatement(IUsingStatement block, IList <IStatement> body) { AddIf(block, CompletionCase.EmptyCompletionBefore, body); var usingBlock = new UsingBlock(); IVariableReference varRef = new VariableReference(); // case 1: variable declarations if (block.VariableDeclarations.Any()) { var decl = block.VariableDeclarations[0]; decl.Accept(this, body); varRef = new VariableReference { Identifier = decl.DeclaredName }; } // case 2: expressions (var refs, method calls ...) else if (block.Expressions.Any()) { var expr = block.Expressions[0]; varRef = _exprVisitor.ToVariableRef(expr, body); } usingBlock.Reference = varRef; var bodyAsIBlock = block.Body as IBlock; if (bodyAsIBlock != null && !bodyAsIBlock.Statements.Any() && IsTargetMatch(block, CompletionCase.InBody)) { usingBlock.Body.Add(new ExpressionStatement { Expression = new CompletionExpression() }); } else { block.Body.Accept(this, usingBlock.Body); } body.Add(usingBlock); AddIf(block, CompletionCase.EmptyCompletionAfter, body); }
public UsingStatementCompiler(IUsingStatement usingStatement, AbstractILCompilerParams @params) : base(@params) { myUsingStatement = usingStatement; }
public override void VisitUsingStatement([NotNull] IUsingStatement operation) { IncrementStatementCount(operation); base.VisitUsingStatement(operation); }
/// <inheritdoc /> public override IOperation VisitUsingStatement(IUsingStatement operation, object argument) { return(base.VisitUsingStatement(operation, argument)); }
public override Location VisitUsingStatement([NotNull] IUsingStatement operation, [CanBeNull] object argument) { var syntax = (UsingStatementSyntax)operation.Syntax; return(syntax.UsingKeyword.GetLocation()); }
public virtual void VisitUsingStatement(IUsingStatement operation) { DefaultVisit(operation); }
public override void VisitUsingStatement(IUsingStatement value) { WriteUnsupported(value); }
public override IOperation VisitUsingStatement(IUsingStatement operation, object argument) { return(new UsingStatement(Visit(operation.Body), Visit(operation.Declaration), Visit(operation.Value), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit)); }
public virtual void VisitUsingStatement(IUsingStatement value) { this.VisitExpression(value.Expression); this.VisitStatement(value.Body); }
private void WriteUsingStatement(IUsingStatement statement, IFormatter formatter) { IVariableReference variable = null; IAssignExpression assignExpression = statement.Expression as IAssignExpression; if (assignExpression != null) { IVariableDeclarationExpression variableDeclarationExpression = assignExpression.Target as IVariableDeclarationExpression; if (variableDeclarationExpression != null) { variable = variableDeclarationExpression.Variable; } IVariableReferenceExpression variableReferenceExpression = assignExpression.Target as IVariableReferenceExpression; if (variableReferenceExpression != null) { variable = variableReferenceExpression.Variable; } } this.WriteStatementSeparator(formatter); // make a comment that Reflector detected this as a using statement //formatter.Write("{using"); if (variable != null) { //formatter.Write(" "); this.WriteVariableReference(variable, formatter); } formatter.Write("}"); formatter.WriteLine(); // and replace this with // - create obj // - try ... finally obj.Dispose end formatter.WriteKeyword("begin"); formatter.WriteLine(); formatter.WriteIndent(); if (variable != null) { this.WriteVariableReference(variable, formatter); formatter.Write(" "); formatter.WriteKeyword(":="); formatter.Write(" "); this.WriteExpression(assignExpression.Expression, formatter); this.WriteStatementSeparator(formatter); } formatter.WriteKeyword("try"); formatter.WriteLine(); formatter.WriteIndent(); if (statement.Body != null) { this.WriteBlockStatement(statement.Body, formatter); } formatter.WriteLine(); formatter.WriteOutdent(); formatter.WriteKeyword("finally"); formatter.WriteLine(); formatter.WriteIndent(); if (variable != null) { this.firstStmt = true; this.WriteVariableReference(variable, formatter); formatter.Write("."); formatter.Write("Dispose"); formatter.WriteLine(); } else { this.firstStmt = true; this.WriteExpression(statement.Expression); formatter.Write("."); formatter.Write("Dispose"); formatter.WriteLine(); } formatter.WriteOutdent(); formatter.WriteKeyword("end"); formatter.WriteLine(); formatter.WriteOutdent(); formatter.WriteKeyword("end"); }
public override void VisitUsingStatement(IUsingStatement operation) { base.VisitUsingStatement(operation); }
public static IUsingStatement Update(this IUsingStatement self, ImmutableArray <ISymbol> @locals, IVariableDeclarationStatement @declarationsOpt, IOperation @expressionOpt, Conversion @iDisposableConversion, IOperation @body) => self;
public static Gen::IEnumerable <IStatement> ModifyStatements(IStatementCollection collection) { #if YIELD_LIST Gen::List <IStatement> yields = new System.Collections.Generic.List <IStatement>(); #endif for (int i = 0, iM = collection.Count; i < iM; i++) { IStatement s = collection[i]; ILabeledStatement state_labeled = s as ILabeledStatement; if (state_labeled != null) { #if YIELD_LIST yields.Add(new LabelStatement(state_labeled.Name)); #else yield return(new LabelStatement(state_labeled.Name)); #endif s = state_labeled.Statement; if (s == null) { continue; } goto next; } // // TryCatch から // ITryCatchFinallyStatement state_tcf = s as ITryCatchFinallyStatement; if (state_tcf != null) { ModifyCatchClauses(state_tcf); goto next; } // // IUsingStatement → LocalRefVariableStatement 書き込み // IUsingStatement state_using = s as IUsingStatement; if (state_using != null) { TransformUsingStatement(yields, state_using, i + 1 == iM); continue; } // // 代入部分から構文合致を始める場合 // IAssignExpression exp_assign = GetAssignExpression(s); if (exp_assign != null) { IVariableDeclaration var = GetVariable(exp_assign.Target); if (var == null) { goto next; } TypeRef type = new TypeRef(var.VariableType); // // Detect 'default construction of value class' // //----------------------------------------------- // Value value; // default constructor is called //----------------------------------------------- /* * if(type.IsValueType){ * IObjectCreateExpression exp_create=exp_assign.Expression as IObjectCreateExpression; * if(exp_create!=null&&exp_create.Constructor==null){ #if YIELD_LIST * yields.Add(new DefaultConstructionStatement(exp_create.Type,var.Name)); #else * yield return new DefaultConstructionStatement(exp_create.Type,var.Name); #endif * continue; * } * } * //*/ // // Detect 'delete' // //----------------------------------------------- // IDisposable^ disposable= <expression> ; // if(disposable!=nullptr)disposable->Dispose(); //----------------------------------------------- if (i + 1 < iM && type.IsType("System", "IDisposable") && DetectDeleteStatement(var.Name, collection[i + 1])) { i++; #if YIELD_LIST yields.Add(new DeleteStatement(exp_assign.Expression)); #else yield return(new DeleteStatement(exp_assign.Expression)); #endif continue; } // // Detect 'local ref value instance' // //----------------------------------------------- // Class value= <expression> ; // try{ // disposable=value; // ... // }... // disposable->Dispose(); //----------------------------------------------- LocalRefVariableStatement yret_lrv; if (i + 2 < iM && DetectLocalRefVariable(var.Name, collection[i + 1], collection[i + 2], out yret_lrv)) { i += 2; yret_lrv.var_type = var.VariableType; yret_lrv.exp = exp_assign.Expression; #if YIELD_LIST #warning local-ref: 更に上層でも削除しなければならない可能性がある RemoveNullDeclaration(yret_lrv.var_name, yields); yields.Add(yret_lrv); #else yield return(yret_lrv); #endif continue; } goto next; } next: #if YIELD_LIST yields.Add(s); #else yield return(s); #endif } #if YIELD_LIST return(yields); #endif }
public override void VisitUsingStatement([NotNull] IUsingStatement operation) { Visit(operation.Declaration); Visit(operation.Value); }
//=========================================================== // using の変換 //=========================================================== /// <summary> /// Using 文を他の構文に変換して、yields に変換後の Statement を書き込みます。 /// </summary> /// <param name="yields">変換後の Statement の書き込み先を指定します。</param> /// <param name="state">using 構文を表現する Statement を指定します。</param> /// <param name="last">state が Statements の中で最後の Statement か否かを指定します。</param> public static void TransformUsingStatement(Gen::List <IStatement> yields, IUsingStatement state, bool last) { // 変数の宣言の場合 IAssignExpression assig = state.Expression as IAssignExpression; if (assig != null) { do { IVariableDeclarationExpression var_decl_x = assig.Target as IVariableDeclarationExpression; if (var_decl_x == null) { continue; } IVariableDeclaration var_decl = var_decl_x.Variable as IVariableDeclaration; if (var_decl == null) { continue; } IObjectCreateExpression exp_create = assig.Expression as IObjectCreateExpression; if (exp_create != null) { LocalRefVariableStatement s_lr = new LocalRefVariableStatement(var_decl, assig.Expression, state.Body); s_lr.noblock = last; yields.Add(s_lr); } else { //yields.Add(new ExpressionStatement(assig)); //yields.Add(state.Body); //yields.Add(new DeleteStatement(new VariableReferenceExpression(var_decl))); //↑ 中で例外が起こったときのことを考えていない。 // 宣言部分と代入部分を分離 IStatement s_decl = new ExpressionStatement(var_decl_x); IStatement s_asgn = new ExpressionStatement( new AssignExpression( new VariableReferenceExpression(var_decl), assig.Expression ) ); IStatement s_delete = new DeleteStatement(new VariableReferenceExpression(var_decl)); // 宣言 yields.Add(s_decl); // try-finally BlockStatement try_block = new BlockStatement(); try_block.Statements.Add(s_asgn); try_block.Statements.AddRange(state.Body.Statements); BlockStatement finally_block = new BlockStatement(); finally_block.Statements.Add(s_delete); TryCatchFinallyStatement s_tcf = new TryCatchFinallyStatement(try_block); s_tcf.Finally = finally_block; yields.Add(s_tcf); } return; }while(false); throw new InterfaceNotImplementedException("×実装中×", typeof(IVariableDeclarationExpression), assig.Target); } // 変数の参照の場合 IVariableReferenceExpression varref = state.Expression as IVariableReferenceExpression; if (varref != null) { IStatement s_delete = new DeleteStatement(varref); // try-finally TryCatchFinallyStatement s_tcf = new TryCatchFinallyStatement(state.Body); BlockStatement finally_block = new BlockStatement(); finally_block.Statements.Add(s_delete); s_tcf.Finally = finally_block; yields.Add(s_tcf); return; } throw new InterfaceNotImplementedException( "Unexpected using-statement expression interface (expects IAssignExpression or IVariableReferenceExpression)", typeof(IAssignExpression), state.Expression); }
public override void VisitUsingStatement(IUsingStatement operation) { Visit(operation.Declaration); Visit(operation.Value); Visit(operation.Body); }
public virtual void VisitUsingStatement(IUsingStatement value) { VisitExpression(value.Expression); VisitStatement(value.Body); }
public virtual void VisitUsingStatement <TExpression, TStatement>(IUsingStatement <TExpression, TStatement> usingStatement) where TExpression : IExpression where TStatement : IStatement { Visit(usingStatement); }
public virtual IStatement TransformUsingStatement(IUsingStatement value) { value.Expression = this.TransformExpression(value.Expression); value.Body = (IBlockStatement)this.TransformStatement(value.Body); return value; }