public override void VisitUsingStatement(UsingStatement usingStatement) { inUsingStatementResourceAcquisition = true; usingStatement.ResourceAcquisition.AcceptVisitor (this); inUsingStatementResourceAcquisition = false; usingStatement.EmbeddedStatement.AcceptVisitor (this); }
public JNode VisitUsingStatement(UsingStatement node) { var st3 = Visit(node.ResourceAcquisition); JVariableDeclarationStatement stVar; if (st3 is JExpression) { stVar = J.Var("$r" + VariableResourceCounter++, node.Resolve().Type.JAccess(), (JExpression)st3).Statement(); } else { stVar = (JVariableDeclarationStatement)st3; } var trySt = VisitStatement(node.EmbeddedStatement); var st2 = new JTryStatement { TryBlock = trySt.ToBlock(), FinallyBlock = J.Block() }; //var resource = node.ResourceAcquisition; //var decl = resource as VariableDeclarationStatement; //if (decl == null || decl.Variables.Count == 0) // throw new Exception("using statement is supported only with the var keyword in javascript. Example: using(var g = new MyDisposable()){}"); foreach (var dr in stVar.Declaration.Declarators) { st2.FinallyBlock.Add(J.Member(dr.Name).Member("Dispose").Invoke().Statement()); } return(J.Block().Add(stVar).Add(st2)); //TODO: get rid of block }
public UsingStatement TransformUsings(ExpressionStatement node) { Match m1 = variableAssignPattern.Match(node); if (m1 == null) { return(null); } AstNode tryCatch = node.NextSibling; Match m2 = usingTryCatchPattern.Match(tryCatch); if (m2 == null) { return(null); } string variableName = m1.Get <IdentifierExpression>("variable").Single().Identifier; if (variableName == m2.Get <IdentifierExpression>("ident").Single().Identifier) { if (m2.Has("valueType")) { // if there's no if(x!=null), then it must be a value type ILVariable v = m1.Get("variable").Single().Annotation <ILVariable>(); if (v == null || v.Type == null || !v.Type.IsValueType) { return(null); } } node.Remove(); BlockStatement body = m2.Get <BlockStatement>("body").Single(); UsingStatement usingStatement = new UsingStatement(); usingStatement.ResourceAcquisition = node.Expression.Detach(); usingStatement.EmbeddedStatement = body.Detach(); tryCatch.ReplaceWith(usingStatement); // Move the variable declaration into the resource acquisition, if possible // This is necessary for the foreach-pattern to work on the result of the using-pattern VariableDeclarationStatement varDecl = FindVariableDeclaration(usingStatement, variableName); if (varDecl != null && varDecl.Parent is BlockStatement) { Statement declarationPoint; if (CanMoveVariableDeclarationIntoStatement(varDecl, usingStatement, out declarationPoint)) { Debug.Assert(declarationPoint == usingStatement); // Moving the variable into the UsingStatement is allowed: usingStatement.ResourceAcquisition = new VariableDeclarationStatement { Type = (AstType)varDecl.Type.Clone(), Variables = { new VariableInitializer { Name = variableName, Initializer = m1.Get <Expression>("initializer").Single().Detach() }.CopyAnnotationsFrom(usingStatement.ResourceAcquisition) } }.CopyAnnotationsFrom(node); } } return(usingStatement); } return(null); }
private static void GenerateUsingStatement(ScriptGenerator generator, MemberSymbol symbol, UsingStatement statement) { GenerateVariableDeclarationStatement(generator, symbol, statement.Guard); ScriptTextWriter writer = generator.Writer; writer.WriteLine("try {"); writer.Indent++; GenerateStatement(generator, symbol, statement.Body); writer.Indent--; writer.WriteLine("}"); writer.WriteLine("finally {"); writer.Indent++; foreach (VariableSymbol variable in statement.Guard.Variables) { writer.Write("if("); writer.Write(variable.GeneratedName); writer.WriteLine(") {"); writer.Indent++; writer.Write(variable.GeneratedName); writer.Write("."); writer.Write(variable.ValueType.GetMember("Dispose").GeneratedName); writer.WriteLine("();"); writer.Indent--; writer.WriteLine("}"); } writer.Indent--; writer.WriteLine("}"); }
public object VisitUsingStatement(UsingStatement usingStatement, object data) { LocalVariableDeclaration varDecl = usingStatement.ResourceAcquisition as LocalVariableDeclaration; Expression expr; if (varDecl != null) { if (varDecl.Variables.Count != 1) { AddError(usingStatement, "Only one variable can be used with the using statement."); return(null); } expr = new AssignmentExpression(new IdentifierExpression(varDecl.Variables[0].Name), AssignmentOperatorType.Assign, varDecl.Variables[0].Initializer); } else { ExpressionStatement se = usingStatement.ResourceAcquisition as ExpressionStatement; if (se == null) { AddError(usingStatement, "Expected: VariableDeclaration or StatementExpression"); return(null); } expr = se.Expression; } return(CreateMacro(usingStatement, "using", usingStatement.EmbeddedStatement, expr)); }
public override ControlFlowNode VisitUsingStatement(UsingStatement usingStatement, ControlFlowNode data) { data = HandleEmbeddedStatement(usingStatement.ResourceAcquisition as Statement, data); ControlFlowNode bodyEnd = HandleEmbeddedStatement(usingStatement.EmbeddedStatement, data); return(CreateConnectedEndNode(usingStatement, bodyEnd)); }
public override void VisitUsingStatement(UsingStatement usingStatement) { inUsingStatementResourceAcquisition = true; usingStatement.ResourceAcquisition.AcceptVisitor(this); inUsingStatementResourceAcquisition = false; usingStatement.EmbeddedStatement.AcceptVisitor(this); }
public void UsingStatementWithExpression() { UsingStatement usingStmt = ParseUtilCSharp.ParseStatement <UsingStatement>("using (new MyVar()) { } "); Assert.IsTrue(usingStmt.ResourceAcquisition is ObjectCreateExpression); Assert.IsTrue(usingStmt.EmbeddedStatement is BlockStatement); }
/// <summary> /// Tests UsingStatement.cs /// </summary> public static void UsingStatement() { UsingStatement us = new UsingStatement(); us.FunctionWithUsingStatement(); us.FunctionWithTryFinally(); }
static async Task Main(string[] args) { // NOTE: Comment / Uncomment demoes as desired await AsyncIterators.Demo(); DefaultInterfaceMembers.Demo(); IndicesAndRanges.Demo1(); IndicesAndRanges.Demo2(); IndicesAndRanges.Demo3(); IndicesAndRanges.Demo4(); IndicesAndRanges.Demo5(); NullableTypes.Demo(); Patterns.Demo1(); Patterns.Demo2(); ReadOnlyMembers.Demo1(); ReadOnlyMembers.Demo2(); StaticLocalFunctions.Demo1(); StaticLocalFunctions.Demo2(); SwitchExpressions.Demo1(); SwitchExpressions.Demo2(); UsingStatement.Demo1(); UsingStatement.Demo2(); Console.ReadKey(); await Task.CompletedTask; }
public UnifiedElement VisitUsingStatement(UsingStatement stmt, object data) { var target = stmt.ResourceAcquisition.TryAcceptForExpression(this); var body = stmt.EmbeddedStatement.TryAcceptForExpression(this).ToBlock(); return(UnifiedUsing.Create(target.ToSet(), body)); }
public virtual void VisitUsingStatement(UsingStatement usingStatement) { if (ThrowException) { throw (Exception)CreateException(usingStatement); } }
public virtual void VisitUsingStatement(UsingStatement usingStatement) { if (this.ThrowException) { throw (System.Exception) this.CreateException(usingStatement); } }
public override AstNode VisitUsingStatement(UsingStatement usingStatement) { var awaitSearch = new AwaitSearchVisitor(null); usingStatement.AcceptVisitor(awaitSearch); var awaiters = awaitSearch.GetAwaitExpressions().ToArray(); if (awaiters.Length > 0) { IEnumerable <AstNode> inner = null; var res = usingStatement.ResourceAcquisition; var varStat = res as VariableDeclarationStatement; if (varStat != null) { inner = varStat.Variables.Skip(1); res = varStat.Variables.First(); } return(this.EmitUsing(usingStatement, res, inner, varStat)); } return(base.VisitUsingStatement(usingStatement)); }
private Statement ProcessUsingStatement(UsingNode node) { UsingStatement statement = new UsingStatement(); statement.AddGuard((VariableDeclarationStatement)ProcessVariableDeclarationStatement((VariableDeclarationNode)node.Guard)); statement.AddBody(BuildStatement((StatementNode)node.Body)); return(statement); }
// public virtual object Visit(ReDimClause reDimClause, object data) // { // Debug.Assert(reDimClause != null); // Debug.Assert(reDimClause.Initializers != null); // foreach (Expression e in reDimClause.Initializers) { // Debug.Assert(e != null); // e.AcceptVisitor(this, data); // } // return data; // } public virtual object Visit(UsingStatement usingStatement, object data) { Debug.Assert(usingStatement != null); Debug.Assert(usingStatement.ResourceAcquisition != null); Debug.Assert(usingStatement.EmbeddedStatement != null); usingStatement.ResourceAcquisition.AcceptVisitor(this, data); usingStatement.EmbeddedStatement.AcceptVisitor(this, data); return(data); }
public override object VisitUsingStatement(UsingStatement usingStatement, object data) { ForceSpacesBefore(usingStatement.LPar, policy.UsingParentheses); ForceSpacesAfter(usingStatement.LPar, policy.WithinUsingParentheses); ForceSpacesBefore(usingStatement.RPar, policy.WithinUsingParentheses); return(base.VisitUsingStatement(usingStatement, data)); }
public void VBNetUsingStatementTest2() { string usingText = @" Using nf As Font = New Font() Bla(nf) End Using"; UsingStatement usingStmt = ParseUtilVBNet.ParseStatement <UsingStatement>(usingText); // TODO : Extend test. }
public void VBNetUsingStatementTest3() { string usingText = @" Using nf As New Font(), nf2 As New List(Of Font)(), nf3 = Nothing Bla(nf) End Using"; UsingStatement usingStmt = ParseUtilVBNet.ParseStatement <UsingStatement>(usingText); // TODO : Extend test. }
public override AstNode Visit(UsingStatement node) { // Visit the using member. Expression member = node.GetMember(); member.Accept(this); // Cast the pseudo-scope. PseudoScope scope = (PseudoScope)node.GetScope(); // Get the member type. IChelaType memberType = member.GetNodeType(); if (memberType.IsMetaType()) { // Get the actual type. MetaType meta = (MetaType)memberType; memberType = meta.GetActualType(); // Only structure relatives. if (memberType.IsStructure() || memberType.IsClass() || memberType.IsInterface()) { scope.AddAlias(memberType.GetName(), (ScopeMember)memberType); } else { Error(node, "unexpected type."); } } else if (memberType.IsReference()) { // Only static members supported. ScopeMember theMember = (ScopeMember)member.GetNodeValue(); MemberFlags instanceFlags = MemberFlags.InstanceMask & theMember.GetFlags(); if (instanceFlags != MemberFlags.Static) { Error(node, "unexpected member type."); } // Store the member. scope.AddAlias(theMember.GetName(), theMember); } else if (memberType.IsNamespace()) { // Set the namespace chain. Namespace space = (Namespace)member.GetNodeValue(); scope.SetChainNamespace(space); } else { Error(node, "unsupported object to use."); } base.Visit(node); return(node); }
S IAstVisitor <T, S> .VisitUsingStatement(UsingStatement usingStatement, T data) { var handler = UsingStatementVisited; if (handler != null) { handler(usingStatement, data); } return(VisitChildren(usingStatement, data)); }
public void UsingStatementWithVariableDeclaration() { UsingStatement usingStmt = ParseUtilCSharp.ParseStatement <UsingStatement>("using (MyVar var = new MyVar()) { } "); VariableDeclarationStatement varDecl = (VariableDeclarationStatement)usingStmt.ResourceAcquisition; Assert.AreEqual("var", varDecl.Variables.Single().Name); Assert.IsTrue(varDecl.Variables.Single().Initializer is ObjectCreateExpression); Assert.AreEqual("MyVar", ((SimpleType)varDecl.Type).Identifier); Assert.IsTrue(usingStmt.EmbeddedStatement is BlockStatement); }
public override IEnumerable <Expression> VisitUsingStatement(UsingStatement usingStatement) { if (usingStatement.ResourceAcquisition is Expression expr) { return new[] { expr } } ; return(usingStatement.ResourceAcquisition.AcceptVisitor(this)); }
public void VBNetUsingStatementTest() { string usingText = @" Using nf As New System.Drawing.Font(""Arial"", 12.0F, FontStyle.Bold) c.Font = nf c.Text = ""This is 12-point Arial bold"" End Using"; UsingStatement usingStmt = ParseUtilVBNet.ParseStatement <UsingStatement>(usingText); // TODO : Extend test. }
public override DefiniteAssignmentStatus VisitUsingStatement(UsingStatement usingStatement, DefiniteAssignmentStatus data) { if (usingStatement.ResourceAcquisition is Expression) { return(usingStatement.ResourceAcquisition.AcceptVisitor(this, data)); } else { return(data); // don't handle resource acquisition statements, as those are connected in the control flow graph } }
public override IEnumerable <Expression> VisitUsingStatement(UsingStatement usingStatement) { var expr = usingStatement.ResourceAcquisition as Expression; if (expr != null) { return new [] { expr } } ; return(usingStatement.ResourceAcquisition.AcceptVisitor(this)); }
public override AstNode VisitUsingStatement(UsingStatement usingStatement, object data) { if (context.Settings.ForEachStatement) { AstNode result = TransformForeach(usingStatement); if (result != null) { return(result); } } return(base.VisitUsingStatement(usingStatement, data)); }
public IEnumerator GetEnumerator() { foreach (var filePath in Directory.GetFiles("TestCases")) { var testCase = new FormatTestCase(); testCase.FileName = Path.GetFileNameWithoutExtension(filePath); using (var reader = new StreamReader(filePath)) { testCase.ConfigurationString = reader.ReadLine(); reader.ReadLine().Should().Be("INPUT"); testCase.Input = new List <UsingStatement>(); while (true) { string line = reader.ReadLine(); if ((line == null) || (line == "OUTPUT")) { break; } if (UsingStatement.TryParse(line, out var statement)) { testCase.Input.Add(statement); } } var outputBuffer = new StringWriter(); while (true) { string line = reader.ReadLine(); if (line == null) { break; } outputBuffer.WriteLine(line); } testCase.ExpectedOutput = outputBuffer.ToString(); yield return(testCase); } } }
public void A_UsingStatement_Is_Created() { const string code = "using System;"; CSharpParser parser = new CSharpParser(); IBaseConstruct bc = parser.ParseSingleConstruct(code, BaseConstructType.UsingDirective); Assert.That(bc, Is.Not.Null); Assert.That(bc, Is.InstanceOfType(typeof(UsingStatement))); UsingStatement con = (UsingStatement)bc; Assert.That(con.Value, Is.EqualTo("System")); }
public override void VisitUsingStatement(UsingStatement usingStatement) { var awaitSearch = new AwaitSearchVisitor(null); usingStatement.AcceptVisitor(awaitSearch); var awaiters = awaitSearch.GetAwaitExpressions().ToArray(); if (awaiters.Length > 0) { this.Found = true; } base.VisitUsingStatement(usingStatement); }
public void CSharpCodeGenerator_UsingStatement_WithoutBody() { var statement = new UsingStatement(); statement.Statement = new NewObjectExpression(new TypeReference("Disposable")); var generator = new CSharpCodeGenerator(); var result = generator.Write(statement); Assert.That.StringEquals(@"using (new Disposable()) { } ", result); }
public RemoveUsingStatementFromClassAction(UsingStatement usingStatementToDelete) { UsingStatementToDelete = usingStatementToDelete; }
public override void VisitUsingStatement(UsingStatement usingStatement) { ForceSpacesBefore(usingStatement.LParToken, policy.SpaceBeforeUsingParentheses); ForceSpacesAfter(usingStatement.LParToken, policy.SpacesWithinUsingParentheses); ForceSpacesBefore(usingStatement.RParToken, policy.SpacesWithinUsingParentheses); FixEmbeddedStatment(policy.StatementBraceStyle, policy.UsingBraceForcement, usingStatement.EmbeddedStatement); }
public UsingStatement CreateUsingStatement(Block blockStatement) { var usingResult = new UsingStatement(); Mono.CSharp.Statement cur = blockStatement.Statements [0]; var u = cur as Using; if (u != null) { usingResult.AddChild(new CSharpTokenNode(Convert(u.loc), UsingStatement.UsingKeywordRole), UsingStatement.UsingKeywordRole); usingResult.AddChild(new CSharpTokenNode(Convert(blockStatement.StartLocation), Roles.LPar), Roles.LPar); if (u.Variables != null) { var initializer = new VariableInitializer { NameToken = Identifier.Create(u.Variables.Variable.Name, Convert(u.Variables.Variable.Location)), }; var loc = LocationsBag.GetLocations(u.Variables); if (loc != null) initializer.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.Assign), Roles.Assign); if (u.Variables.Initializer != null) initializer.Initializer = u.Variables.Initializer.Accept(this) as Expression; var varDec = new VariableDeclarationStatement { Type = ConvertToType(u.Variables.TypeExpression), Variables = { initializer } }; if (u.Variables.Declarators != null) { foreach (var decl in u.Variables.Declarators) { var declLoc = LocationsBag.GetLocations(decl); var init = new VariableInitializer(); if (declLoc != null && declLoc.Count > 0) varDec.AddChild(new CSharpTokenNode(Convert(declLoc [0]), Roles.Comma), Roles.Comma); init.AddChild(Identifier.Create(decl.Variable.Name, Convert(decl.Variable.Location)), Roles.Identifier); if (decl.Initializer != null) { if (declLoc != null && declLoc.Count > 1) init.AddChild(new CSharpTokenNode(Convert(declLoc [1]), Roles.Assign), Roles.Assign); init.AddChild((Expression)decl.Initializer.Accept(this), Roles.Expression); } varDec.AddChild(init, Roles.Variable); } } usingResult.AddChild(varDec, UsingStatement.ResourceAcquisitionRole); } cur = u.Statement; usingResult.AddChild(new CSharpTokenNode(Convert(blockStatement.EndLocation), Roles.RPar), Roles.RPar); if (cur != null) usingResult.AddChild((Statement)cur.Accept(this), Roles.EmbeddedStatement); } return usingResult; }
public virtual void VisitUsingStatement (UsingStatement usingStatement) { VisitChildren (usingStatement); }
void EmbeddedStatement( #line 1528 "cs.ATG" out Statement statement) { #line 1530 "cs.ATG" TypeReference type = null; Expression expr = null; Statement embeddedStatement = null; statement = null; #line 1536 "cs.ATG" Location startLocation = la.Location; if (la.kind == 16) { Block( #line 1538 "cs.ATG" out statement); } else if (la.kind == 11) { lexer.NextToken(); #line 1541 "cs.ATG" statement = new EmptyStatement(); } else if ( #line 1544 "cs.ATG" UnCheckedAndLBrace()) { #line 1544 "cs.ATG" Statement block; bool isChecked = true; if (la.kind == 58) { lexer.NextToken(); } else if (la.kind == 118) { lexer.NextToken(); #line 1545 "cs.ATG" isChecked = false; } else SynErr(197); Block( #line 1546 "cs.ATG" out block); #line 1546 "cs.ATG" statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); } else if (la.kind == 79) { IfStatement( #line 1549 "cs.ATG" out statement); } else if (la.kind == 110) { lexer.NextToken(); #line 1551 "cs.ATG" List<SwitchSection> switchSections = new List<SwitchSection>(); Expect(20); Expr( #line 1552 "cs.ATG" out expr); Expect(21); Expect(16); SwitchSections( #line 1553 "cs.ATG" switchSections); Expect(17); #line 1555 "cs.ATG" statement = new SwitchStatement(expr, switchSections); } else if (la.kind == 125) { lexer.NextToken(); Expect(20); Expr( #line 1558 "cs.ATG" out expr); Expect(21); EmbeddedStatement( #line 1559 "cs.ATG" out embeddedStatement); #line 1560 "cs.ATG" statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start); } else if (la.kind == 65) { lexer.NextToken(); EmbeddedStatement( #line 1562 "cs.ATG" out embeddedStatement); Expect(125); Expect(20); Expr( #line 1563 "cs.ATG" out expr); Expect(21); Expect(11); #line 1564 "cs.ATG" statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); } else if (la.kind == 76) { lexer.NextToken(); #line 1566 "cs.ATG" List<Statement> initializer = null; List<Statement> iterator = null; Expect(20); if (StartOf(6)) { ForInitializer( #line 1567 "cs.ATG" out initializer); } Expect(11); if (StartOf(6)) { Expr( #line 1568 "cs.ATG" out expr); } Expect(11); if (StartOf(6)) { ForIterator( #line 1569 "cs.ATG" out iterator); } Expect(21); EmbeddedStatement( #line 1570 "cs.ATG" out embeddedStatement); #line 1571 "cs.ATG" statement = new ForStatement(initializer, expr, iterator, embeddedStatement); } else if (la.kind == 77) { lexer.NextToken(); Expect(20); Type( #line 1573 "cs.ATG" out type); Identifier(); #line 1573 "cs.ATG" string varName = t.val; Expect(81); Expr( #line 1574 "cs.ATG" out expr); Expect(21); EmbeddedStatement( #line 1575 "cs.ATG" out embeddedStatement); #line 1576 "cs.ATG" statement = new ForeachStatement(type, varName , expr, embeddedStatement); } else if (la.kind == 53) { lexer.NextToken(); Expect(11); #line 1579 "cs.ATG" statement = new BreakStatement(); } else if (la.kind == 61) { lexer.NextToken(); Expect(11); #line 1580 "cs.ATG" statement = new ContinueStatement(); } else if (la.kind == 78) { GotoStatement( #line 1581 "cs.ATG" out statement); } else if ( #line 1583 "cs.ATG" IsYieldStatement()) { Expect(132); if (la.kind == 101) { lexer.NextToken(); Expr( #line 1584 "cs.ATG" out expr); #line 1584 "cs.ATG" statement = new YieldStatement(new ReturnStatement(expr)); } else if (la.kind == 53) { lexer.NextToken(); #line 1585 "cs.ATG" statement = new YieldStatement(new BreakStatement()); } else SynErr(198); Expect(11); } else if (la.kind == 101) { lexer.NextToken(); if (StartOf(6)) { Expr( #line 1588 "cs.ATG" out expr); } Expect(11); #line 1588 "cs.ATG" statement = new ReturnStatement(expr); } else if (la.kind == 112) { lexer.NextToken(); if (StartOf(6)) { Expr( #line 1589 "cs.ATG" out expr); } Expect(11); #line 1589 "cs.ATG" statement = new ThrowStatement(expr); } else if (StartOf(6)) { StatementExpr( #line 1592 "cs.ATG" out statement); while (!(la.kind == 0 || la.kind == 11)) {SynErr(199); lexer.NextToken(); } Expect(11); } else if (la.kind == 114) { TryStatement( #line 1595 "cs.ATG" out statement); } else if (la.kind == 86) { lexer.NextToken(); Expect(20); Expr( #line 1598 "cs.ATG" out expr); Expect(21); EmbeddedStatement( #line 1599 "cs.ATG" out embeddedStatement); #line 1599 "cs.ATG" statement = new LockStatement(expr, embeddedStatement); } else if (la.kind == 121) { #line 1602 "cs.ATG" Statement resourceAcquisitionStmt = null; lexer.NextToken(); Expect(20); ResourceAcquisition( #line 1604 "cs.ATG" out resourceAcquisitionStmt); Expect(21); EmbeddedStatement( #line 1605 "cs.ATG" out embeddedStatement); #line 1605 "cs.ATG" statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); } else if (la.kind == 119) { lexer.NextToken(); Block( #line 1608 "cs.ATG" out embeddedStatement); #line 1608 "cs.ATG" statement = new UnsafeStatement(embeddedStatement); } else if (la.kind == 74) { #line 1610 "cs.ATG" Statement pointerDeclarationStmt = null; lexer.NextToken(); Expect(20); ResourceAcquisition( #line 1612 "cs.ATG" out pointerDeclarationStmt); Expect(21); EmbeddedStatement( #line 1613 "cs.ATG" out embeddedStatement); #line 1613 "cs.ATG" statement = new FixedStatement(pointerDeclarationStmt, embeddedStatement); } else SynErr(200); #line 1615 "cs.ATG" if (statement != null) { statement.StartLocation = startLocation; statement.EndLocation = t.EndLocation; } }
public void UsingStatement() { UsingStatement inter = new UsingStatement(controller, "IntelliMerge", "ArchAngel.Workbench.IntelliMerge"); Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True); }
public override object Visit (Using usingStatement) { var result = new UsingStatement (); var location = LocationsBag.GetLocations (usingStatement); result.AddChild (new CSharpTokenNode (Convert (usingStatement.loc), "using".Length), UsingStatement.Roles.Keyword); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), UsingStatement.Roles.LPar); result.AddChild ((AstNode)usingStatement.Expression.Accept (this), UsingStatement.ResourceAcquisitionRole); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), UsingStatement.Roles.RPar); result.AddChild ((MonoDevelop.CSharp.Ast.Statement)usingStatement.Statement.Accept (this), UsingStatement.Roles.EmbeddedStatement); return result; }
public override void VisitUsingStatement(UsingStatement usingStatement) { VisitNewDeclarationSpace(usingStatement); }
public override object VisitUsingStatement(UsingStatement usingStatement, object data) { UnlockWith(usingStatement); return base.VisitUsingStatement(usingStatement, data); }
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; } }
public override void VisitUsingStatement(UsingStatement usingStatement) { ForceSpacesBeforeRemoveNewLines(usingStatement.LParToken, policy.SpaceBeforeUsingParentheses); Align(usingStatement.LParToken, usingStatement.ResourceAcquisition, policy.SpacesWithinUsingParentheses); ForceSpacesBeforeRemoveNewLines(usingStatement.RParToken, policy.SpacesWithinUsingParentheses); FixEmbeddedStatment(policy.StatementBraceStyle, usingStatement.EmbeddedStatement); }
public UsingStatement CreateUsingStatement (Block blockStatement) { var usingResult = new UsingStatement (); Statement cur = blockStatement.Statements[0]; if (cur is Using) { Using u = (Using)cur; usingResult.AddChild (new CSharpTokenNode (Convert (u.loc), "using".Length), UsingStatement.Roles.Keyword); usingResult.AddChild (new CSharpTokenNode (Convert (blockStatement.StartLocation), 1), UsingStatement.Roles.LPar); if (u.Variables != null) { usingResult.AddChild ((INode)u.Variables.TypeExpression.Accept (this), UsingStatement.Roles.ReturnType); usingResult.AddChild (new Identifier (u.Variables.Variable.Name, Convert (u.Variables.Variable.Location)), UsingStatement.Roles.Identifier); var loc = LocationsBag.GetLocations (u.Variables); if (loc != null) usingResult.AddChild (new CSharpTokenNode (Convert (loc[1]), 1), ContinueStatement.Roles.Assign); if (u.Variables.Initializer != null) usingResult.AddChild ((INode)u.Variables.Initializer.Accept (this), UsingStatement.Roles.Initializer); } cur = u.Statement; usingResult.AddChild (new CSharpTokenNode (Convert (blockStatement.EndLocation), 1), UsingStatement.Roles.RPar); usingResult.AddChild ((INode)cur.Accept (this), UsingStatement.Roles.EmbeddedStatement); } return usingResult; }
public UsingStatement CreateUsingStatement (Block blockStatement) { var usingResult = new UsingStatement (); var location = LocationsBag.GetLocations (blockStatement); if (location != null) usingResult.AddChild (new CSharpTokenNode (Convert (location[0]), "using".Length), UsingStatement.Roles.Keyword); if (location != null) usingResult.AddChild (new CSharpTokenNode (Convert (location[1]), 1), UsingStatement.Roles.LPar); Statement cur = blockStatement.Statements[0]; while (cur is Using) { Using u = (Using)cur; if (u.Var != null) usingResult.AddChild ((INode)u.Var.Accept (this), UsingStatement.Roles.Identifier); if (u.Init != null) usingResult.AddChild ((INode)u.Init.Accept (this), UsingStatement.Roles.Initializer); cur = u.EmbeddedStatement; } if (location != null) usingResult.AddChild (new CSharpTokenNode (Convert (location[2]), 1), UsingStatement.Roles.RPar); usingResult.AddChild ((INode)cur.Accept (this), UsingStatement.Roles.EmbeddedStatement); return usingResult; }
public AddUsingStatementToClassAction(Class classToAddTo, UsingStatement usingStatementToAdd) { ClassToAddTo = classToAddTo; UsingStatementToAdd = usingStatementToAdd; }
public override void VisitUsingStatement(UsingStatement usingStatement) { new UsingBlock(this, usingStatement).Emit(); }
public virtual void VisitUsingStatement(UsingStatement usingStatement) { if (this.ThrowException) { throw (Exception)this.CreateException(usingStatement); } }
public VBUsingStatementPrinter(UsingStatement obj) { this.obj = obj; }
public virtual void VisitUsingStatement(UsingStatement usingStatement) { StartNode(usingStatement); WriteKeywordReference(UsingStatement.UsingKeywordRole); Space(policy.SpaceBeforeUsingParentheses); var braceHelper = BraceHelper.LeftParen(this, CodeBracesRangeFlags.Parentheses); Space(policy.SpacesWithinUsingParentheses); DebugStart(usingStatement); usingStatement.ResourceAcquisition.AcceptVisitor(this); DebugEnd(usingStatement); Space(policy.SpacesWithinUsingParentheses); braceHelper.RightParen(); WriteEmbeddedStatement(usingStatement.EmbeddedStatement); EndNode(usingStatement); }
public bool Equals( UsingStatement obj ) { if (ReferenceEquals( null, obj )) return false; if (ReferenceEquals( this, obj )) return true; return Equals( obj.@namespace, this.@namespace ); }
public override void VisitUsingStatement(UsingStatement usingStatement) { var stmt = CreateInnerCompiler().Compile(usingStatement.EmbeddedStatement); var vds = usingStatement.ResourceAcquisition as VariableDeclarationStatement; if (vds != null) { foreach (var resource in vds.Variables.Reverse()) { stmt = GenerateUsingBlock(((LocalResolveResult)_resolver.Resolve(resource)), resource.Initializer, usingStatement.GetRegion(), stmt); } } else { var resource = CreateTemporaryVariable(_resolver.Resolve((Expression)usingStatement.ResourceAcquisition).Type, usingStatement.GetRegion()); stmt = GenerateUsingBlock(new LocalResolveResult(resource), (Expression)usingStatement.ResourceAcquisition, usingStatement.GetRegion(), stmt); } _result.Add(stmt); }
void EmbeddedStatement( #line 2755 "VBNET.ATG" out Statement statement) { #line 2757 "VBNET.ATG" Statement embeddedStatement = null; statement = null; Expression expr = null; string name = String.Empty; List<Expression> p = null; if (la.kind == 107) { lexer.NextToken(); #line 2763 "VBNET.ATG" ExitType exitType = ExitType.None; switch (la.kind) { case 195: { lexer.NextToken(); #line 2765 "VBNET.ATG" exitType = ExitType.Sub; break; } case 114: { lexer.NextToken(); #line 2767 "VBNET.ATG" exitType = ExitType.Function; break; } case 171: { lexer.NextToken(); #line 2769 "VBNET.ATG" exitType = ExitType.Property; break; } case 95: { lexer.NextToken(); #line 2771 "VBNET.ATG" exitType = ExitType.Do; break; } case 111: { lexer.NextToken(); #line 2773 "VBNET.ATG" exitType = ExitType.For; break; } case 203: { lexer.NextToken(); #line 2775 "VBNET.ATG" exitType = ExitType.Try; break; } case 216: { lexer.NextToken(); #line 2777 "VBNET.ATG" exitType = ExitType.While; break; } case 182: { lexer.NextToken(); #line 2779 "VBNET.ATG" exitType = ExitType.Select; break; } default: SynErr(273); break; } #line 2781 "VBNET.ATG" statement = new ExitStatement(exitType); } else if (la.kind == 203) { TryStatement( #line 2782 "VBNET.ATG" out statement); } else if (la.kind == 76) { lexer.NextToken(); #line 2783 "VBNET.ATG" ContinueType continueType = ContinueType.None; if (la.kind == 95 || la.kind == 111 || la.kind == 216) { if (la.kind == 95) { lexer.NextToken(); #line 2783 "VBNET.ATG" continueType = ContinueType.Do; } else if (la.kind == 111) { lexer.NextToken(); #line 2783 "VBNET.ATG" continueType = ContinueType.For; } else { lexer.NextToken(); #line 2783 "VBNET.ATG" continueType = ContinueType.While; } } #line 2783 "VBNET.ATG" statement = new ContinueStatement(continueType); } else if (la.kind == 200) { lexer.NextToken(); if (StartOf(29)) { Expr( #line 2785 "VBNET.ATG" out expr); } #line 2785 "VBNET.ATG" statement = new ThrowStatement(expr); } else if (la.kind == 180) { lexer.NextToken(); if (StartOf(29)) { Expr( #line 2787 "VBNET.ATG" out expr); } #line 2787 "VBNET.ATG" statement = new ReturnStatement(expr); } else if (la.kind == 196) { lexer.NextToken(); Expr( #line 2789 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2789 "VBNET.ATG" out embeddedStatement); Expect(100); Expect(196); #line 2790 "VBNET.ATG" statement = new LockStatement(expr, embeddedStatement); } else if (la.kind == 174) { lexer.NextToken(); Identifier(); #line 2792 "VBNET.ATG" name = t.val; if (la.kind == 25) { lexer.NextToken(); if (StartOf(37)) { ArgumentList( #line 2793 "VBNET.ATG" out p); } Expect(26); } #line 2795 "VBNET.ATG" statement = new RaiseEventStatement(name, p); } else if (la.kind == 218) { WithStatement( #line 2798 "VBNET.ATG" out statement); } else if (la.kind == 43) { lexer.NextToken(); #line 2800 "VBNET.ATG" Expression handlerExpr = null; Expr( #line 2801 "VBNET.ATG" out expr); Expect(12); Expr( #line 2801 "VBNET.ATG" out handlerExpr); #line 2803 "VBNET.ATG" statement = new AddHandlerStatement(expr, handlerExpr); } else if (la.kind == 178) { lexer.NextToken(); #line 2806 "VBNET.ATG" Expression handlerExpr = null; Expr( #line 2807 "VBNET.ATG" out expr); Expect(12); Expr( #line 2807 "VBNET.ATG" out handlerExpr); #line 2809 "VBNET.ATG" statement = new RemoveHandlerStatement(expr, handlerExpr); } else if (la.kind == 216) { lexer.NextToken(); Expr( #line 2812 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2813 "VBNET.ATG" out embeddedStatement); Expect(100); Expect(216); #line 2815 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start); } else if (la.kind == 95) { lexer.NextToken(); #line 2820 "VBNET.ATG" ConditionType conditionType = ConditionType.None; if (la.kind == 209 || la.kind == 216) { WhileOrUntil( #line 2823 "VBNET.ATG" out conditionType); Expr( #line 2823 "VBNET.ATG" out expr); EndOfStmt(); Block( #line 2824 "VBNET.ATG" out embeddedStatement); Expect(138); #line 2827 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, conditionType == ConditionType.While ? ConditionType.DoWhile : conditionType, ConditionPosition.Start); } else if (la.kind == 1 || la.kind == 11) { EndOfStmt(); Block( #line 2834 "VBNET.ATG" out embeddedStatement); Expect(138); if (la.kind == 209 || la.kind == 216) { WhileOrUntil( #line 2835 "VBNET.ATG" out conditionType); Expr( #line 2835 "VBNET.ATG" out expr); } #line 2837 "VBNET.ATG" statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End); } else SynErr(274); } else if (la.kind == 111) { lexer.NextToken(); #line 2842 "VBNET.ATG" Expression group = null; TypeReference typeReference; string typeName; Location startLocation = t.Location; if (la.kind == 97) { lexer.NextToken(); LoopControlVariable( #line 2849 "VBNET.ATG" out typeReference, out typeName); Expect(125); Expr( #line 2850 "VBNET.ATG" out group); EndOfStmt(); Block( #line 2851 "VBNET.ATG" out embeddedStatement); Expect(149); if (StartOf(29)) { Expr( #line 2852 "VBNET.ATG" out expr); } #line 2854 "VBNET.ATG" statement = new ForeachStatement(typeReference, typeName, group, embeddedStatement, expr); statement.StartLocation = startLocation; statement.EndLocation = t.EndLocation; } else if (StartOf(38)) { #line 2865 "VBNET.ATG" Expression start = null; Expression end = null; Expression step = null; Expression variableExpr = null; Expression nextExpr = null; List<Expression> nextExpressions = null; if ( #line 2872 "VBNET.ATG" IsLoopVariableDeclaration()) { LoopControlVariable( #line 2873 "VBNET.ATG" out typeReference, out typeName); } else { #line 2875 "VBNET.ATG" typeReference = null; typeName = null; SimpleExpr( #line 2876 "VBNET.ATG" out variableExpr); } Expect(10); Expr( #line 2878 "VBNET.ATG" out start); Expect(201); Expr( #line 2878 "VBNET.ATG" out end); if (la.kind == 190) { lexer.NextToken(); Expr( #line 2878 "VBNET.ATG" out step); } EndOfStmt(); Block( #line 2879 "VBNET.ATG" out embeddedStatement); Expect(149); if (StartOf(29)) { Expr( #line 2882 "VBNET.ATG" out nextExpr); #line 2884 "VBNET.ATG" nextExpressions = new List<Expression>(); nextExpressions.Add(nextExpr); while (la.kind == 12) { lexer.NextToken(); Expr( #line 2887 "VBNET.ATG" out nextExpr); #line 2887 "VBNET.ATG" nextExpressions.Add(nextExpr); } } #line 2890 "VBNET.ATG" statement = new ForNextStatement { TypeReference = typeReference, VariableName = typeName, LoopVariableExpression = variableExpr, Start = start, End = end, Step = step, EmbeddedStatement = embeddedStatement, NextExpressions = nextExpressions }; } else SynErr(275); } else if (la.kind == 105) { lexer.NextToken(); Expr( #line 2903 "VBNET.ATG" out expr); #line 2903 "VBNET.ATG" statement = new ErrorStatement(expr); } else if (la.kind == 176) { lexer.NextToken(); #line 2905 "VBNET.ATG" bool isPreserve = false; if (la.kind == 169) { lexer.NextToken(); #line 2905 "VBNET.ATG" isPreserve = true; } ReDimClause( #line 2906 "VBNET.ATG" out expr); #line 2908 "VBNET.ATG" ReDimStatement reDimStatement = new ReDimStatement(isPreserve); statement = reDimStatement; SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); while (la.kind == 12) { lexer.NextToken(); ReDimClause( #line 2912 "VBNET.ATG" out expr); #line 2913 "VBNET.ATG" SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); } } else if (la.kind == 104) { lexer.NextToken(); Expr( #line 2917 "VBNET.ATG" out expr); #line 2919 "VBNET.ATG" EraseStatement eraseStatement = new EraseStatement(); if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr);} while (la.kind == 12) { lexer.NextToken(); Expr( #line 2922 "VBNET.ATG" out expr); #line 2922 "VBNET.ATG" if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr); } } #line 2923 "VBNET.ATG" statement = eraseStatement; } else if (la.kind == 191) { lexer.NextToken(); #line 2925 "VBNET.ATG" statement = new StopStatement(); } else if ( #line 2927 "VBNET.ATG" la.kind == Tokens.If) { Expect(122); #line 2928 "VBNET.ATG" Location ifStartLocation = t.Location; Expr( #line 2928 "VBNET.ATG" out expr); if (la.kind == 199) { lexer.NextToken(); } if (la.kind == 1 || la.kind == 11) { EndOfStmt(); Block( #line 2931 "VBNET.ATG" out embeddedStatement); #line 2933 "VBNET.ATG" IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement); ifStatement.StartLocation = ifStartLocation; Location elseIfStart; while (la.kind == 99 || #line 2939 "VBNET.ATG" IsElseIf()) { if ( #line 2939 "VBNET.ATG" IsElseIf()) { Expect(98); #line 2939 "VBNET.ATG" elseIfStart = t.Location; Expect(122); } else { lexer.NextToken(); #line 2940 "VBNET.ATG" elseIfStart = t.Location; } #line 2942 "VBNET.ATG" Expression condition = null; Statement block = null; Expr( #line 2943 "VBNET.ATG" out condition); if (la.kind == 199) { lexer.NextToken(); } EndOfStmt(); Block( #line 2944 "VBNET.ATG" out block); #line 2946 "VBNET.ATG" ElseIfSection elseIfSection = new ElseIfSection(condition, block); elseIfSection.StartLocation = elseIfStart; elseIfSection.EndLocation = t.Location; elseIfSection.Parent = ifStatement; ifStatement.ElseIfSections.Add(elseIfSection); } if (la.kind == 98) { lexer.NextToken(); EndOfStmt(); Block( #line 2955 "VBNET.ATG" out embeddedStatement); #line 2957 "VBNET.ATG" ifStatement.FalseStatement.Add(embeddedStatement); } Expect(100); Expect(122); #line 2961 "VBNET.ATG" ifStatement.EndLocation = t.Location; statement = ifStatement; } else if (StartOf(39)) { #line 2966 "VBNET.ATG" IfElseStatement ifStatement = new IfElseStatement(expr); ifStatement.StartLocation = ifStartLocation; SingleLineStatementList( #line 2969 "VBNET.ATG" ifStatement.TrueStatement); if (la.kind == 98) { lexer.NextToken(); if (StartOf(39)) { SingleLineStatementList( #line 2972 "VBNET.ATG" ifStatement.FalseStatement); } } #line 2974 "VBNET.ATG" ifStatement.EndLocation = t.Location; statement = ifStatement; } else SynErr(276); } else if (la.kind == 182) { lexer.NextToken(); if (la.kind == 61) { lexer.NextToken(); } Expr( #line 2977 "VBNET.ATG" out expr); EndOfStmt(); #line 2978 "VBNET.ATG" List<SwitchSection> selectSections = new List<SwitchSection>(); Statement block = null; while (la.kind == 61) { #line 2982 "VBNET.ATG" List<CaseLabel> caseClauses = null; Location caseLocation = la.Location; lexer.NextToken(); CaseClauses( #line 2983 "VBNET.ATG" out caseClauses); if ( #line 2983 "VBNET.ATG" IsNotStatementSeparator()) { lexer.NextToken(); } EndOfStmt(); #line 2985 "VBNET.ATG" SwitchSection selectSection = new SwitchSection(caseClauses); selectSection.StartLocation = caseLocation; Block( #line 2988 "VBNET.ATG" out block); #line 2990 "VBNET.ATG" selectSection.Children = block.Children; selectSection.EndLocation = t.EndLocation; selectSections.Add(selectSection); } #line 2996 "VBNET.ATG" statement = new SwitchStatement(expr, selectSections); Expect(100); Expect(182); } else if (la.kind == 157) { #line 2999 "VBNET.ATG" OnErrorStatement onErrorStatement = null; OnErrorStatement( #line 3000 "VBNET.ATG" out onErrorStatement); #line 3000 "VBNET.ATG" statement = onErrorStatement; } else if (la.kind == 119) { #line 3001 "VBNET.ATG" GotoStatement goToStatement = null; GotoStatement( #line 3002 "VBNET.ATG" out goToStatement); #line 3002 "VBNET.ATG" statement = goToStatement; } else if (la.kind == 179) { #line 3003 "VBNET.ATG" ResumeStatement resumeStatement = null; ResumeStatement( #line 3004 "VBNET.ATG" out resumeStatement); #line 3004 "VBNET.ATG" statement = resumeStatement; } else if (StartOf(38)) { #line 3007 "VBNET.ATG" Expression val = null; AssignmentOperatorType op; bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus || la.kind == Tokens.Not || la.kind == Tokens.Times; SimpleExpr( #line 3013 "VBNET.ATG" out expr); if (StartOf(40)) { AssignmentOperator( #line 3015 "VBNET.ATG" out op); Expr( #line 3015 "VBNET.ATG" out val); #line 3015 "VBNET.ATG" expr = new AssignmentExpression(expr, op, val); } else if (la.kind == 1 || la.kind == 11 || la.kind == 98) { #line 3016 "VBNET.ATG" if (mustBeAssignment) Error("error in assignment."); } else SynErr(277); #line 3019 "VBNET.ATG" // a field reference expression that stands alone is a // invocation expression without parantheses and arguments if(expr is MemberReferenceExpression || expr is IdentifierExpression) { expr = new InvocationExpression(expr); } statement = new ExpressionStatement(expr); } else if (la.kind == 60) { lexer.NextToken(); SimpleExpr( #line 3026 "VBNET.ATG" out expr); #line 3026 "VBNET.ATG" statement = new ExpressionStatement(expr); } else if (la.kind == 211) { lexer.NextToken(); #line 3028 "VBNET.ATG" Statement block; if ( #line 3029 "VBNET.ATG" Peek(1).kind == Tokens.As) { #line 3030 "VBNET.ATG" LocalVariableDeclaration resourceAquisition = new LocalVariableDeclaration(Modifiers.None); VariableDeclarator( #line 3031 "VBNET.ATG" resourceAquisition.Variables); while (la.kind == 12) { lexer.NextToken(); VariableDeclarator( #line 3033 "VBNET.ATG" resourceAquisition.Variables); } Block( #line 3035 "VBNET.ATG" out block); #line 3037 "VBNET.ATG" statement = new UsingStatement(resourceAquisition, block); } else if (StartOf(29)) { Expr( #line 3039 "VBNET.ATG" out expr); Block( #line 3040 "VBNET.ATG" out block); #line 3041 "VBNET.ATG" statement = new UsingStatement(new ExpressionStatement(expr), block); } else SynErr(278); Expect(100); Expect(211); } else if (StartOf(41)) { LocalDeclarationStatement( #line 3044 "VBNET.ATG" out statement); } else SynErr(279); }
public UsingStatement CreateUsingStatement (Block blockStatement) { var usingResult = new UsingStatement (); Mono.CSharp.Statement cur = blockStatement.Statements[0]; if (cur is Using) { Using u = (Using)cur; usingResult.AddChild (new CSharpTokenNode (Convert (u.loc), "using".Length), UsingStatement.Roles.Keyword); usingResult.AddChild (new CSharpTokenNode (Convert (blockStatement.StartLocation), 1), UsingStatement.Roles.LPar); if (u.Variables != null) { var initializer = new VariableInitializer () { NameToken = Identifier.Create (u.Variables.Variable.Name, Convert (u.Variables.Variable.Location)), }; var loc = LocationsBag.GetLocations (u.Variables); if (loc != null) initializer.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), VariableInitializer.Roles.Assign); if (u.Variables.Initializer != null) initializer.Initializer = u.Variables.Initializer.Accept (this) as Expression; var varDec = new VariableDeclarationStatement () { Type = ConvertToType (u.Variables.TypeExpression), Variables = { initializer } }; usingResult.AddChild (varDec, UsingStatement.ResourceAcquisitionRole); } cur = u.Statement; usingResult.AddChild (new CSharpTokenNode (Convert (blockStatement.EndLocation), 1), UsingStatement.Roles.RPar); if (cur != null) usingResult.AddChild ((Statement)cur.Accept (this), UsingStatement.Roles.EmbeddedStatement); } return usingResult; }
/// <summary> /// Visits the specified using statement. /// </summary> /// <param name="usingStatement">The using statement.</param> public override void Visit(UsingStatement usingStatement) { WriteLinkLine(usingStatement); Write("using ").Write(usingStatement.Name).WriteLine(";"); }
public override object Visit(Using usingStatement) { var result = new UsingStatement(); var location = LocationsBag.GetLocations(usingStatement); result.AddChild(new CSharpTokenNode(Convert(usingStatement.loc), UsingStatement.UsingKeywordRole), UsingStatement.UsingKeywordRole); if (location != null) result.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LPar), Roles.LPar); if (usingStatement.Expr != null) result.AddChild((AstNode)usingStatement.Expr.Accept(this), UsingStatement.ResourceAcquisitionRole); if (location != null && location.Count > 1) result.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RPar), Roles.RPar); if (usingStatement.Statement != null) result.AddChild((Statement)usingStatement.Statement.Accept(this), Roles.EmbeddedStatement); return result; }
public void UsingStatement_Change_Value() { UsingStatement merged1 = new UsingStatement(controller); UsingStatement merged2 = new UsingStatement(controller); UsingStatement merged3 = new UsingStatement(controller); const string Alias = "MyAlias1"; const string Value1 = "MyValue1"; const string Value2 = "MyValue2"; UsingStatement unchanging = new UsingStatement(controller, Alias, Value1); UsingStatement changing = new UsingStatement(controller, Alias, Value2); const string expectedResult = "using " + Alias + " = " + Value2; Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult); }
public override object Visit (UsingTemporary usingTemporary) { var result = new UsingStatement (); var location = LocationsBag.GetLocations (usingTemporary); result.AddChild (new CSharpTokenNode (Convert (usingTemporary.loc), "using".Length), UsingStatement.Roles.Keyword); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), UsingStatement.Roles.LPar); result.AddChild ((INode)usingTemporary.Expr.Accept (this), UsingStatement.Roles.Initializer); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), UsingStatement.Roles.RPar); result.AddChild ((INode)usingTemporary.Statement.Accept (this), UsingStatement.Roles.EmbeddedStatement); return result; }
public StringBuilder VisitUsingStatement(UsingStatement usingStatement, int data) { throw new SLSharpException("SL# does not have the using keyword."); }
public void VisitUsingStatement(UsingStatement usingStatement) { StartNode(usingStatement); WriteKeyword(UsingStatement.UsingKeywordRole); Space(policy.SpaceBeforeUsingParentheses); LPar(); Space(policy.SpacesWithinUsingParentheses); usingStatement.ResourceAcquisition.AcceptVisitor(this); Space(policy.SpacesWithinUsingParentheses); RPar(); WriteEmbeddedStatement(usingStatement.EmbeddedStatement); EndNode(usingStatement); }
public UsingBlock(IEmitter emitter, UsingStatement usingStatement) : base(emitter, usingStatement) { this.Emitter = emitter; this.UsingStatement = usingStatement; }