void TestParameters(DelegateDeclaration dd)
		{
			Assert.AreEqual(3, dd.Parameters.Count);
			
			Assert.AreEqual("a", ((ParameterDeclarationExpression)dd.Parameters[0]).ParameterName);
			Assert.AreEqual("System.Int32", ((ParameterDeclarationExpression)dd.Parameters[0]).TypeReference.Type);
			
			Assert.AreEqual("secondParam", ((ParameterDeclarationExpression)dd.Parameters[1]).ParameterName);
			Assert.AreEqual("System.Int32", ((ParameterDeclarationExpression)dd.Parameters[1]).TypeReference.Type);
			
			Assert.AreEqual("lastParam", ((ParameterDeclarationExpression)dd.Parameters[2]).ParameterName);
			Assert.AreEqual("MyObj", ((ParameterDeclarationExpression)dd.Parameters[2]).TypeReference.Type);
		}
		public virtual object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) {
			Debug.Assert((delegateDeclaration != null));
			Debug.Assert((delegateDeclaration.Attributes != null));
			Debug.Assert((delegateDeclaration.ReturnType != null));
			Debug.Assert((delegateDeclaration.Parameters != null));
			Debug.Assert((delegateDeclaration.Templates != null));
			foreach (AttributeSection o in delegateDeclaration.Attributes) {
				Debug.Assert(o != null);
				o.AcceptVisitor(this, data);
			}
			delegateDeclaration.ReturnType.AcceptVisitor(this, data);
			foreach (ParameterDeclarationExpression o in delegateDeclaration.Parameters) {
				Debug.Assert(o != null);
				o.AcceptVisitor(this, data);
			}
			foreach (TemplateDefinition o in delegateDeclaration.Templates) {
				Debug.Assert(o != null);
				o.AcceptVisitor(this, data);
			}
			return null;
		}
		public virtual object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) {
			throw new global::System.NotImplementedException("DelegateDeclaration");
		}
		public virtual object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) {
			Debug.Assert((delegateDeclaration != null));
			Debug.Assert((delegateDeclaration.Attributes != null));
			Debug.Assert((delegateDeclaration.ReturnType != null));
			Debug.Assert((delegateDeclaration.Parameters != null));
			Debug.Assert((delegateDeclaration.Templates != null));
			for (int i = 0; i < delegateDeclaration.Attributes.Count; i++) {
				AttributeSection o = delegateDeclaration.Attributes[i];
				Debug.Assert(o != null);
				nodeStack.Push(o);
				o.AcceptVisitor(this, data);
				o = (AttributeSection)nodeStack.Pop();
				if (o == null)
					delegateDeclaration.Attributes.RemoveAt(i--);
				else
					delegateDeclaration.Attributes[i] = o;
			}
			nodeStack.Push(delegateDeclaration.ReturnType);
			delegateDeclaration.ReturnType.AcceptVisitor(this, data);
			delegateDeclaration.ReturnType = ((TypeReference)(nodeStack.Pop()));
			for (int i = 0; i < delegateDeclaration.Parameters.Count; i++) {
				ParameterDeclarationExpression o = delegateDeclaration.Parameters[i];
				Debug.Assert(o != null);
				nodeStack.Push(o);
				o.AcceptVisitor(this, data);
				o = (ParameterDeclarationExpression)nodeStack.Pop();
				if (o == null)
					delegateDeclaration.Parameters.RemoveAt(i--);
				else
					delegateDeclaration.Parameters[i] = o;
			}
			for (int i = 0; i < delegateDeclaration.Templates.Count; i++) {
				TemplateDefinition o = delegateDeclaration.Templates[i];
				Debug.Assert(o != null);
				nodeStack.Push(o);
				o.AcceptVisitor(this, data);
				o = (TemplateDefinition)nodeStack.Pop();
				if (o == null)
					delegateDeclaration.Templates.RemoveAt(i--);
				else
					delegateDeclaration.Templates[i] = o;
			}
			return null;
		}
