Example #1
0
			public override void Visit (Destructor d)
			{
				DestructorDeclaration newDestructor = new DestructorDeclaration ();
				var location = LocationsBag.GetMemberLocation (d);
				AddModifiers (newDestructor, location);
				if (location != null)
					newDestructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), DestructorDeclaration.TildeRole);
				newDestructor.AddChild (new Identifier (d.MemberName.Name, Convert (d.MemberName.Location)), AbstractNode.Roles.Identifier);
				
				if (location != null) {
					newDestructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DestructorDeclaration.Roles.LPar);
					newDestructor.AddChild (new CSharpTokenNode (Convert (location[2]), 1), DestructorDeclaration.Roles.RPar);
				}
				
				if (d.Block != null)
					newDestructor.AddChild ((INode)d.Block.Accept (this), DestructorDeclaration.Roles.Body);
				
				typeStack.Peek ().AddChild (newDestructor, TypeDeclaration.Roles.Member);
			}
		public virtual object TrackedVisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) {
			return base.VisitDestructorDeclaration(destructorDeclaration, data);
		}
			public override void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
			{
				currentMethodName = "~" + destructorDeclaration.Name;
				base.VisitDestructorDeclaration(destructorDeclaration);
			}
Example #4
0
			public override void Visit(Destructor d)
			{
				var newDestructor = new DestructorDeclaration();
				AddAttributeSection(newDestructor, d);
				var location = LocationsBag.GetMemberLocation(d);
				AddModifiers(newDestructor, location);
				if (location != null && location.Count > 0)
					newDestructor.AddChild(new CSharpTokenNode(Convert(location [0]), DestructorDeclaration.TildeRole), DestructorDeclaration.TildeRole);
				newDestructor.AddChild(Identifier.Create(d.Identifier, Convert(d.MemberName.Location)), Roles.Identifier);
				
				if (location != null && location.Count > 1) {
					newDestructor.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.LPar), Roles.LPar);
					
					if (location.Count > 2)
						newDestructor.AddChild(new CSharpTokenNode(Convert(location [2]), Roles.RPar), Roles.RPar);
				}
				
				if (d.Block != null)
					newDestructor.AddChild((BlockStatement)d.Block.Accept(this), Roles.Body);
				
				typeStack.Peek().AddChild(newDestructor, Roles.TypeMemberRole);
			}
Example #5
0
		public override void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
		{
			FormatAttributedNode(destructorDeclaration);
			
			CSharpTokenNode lParen = destructorDeclaration.LParToken;
			int offset = this.document.GetOffset(lParen.StartLocation);
			ForceSpaceBefore(offset, policy.SpaceBeforeConstructorDeclarationParentheses);
			
			if (!destructorDeclaration.Body.IsNull) {
				EnforceBraceStyle(policy.DestructorBraceStyle, destructorDeclaration.Body.LBraceToken, destructorDeclaration.Body.RBraceToken);
				VisitBlockWithoutFixingBraces(destructorDeclaration.Body, policy.IndentMethodBody);
			}
			if (IsMember(destructorDeclaration.NextSibling)) {
				EnsureBlankLinesAfter(destructorDeclaration, policy.BlankLinesBetweenMembers);
			}
		}
        public override void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
        {
            FixAttributesAndDocComment(destructorDeclaration);

            CSharpTokenNode lParen = destructorDeclaration.LParToken;
            ForceSpaceBefore(lParen, policy.SpaceBeforeConstructorDeclarationParentheses);

            if (!destructorDeclaration.Body.IsNull) {
                FixOpenBrace(policy.DestructorBraceStyle, destructorDeclaration.Body.LBraceToken);
                VisitBlockWithoutFixingBraces(destructorDeclaration.Body, policy.IndentMethodBody);
                FixClosingBrace(policy.DestructorBraceStyle, destructorDeclaration.Body.RBraceToken);
            }
        }
