private void InjectStaticInitializerIfNoneSpecified(TypeNode typeNode){ if (typeNode.NodeType == NodeType.EnumNode) return; MemberList staticCons = typeNode.GetMembersNamed(StandardIds.CCtor); if (staticCons != null && staticCons.Count > 0) return; StatementList statements = null; MemberList members = typeNode.Members; for (int i = 0, n = members == null ? 0 : members.Count; i < n; i++){ Field f = members[i] as Field; if (f == null) continue; if (!f.IsStatic) continue; if (f.IsLiteral) continue; if (f.Initializer == null) continue; statements = new StatementList(1); break; } if (statements == null && typeNode.Contract != null && typeNode.Contract.FrameField != null) statements = new StatementList(1); if (statements != null){ FieldInitializerBlock finitBlock = new FieldInitializerBlock(typeNode, true); statements.Add(finitBlock); StaticInitializer cctor = new StaticInitializer(typeNode, null, new Block(statements)); typeNode.Members.Add(cctor); if (typeNode.PartiallyDefines != null){ staticCons = typeNode.PartiallyDefines.GetMembersNamed(StandardIds.CCtor); if (staticCons == null || staticCons.Count == 0){ finitBlock.Type = typeNode.PartiallyDefines; cctor.DeclaringType = typeNode.PartiallyDefines; typeNode.PartiallyDefines.Members.Add(cctor); } } } }
public virtual Block VisitFieldInitializerBlock(FieldInitializerBlock block) { if (block == null) return null; block.Type = this.VisitTypeReference(block.Type); return this.VisitBlock(block); }
public override Block VisitFieldInitializerBlock(FieldInitializerBlock block) { // TODO: is this ever interesting?? return base.VisitFieldInitializerBlock(block); }
public override Block VisitFieldInitializerBlock(FieldInitializerBlock block) { if (block == null) return null; return base.VisitFieldInitializerBlock((FieldInitializerBlock)block.Clone()); }
public EventingVisitor(Action<FieldInitializerBlock> visitFieldInitializerBlock) { VisitedFieldInitializerBlock += visitFieldInitializerBlock; } public event Action<FieldInitializerBlock> VisitedFieldInitializerBlock; public override Block VisitFieldInitializerBlock(FieldInitializerBlock block) { if (VisitedFieldInitializerBlock != null) VisitedFieldInitializerBlock(block); return base.VisitFieldInitializerBlock(block); }