Exemple #5
0
	void NonModuleDeclaration(ModifierList m, List<AttributeSection> attributes) {
		TypeReference typeRef = null;
		List<TypeReference> baseInterfaces = null;

		switch (la.kind) {
		case 84: {
			m.Check(Modifiers.Classes);
			Get();
			TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
				newType.StartLocation = t.Location;
				AddChild(newType);
				BlockStart(newType);
				
				newType.Type       = ClassType.Class;

			Identifier();
			newType.Name = t.val;
			TypeParameterList(newType.Templates);
			EndOfStmt();
			newType.BodyStartLocation = t.Location;
			if (la.kind == 140) {
				ClassBaseType(out typeRef);
				SafeAdd(newType, newType.BaseTypes, typeRef);
			}
			while (la.kind == 136) {
				TypeImplementsClause(out baseInterfaces);
				newType.BaseTypes.AddRange(baseInterfaces);
			}
			ClassBody(newType);
			Expect(113);
			Expect(84);
			newType.EndLocation = t.EndLocation;
			EndOfStmt();
			BlockEnd();

			break;
		}
		case 155: {
			Get();
			m.Check(Modifiers.VBModules);
				TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
				AddChild(newType);
				BlockStart(newType);
				newType.StartLocation = m.GetDeclarationLocation(t.Location);
				newType.Type = ClassType.Module;

			Identifier();
			newType.Name = t.val;
			EndOfStmt();
			newType.BodyStartLocation = t.Location;
			ModuleBody(newType);
			BlockEnd();

			break;
		}
		case 209: {
			Get();
			m.Check(Modifiers.VBStructures);
				TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
				AddChild(newType);
				BlockStart(newType);
				newType.StartLocation = m.GetDeclarationLocation(t.Location);
				newType.Type = ClassType.Struct;

			Identifier();
			newType.Name = t.val;
			TypeParameterList(newType.Templates);
			EndOfStmt();
			newType.BodyStartLocation = t.Location;
			while (la.kind == 136) {
				TypeImplementsClause(out baseInterfaces);
				newType.BaseTypes.AddRange(baseInterfaces);
			}
			StructureBody(newType);
			BlockEnd();

			break;
		}
		case 115: {
			Get();
			m.Check(Modifiers.VBEnums);
				TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
				newType.StartLocation = m.GetDeclarationLocation(t.Location);
				AddChild(newType);
				BlockStart(newType);
				
				newType.Type = ClassType.Enum;

			Identifier();
			newType.Name = t.val;
			if (la.kind == 63) {
				Get();
				NonArrayTypeName(out typeRef, false);
				SafeAdd(newType, newType.BaseTypes, typeRef);
			}
			EndOfStmt();
			newType.BodyStartLocation = t.Location;
			EnumBody(newType);
			BlockEnd();

			break;
		}
		case 142: {
			Get();
			m.Check(Modifiers.VBInterfacs);
				TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
				newType.StartLocation = m.GetDeclarationLocation(t.Location);
				AddChild(newType);
				BlockStart(newType);
				newType.Type = ClassType.Interface;

			Identifier();
			newType.Name = t.val;
			TypeParameterList(newType.Templates);
			EndOfStmt();
			newType.BodyStartLocation = t.Location;
			while (la.kind == 140) {
				InterfaceBase(out baseInterfaces);
				newType.BaseTypes.AddRange(baseInterfaces);
			}
			InterfaceBody(newType);
			BlockEnd();

			break;
		}
		case 103: {
			Get();
			m.Check(Modifiers.VBDelegates);
				DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes);
				delegateDeclr.ReturnType = new TypeReference("System.Void", true);
				delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location);
				List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();

			if (la.kind == 210) {
				Get();
				Identifier();
				delegateDeclr.Name = t.val;
				TypeParameterList(delegateDeclr.Templates);
				if (la.kind == 37) {
					Get();
					if (StartOf(7)) {
						FormalParameterList(p);
					}
					Expect(38);
					delegateDeclr.Parameters = p;
				}
			} else if (la.kind == 127) {
				Get();
				Identifier();
				delegateDeclr.Name = t.val;
				TypeParameterList(delegateDeclr.Templates);
				if (la.kind == 37) {
					Get();
					if (StartOf(7)) {
						FormalParameterList(p);
					}
					Expect(38);
					delegateDeclr.Parameters = p;
				}
				if (la.kind == 63) {
					Get();
					TypeReference type;
					TypeName(out type);
					delegateDeclr.ReturnType = type;
				}
			} else SynErr(251);
			delegateDeclr.EndLocation = t.EndLocation;
			EndOfStmt();
			AddChild(delegateDeclr);

			break;
		}
		default: SynErr(252); break;
		}
	}
		void TestDelegateDeclaration(DelegateDeclaration dd)
		{
			Assert.AreEqual("System.Void", dd.ReturnType.Type);
			Assert.AreEqual("MyDelegate", dd.Name);
		}
		public virtual object TrackedVisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) {
			return base.VisitDelegateDeclaration(delegateDeclaration, data);
		}
		public sealed override object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) {
			this.BeginVisit(delegateDeclaration);
			object result = this.TrackedVisitDelegateDeclaration(delegateDeclaration, data);
			this.EndVisit(delegateDeclaration);
			return result;
		}
		public override object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
		{
			CodeTypeDelegate codeTypeDelegate = new CodeTypeDelegate(delegateDeclaration.Name);
			codeTypeDelegate.Attributes = ConvMemberAttributes(delegateDeclaration.Modifier);
			codeTypeDelegate.ReturnType = ConvType(delegateDeclaration.ReturnType);

			foreach (ParameterDeclarationExpression parameter in delegateDeclaration.Parameters)
			{
				codeTypeDelegate.Parameters.Add((CodeParameterDeclarationExpression)VisitParameterDeclarationExpression(parameter, data));
			}

			if (typeDeclarations.Count > 0)
			{
				typeDeclarations.Peek().Members.Add(codeTypeDelegate);
			}
			else
			{
				namespaceDeclarations.Peek().Types.Add(codeTypeDelegate);
			}

			return null;
		}