Example #7
0
        public void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
        {
            JsonObject declaration = CreateJsonEntityDeclaration(destructorDeclaration);
            AddKeyword(declaration, DestructorDeclaration.TildeRole);
            TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration;
            if (type != null && type.Name != destructorDeclaration.Name)
            {
                declaration.AddJsonValue("name", GetIdentifier((Identifier)type.NameToken.Clone()));
            }
            else
            {
                declaration.AddJsonValue("name", GetIdentifier(destructorDeclaration.NameToken));
            }
            declaration.AddJsonValue("body", GetMethodBody(destructorDeclaration.Body));

            Push(declaration);
        }
		DestructorDeclaration ConvertDestructor(IMethod dtor)
		{
			DestructorDeclaration decl = new DestructorDeclaration();
			decl.Name = dtor.DeclaringTypeDefinition.Name;
			return decl;
		}
Example #9
0
 public void VisitDestructorDeclaration(DestructorDeclaration node)
 {
     NotSupported(node);
 }
		public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
		{
			if (!IsClassType(ClassType.Interface) && (methodDeclaration.Modifier & Modifiers.Visibility) == 0)
				methodDeclaration.Modifier |= Modifiers.Public;
			
			if ("Finalize".Equals(methodDeclaration.Name, StringComparison.InvariantCultureIgnoreCase)
			    && methodDeclaration.Parameters.Count == 0
			    && methodDeclaration.Modifier == (Modifiers.Protected | Modifiers.Override)
			    && methodDeclaration.Body.Children.Count == 1)
			{
				TryCatchStatement tcs = methodDeclaration.Body.Children[0] as TryCatchStatement;
				if (tcs != null
				    && tcs.StatementBlock is BlockStatement
				    && tcs.CatchClauses.Count == 0
				    && tcs.FinallyBlock is BlockStatement
				    && tcs.FinallyBlock.Children.Count == 1)
				{
					ExpressionStatement se = tcs.FinallyBlock.Children[0] as ExpressionStatement;
					if (se != null) {
						InvocationExpression ie = se.Expression as InvocationExpression;
						if (ie != null
						    && ie.Arguments.Count == 0
						    && ie.TargetObject is MemberReferenceExpression
						    && (ie.TargetObject as MemberReferenceExpression).TargetObject is BaseReferenceExpression
						    && "Finalize".Equals((ie.TargetObject as MemberReferenceExpression).MemberName, StringComparison.InvariantCultureIgnoreCase))
						{
							DestructorDeclaration des = new DestructorDeclaration("Destructor", Modifiers.None, methodDeclaration.Attributes);
							ReplaceCurrentNode(des);
							des.Body = (BlockStatement)tcs.StatementBlock;
							return base.VisitDestructorDeclaration(des, data);
						}
					}
				}
			}
			
			if ((methodDeclaration.Modifier & (Modifiers.Static | Modifiers.Extern)) == Modifiers.Static
			    && methodDeclaration.Body.Children.Count == 0)
			{
				foreach (AttributeSection sec in methodDeclaration.Attributes) {
					foreach (Attribute att in sec.Attributes) {
						if ("DllImport".Equals(att.Name, StringComparison.InvariantCultureIgnoreCase)) {
							methodDeclaration.Modifier |= Modifiers.Extern;
							methodDeclaration.Body = null;
						}
					}
				}
			}
			
			if (methodDeclaration.TypeReference.Type != "System.Void" && methodDeclaration.Body.Children.Count > 0) {
				if (IsAssignmentTo(methodDeclaration.Body.Children[methodDeclaration.Body.Children.Count - 1], methodDeclaration.Name))
				{
					Expression returnValue = GetAssignmentFromStatement(methodDeclaration.Body.Children[methodDeclaration.Body.Children.Count - 1]).Right;
					methodDeclaration.Body.Children.RemoveAt(methodDeclaration.Body.Children.Count - 1);
					methodDeclaration.Body.Return(returnValue);
				} else {
					ReturnStatementForFunctionAssignment visitor = new ReturnStatementForFunctionAssignment(methodDeclaration.Name);
					methodDeclaration.Body.AcceptVisitor(visitor, null);
					if (visitor.replacementCount > 0) {
						Expression init;
						init = ExpressionBuilder.CreateDefaultValueForType(methodDeclaration.TypeReference);
						methodDeclaration.Body.Children.Insert(0, new LocalVariableDeclaration(new VariableDeclaration(FunctionReturnValueName, init, methodDeclaration.TypeReference)));
						methodDeclaration.Body.Children[0].Parent = methodDeclaration.Body;
						methodDeclaration.Body.Return(new IdentifierExpression(FunctionReturnValueName));
					}
				}
			}
			
			return base.VisitMethodDeclaration(methodDeclaration, data);
		}
		public virtual object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) {
			throw new global::System.NotImplementedException("DestructorDeclaration");
		}
