Exemplo n.º 1
0
		public virtual object VisitUsingStatement(UsingStatement usingStatement, object data) {
			Debug.Assert((usingStatement != null));
			Debug.Assert((usingStatement.ResourceAcquisition != null));
			Debug.Assert((usingStatement.EmbeddedStatement != null));
			usingStatement.ResourceAcquisition.AcceptVisitor(this, data);
			return usingStatement.EmbeddedStatement.AcceptVisitor(this, data);
		}
Exemplo n.º 2
0
		public virtual object VisitUsingStatement(UsingStatement usingStatement, object data) {
			Debug.Assert((usingStatement != null));
			Debug.Assert((usingStatement.ResourceAcquisition != null));
			Debug.Assert((usingStatement.EmbeddedStatement != null));
			nodeStack.Push(usingStatement.ResourceAcquisition);
			usingStatement.ResourceAcquisition.AcceptVisitor(this, data);
			usingStatement.ResourceAcquisition = ((Statement)(nodeStack.Pop()));
			nodeStack.Push(usingStatement.EmbeddedStatement);
			usingStatement.EmbeddedStatement.AcceptVisitor(this, data);
			usingStatement.EmbeddedStatement = ((Statement)(nodeStack.Pop()));
			return null;
		}
		public virtual object VisitUsingStatement(UsingStatement usingStatement, object data) {
			throw new global::System.NotImplementedException("UsingStatement");
		}
Exemplo n.º 4
0
	void UsingStatement(out Statement statement) {
		Expression expr = null; Statement block; statement = null;
		Expect(226);
		if (Peek(1).kind == Tokens.As) {
			LocalVariableDeclaration resourceAquisition = 
			new LocalVariableDeclaration(Modifiers.None);
			VariableDeclarator(resourceAquisition.Variables);
			while (la.kind == 22) {
				Get();
				VariableDeclarator(resourceAquisition.Variables);
			}
			EndOfStmt();
			Block(out block);
			statement = new UsingStatement(resourceAquisition, block);
		} else if (StartOf(24)) {
			Expr(out expr);
			EndOfStmt();
			Block(out block);
			statement = new UsingStatement(new ExpressionStatement(expr), block);
		} else SynErr(313);
		Expect(113);
		Expect(226);
	}
Exemplo n.º 5
0
		public override object VisitUsingStatement(UsingStatement usingStatement, object data)
		{
			// uses LocalVariableDeclaration, we just have to put the end location on the stack
			if (usingStatement.EmbeddedStatement.EndLocation.IsEmpty) {
				return base.VisitUsingStatement(usingStatement, data);
			} else {
				endLocationStack.Push(usingStatement.EmbeddedStatement.EndLocation);
				base.VisitUsingStatement(usingStatement, data);
				endLocationStack.Pop();
				return null;
			}
		}
Exemplo n.º 6
0
		public sealed override object VisitUsingStatement(UsingStatement usingStatement, object data) {
			this.BeginVisit(usingStatement);
			object result = this.TrackedVisitUsingStatement(usingStatement, data);
			this.EndVisit(usingStatement);
			return result;
		}
Exemplo n.º 7
0
		public virtual object TrackedVisitUsingStatement(UsingStatement usingStatement, object data) {
			return base.VisitUsingStatement(usingStatement, data);
		}
Exemplo n.º 8
0
		public override object VisitUsingStatement(UsingStatement usingStatement, object data)
		{
			// using (new expr) { stmts; }
			//
			// emulate with
			//      object _dispose;
			//      try
			//      {
			//          _dispose = new expr;
			//
			//          stmts;
			//      }
			//      finally
			//      {
			//          if (((_dispose != null)
			//              && (typeof(System.IDisposable).IsInstanceOfType(_dispose) == true)))
			//          {
			//              ((System.IDisposable)(_dispose)).Dispose();
			//          }
			//      }
			//

			usingId++; // in case nested using() statements
			string name = "_dispose" + usingId.ToString();

			CodeVariableDeclarationStatement disposable = new CodeVariableDeclarationStatement("System.Object", name, new CodePrimitiveExpression(null));

			AddStmt(disposable);

			CodeTryCatchFinallyStatement tryStmt = new CodeTryCatchFinallyStatement();

			CodeVariableReferenceExpression left1 = new CodeVariableReferenceExpression(name);

			codeStack.Push(NullStmtCollection); // send statements to nul Statement collection
			CodeExpression right1 = (CodeExpression)usingStatement.ResourceAcquisition.AcceptVisitor(this, data);
			codeStack.Pop();

			CodeAssignStatement assign1 = new CodeAssignStatement(left1, right1);

			tryStmt.TryStatements.Add(assign1);
			tryStmt.TryStatements.Add(new CodeSnippetStatement());

			codeStack.Push(tryStmt.TryStatements);
			usingStatement.EmbeddedStatement.AcceptChildren(this, data);
			codeStack.Pop();

			CodeMethodInvokeExpression isInstanceOfType = new CodeMethodInvokeExpression(new CodeTypeOfExpression(typeof(IDisposable)), "IsInstanceOfType", new CodeExpression[] { left1 });

			CodeConditionStatement if1 = new CodeConditionStatement();
			if1.Condition = new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(left1, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)),
			                                                 CodeBinaryOperatorType.BooleanAnd,
			                                                 new CodeBinaryOperatorExpression(isInstanceOfType, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(true)));
			if1.TrueStatements.Add(new CodeMethodInvokeExpression(new CodeCastExpression(typeof(IDisposable),left1), "Dispose", new CodeExpression[] { }));

			tryStmt.FinallyStatements.Add(if1);

			// Add Statement to Current Statement Collection
			AddStmt(tryStmt);

			return null;
		}