Example #12
0
 private void ClassMemberDecl(Modifiers m, List<ICSharpCode.NRefactory.Parser.AST.AttributeSection> attributes)
 {
     ICSharpCode.NRefactory.Parser.AST.Statement stmt = null;
     if (this.StartOf(0x10))
     {
         this.StructMemberDecl(m, attributes);
     }
     else if (this.la.kind == 0x1b)
     {
         m.Check(Modifier.Destructors);
         Point location = this.t.Location;
         base.lexer.NextToken();
         base.Expect(1);
         DestructorDeclaration childNode = new DestructorDeclaration(this.t.val, m.Modifier, attributes);
         childNode.Modifier = m.Modifier;
         childNode.StartLocation = m.GetDeclarationLocation(location);
         base.Expect(20);
         base.Expect(0x15);
         childNode.EndLocation = this.t.EndLocation;
         if (this.la.kind == 0x10)
         {
             this.Block(out stmt);
         }
         else if (this.la.kind == 11)
         {
             base.lexer.NextToken();
         }
         else
         {
             base.SynErr(0x8a);
         }
         childNode.Body = (BlockStatement) stmt;
         base.compilationUnit.AddChild(childNode);
     }
     else
     {
         base.SynErr(0x8b);
     }
 }
		public virtual object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) {
			Debug.Assert((destructorDeclaration != null));
			Debug.Assert((destructorDeclaration.Attributes != null));
			Debug.Assert((destructorDeclaration.Body != null));
			for (int i = 0; i < destructorDeclaration.Attributes.Count; i++) {
				AttributeSection o = destructorDeclaration.Attributes[i];
				Debug.Assert(o != null);
				nodeStack.Push(o);
				o.AcceptVisitor(this, data);
				o = (AttributeSection)nodeStack.Pop();
				if (o == null)
					destructorDeclaration.Attributes.RemoveAt(i--);
				else
					destructorDeclaration.Attributes[i] = o;
			}
			nodeStack.Push(destructorDeclaration.Body);
			destructorDeclaration.Body.AcceptVisitor(this, data);
			destructorDeclaration.Body = ((BlockStatement)(nodeStack.Pop()));
			return null;
		}
 DestructorDeclaration ConvertDestructor(IMethod dtor)
 {
     DestructorDeclaration decl = new DestructorDeclaration();
     if (dtor.DeclaringTypeDefinition != null)
         decl.Name = dtor.DeclaringTypeDefinition.Name;
     if (AddResolveResultAnnotations) {
         decl.AddAnnotation(new MemberResolveResult(null, dtor));
     }
     decl.Body = GenerateBodyBlock();
     return decl;
 }
Example #15
0
        private void Process_Destructor(DestructorDeclaration node)
        {
            if (node == null) throw new ArgumentNullException("node");

            Destructor destructor = new Destructor(controller);
            destructor.Name = node.Name.Text;
            destructor.IsExtern = (node.Modifiers & Modifiers.Extern) != 0;

            ProcessBodyText(node, destructor, node.Statements, node.Comments);
            destructor.BodyText = formatter.ProcessBodyText(node.Statements, node.Comments, node.BlockStartOffset, node.BlockEndOffset - node.BlockStartOffset);

            SetupBaseConstruct(node, destructor);
        }
Example #16
0
 public override object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data)
 {
     UnlockWith(destructorDeclaration);
     return base.VisitDestructorDeclaration(destructorDeclaration, data);
 }
		public virtual object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) {
			Debug.Assert((destructorDeclaration != null));
			Debug.Assert((destructorDeclaration.Attributes != null));
			Debug.Assert((destructorDeclaration.Body != null));
			foreach (AttributeSection o in destructorDeclaration.Attributes) {
				Debug.Assert(o != null);
				o.AcceptVisitor(this, data);
			}
			return destructorDeclaration.Body.AcceptVisitor(this, data);
		}
		public virtual void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
		{
			StartNode(destructorDeclaration);
			WriteAttributes(destructorDeclaration.Attributes);
			WriteModifiers(destructorDeclaration.ModifierTokens);
			if (destructorDeclaration.ModifierTokens.Any()) {
				Space();
			}
			WriteToken(DestructorDeclaration.TildeRole);
			TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration;
			if (type != null && type.Name != destructorDeclaration.Name)
				WriteIdentifier((Identifier)type.NameToken.Clone());
			else
				WriteIdentifier(destructorDeclaration.NameToken);
			Space(policy.SpaceBeforeConstructorDeclarationParentheses);
			LPar();
			RPar();
			WriteMethodBody(destructorDeclaration.Body, policy.DestructorBraceStyle);
			EndNode(destructorDeclaration);
		}
 public override void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
 {
     base.VisitDestructorDeclaration(destructorDeclaration);
 }
 public virtual void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(destructorDeclaration);
     }
 }
		public virtual void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
		{
			StartNode(destructorDeclaration);
			WriteAttributes(destructorDeclaration.Attributes);
			WriteModifiers(destructorDeclaration.ModifierTokens);

			// Writer doesn't write the comment before destructorDeclaration if nothing has been printed yet.
			// The following code works with our added comments.
			if (destructorDeclaration.Attributes.Count == 0 && !destructorDeclaration.ModifierTokens.Any()) {
				int count = 0;
				foreach (var child in destructorDeclaration.Children) {
					if (count-- <= 0) {
						cancellationToken.ThrowIfCancellationRequested();
						count = CANCEL_CHECK_LOOP_COUNT;
					}
					var cmt = child as Comment;
					if (cmt == null)
						break;
					cmt.AcceptVisitor(this);
				}
			}

			WriteToken(DestructorDeclaration.TildeRole);
			TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration;
			var method = destructorDeclaration.Annotation<dnlib.DotNet.MethodDef>();
			var textToken = method == null ? TextTokenType.Type : TextTokenHelper.GetTextTokenType(method.DeclaringType);
			if (type != null && type.Name != destructorDeclaration.Name)
				WriteIdentifier((Identifier)type.NameToken.Clone(), textToken);
			else
				WriteIdentifier(destructorDeclaration.NameToken, textToken);
			Space(policy.SpaceBeforeConstructorDeclarationParentheses);
			LPar();
			RPar();
			WriteMethodBody(destructorDeclaration.Body);
			EndNode(destructorDeclaration);
		}
 DestructorDeclaration ConvertDestructor(IMethod dtor)
 {
     DestructorDeclaration decl = new DestructorDeclaration();
     if (dtor.DeclaringTypeDefinition != null)
         decl.Name = dtor.DeclaringTypeDefinition.Name;
     decl.Body = GenerateBodyBlock();
     return decl;
 }
Example #23
0
	void ClassMemberDecl(
#line  1054 "cs.ATG" 
ModifierList m, List<AttributeSection> attributes) {

#line  1055 "cs.ATG" 
		Statement stmt = null; 
		if (StartOf(21)) {
			StructMemberDecl(
#line  1057 "cs.ATG" 
m, attributes);
		} else if (la.kind == 27) {

#line  1058 "cs.ATG" 
			m.Check(Modifiers.Destructors); Location startPos = la.Location; 
			lexer.NextToken();
			Identifier();

#line  1059 "cs.ATG" 
			DestructorDeclaration d = new DestructorDeclaration(t.val, m.Modifier, attributes); 
			d.Modifier = m.Modifier;
			d.StartLocation = m.GetDeclarationLocation(startPos);
			
			Expect(20);
			Expect(21);

#line  1063 "cs.ATG" 
			d.EndLocation = t.EndLocation; 
			if (la.kind == 16) {
				Block(
#line  1063 "cs.ATG" 
out stmt);
			} else if (la.kind == 11) {
				lexer.NextToken();
			} else SynErr(160);

#line  1064 "cs.ATG" 
			d.Body = (BlockStatement)stmt;
			compilationUnit.AddChild(d);
			
		} else SynErr(161);
	}
Example #24
0
		public override void VisitDestructorDeclaration (DestructorDeclaration destructorDeclaration)
		{
			if (!destructorDeclaration.Body.IsNull)
				AddFolding (GetEndOfPrev(destructorDeclaration.Body.LBraceToken),
				            destructorDeclaration.Body.RBraceToken.EndLocation, true);
			base.VisitDestructorDeclaration (destructorDeclaration);
		}
Example #25
0
		public virtual void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
		{
			StartNode(destructorDeclaration);
			var builder = destructorDeclaration.Annotation<MethodDebugInfoBuilder>();
			if (builder != null)
				builder.StartPosition = writer.GetLocation();
			WriteAttributes(destructorDeclaration.Attributes);
			WriteModifiers(destructorDeclaration.ModifierTokens);
			var oldRef = currentMethodReference;
			currentMethodReference = new object();

			// Writer doesn't write the comment before destructorDeclaration if nothing has been printed yet.
			// The following code works with our added comments.
			if (destructorDeclaration.Attributes.Count == 0 && !destructorDeclaration.ModifierTokens.Any()) {
				int count = 0;
				foreach (var child in destructorDeclaration.Children) {
					if (count-- <= 0) {
						cancellationToken.ThrowIfCancellationRequested();
						count = CANCEL_CHECK_LOOP_COUNT;
					}
					var cmt = child as Comment;
					if (cmt == null)
						break;
					cmt.AcceptVisitor(this);
				}
			}

			WriteToken(DestructorDeclaration.TildeRole, BoxedTextColor.Operator);
			TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration;
			var method = destructorDeclaration.Annotation<dnlib.DotNet.MethodDef>();
			var textToken = method == null ? BoxedTextColor.Type : CSharpMetadataTextColorProvider.Instance.GetColor(method.DeclaringType);
			if (type != null && type.Name != destructorDeclaration.Name)
				WriteIdentifier((Identifier)type.NameToken.Clone(), textToken);
			else
				WriteIdentifier(destructorDeclaration.NameToken, textToken);
			Space(policy.SpaceBeforeConstructorDeclarationParentheses);
			var braceHelper = BraceHelper.LeftParen(this, CodeBracesRangeFlags.Parentheses);
			braceHelper.RightParen();
			WriteMethodBody(destructorDeclaration.Body);
			if (builder != null)
				builder.EndPosition = writer.GetLocation();
			currentMethodReference = oldRef;
			EndNode(destructorDeclaration);
		}
		public virtual void VisitDestructorDeclaration (DestructorDeclaration destructorDeclaration)
		{
			VisitChildren (destructorDeclaration);
		}
 public override void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
 {
     VisitMember(destructorDeclaration.Name);
     base.VisitDestructorDeclaration(destructorDeclaration);
 }
Example #28
0
		public void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
		{
			StartNode(destructorDeclaration);
			WriteAttributes(destructorDeclaration.Attributes);
			WriteModifiers(destructorDeclaration.ModifierTokens);
			WriteToken(DestructorDeclaration.TildeRole);
			TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration;
			StartNode(destructorDeclaration.NameToken);
			WriteIdentifier(type != null ? type.Name : destructorDeclaration.Name);
			EndNode(destructorDeclaration.NameToken);
			Space(policy.SpaceBeforeConstructorDeclarationParentheses);
			LPar();
			RPar();
			WriteMethodBody(destructorDeclaration.Body);
			EndNode(destructorDeclaration);
		}
		public sealed override object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) {
			BeginVisit(destructorDeclaration);
			object result = TrackedVisitDestructorDeclaration(destructorDeclaration, data);
			EndVisit(destructorDeclaration);
			return result;
		}