Exemplo n.º 1
0
 public override void LeaveCallableDefinition(CallableDefinition node)
 {
     MakeStaticIfNeeded(node);
     CantBeMarkedAbstract(node);
     CantBeMarkedTransient(node);
     CantBeMarkedPartial(node);
 }
Exemplo n.º 2
0
		override public void OnCallableDefinition(CallableDefinition node)
		{
			CompleteOmittedReturnType(node);
			CompleteOmittedParameterTypes(node);

			ClassDefinition cd = My<CallableTypeBuilder>.Instance.ForCallableDefinition(node);
			ReplaceCurrentNode(cd);
		}
Exemplo n.º 3
0
		public ClassDefinition ForCallableDefinition(CallableDefinition node)
		{
			ClassDefinition cd = CreateEmptyCallableDefinition(node.Name);
			cd.LexicalInfo = node.LexicalInfo;
			cd.GenericParameters = node.GenericParameters;

			cd.Members.Add(CreateInvokeMethod(node));
			cd.Members.Add(CreateBeginInvokeMethod(node));
			cd.Members.Add(CreateEndInvokeMethod(node));

			return cd;
		}
Exemplo n.º 4
0
		private void CompleteOmittedParameterTypes(CallableDefinition node)
		{
			ParameterDeclarationCollection parameters = node.Parameters;
			if (parameters.Count == 0)
				return;

			foreach (ParameterDeclaration parameter in parameters)
			{
				if (parameter.Type != null)
					continue;

				parameter.Type = CodeBuilder.CreateTypeReference(
					parameter.IsParamArray
						? TypeSystemServices.ObjectArrayType
						: TypeSystemServices.ObjectType);
			}
		}
Exemplo n.º 5
0
 public object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
 {
     B.CallableDefinition cd = new B.CallableDefinition(GetLexicalInfo(delegateDeclaration));
     cd.Name = delegateDeclaration.Name;
     ConvertAttributes(delegateDeclaration.Attributes, cd.Attributes);
     cd.Modifiers = ConvertModifier(delegateDeclaration, B.TypeMemberModifiers.Private);
     ConvertParameters(delegateDeclaration.Parameters, cd.Parameters);
     cd.ReturnType = ConvertTypeReference(delegateDeclaration.ReturnType);
     if (currentType != null)
     {
         currentType.Members.Add(cd);
     }
     else
     {
         module.Members.Add(cd);
     }
     return(cd);
 }
        public override void OnCallableDefinition(CallableDefinition node)
        {
            if (null == node.ReturnType)
            {
                node.ReturnType = CodeBuilder.CreateTypeReference(TypeSystemServices.VoidType);
            }

            CompleteOmittedParameterType(node);

            ClassDefinition cd = TypeSystemServices.CreateCallableDefinition(node.Name);
            cd.LexicalInfo = node.LexicalInfo;
            cd.GenericParameters = node.GenericParameters;

            cd.Members.Add(CreateInvokeMethod(node));
            cd.Members.Add(CreateBeginInvokeMethod(node));
            cd.Members.Add(CreateEndInvokeMethod(node));

            ReplaceCurrentNode(cd);
        }
Exemplo n.º 7
0
        override public object Clone()
        {
            CallableDefinition clone = (CallableDefinition)FormatterServices.GetUninitializedObject(typeof(CallableDefinition));

            clone._lexicalInfo       = _lexicalInfo;
            clone._endSourceLocation = _endSourceLocation;
            clone._documentation     = _documentation;
            clone._isSynthetic       = _isSynthetic;
            clone._entity            = _entity;
            if (_annotations != null)
            {
                clone._annotations = (Hashtable)_annotations.Clone();
            }

            clone._modifiers = _modifiers;
            clone._name      = _name;
            if (null != _attributes)
            {
                clone._attributes = _attributes.Clone() as AttributeCollection;
                clone._attributes.InitializeParent(clone);
            }
            if (null != _parameters)
            {
                clone._parameters = _parameters.Clone() as ParameterDeclarationCollection;
                clone._parameters.InitializeParent(clone);
            }
            if (null != _genericParameters)
            {
                clone._genericParameters = _genericParameters.Clone() as GenericParameterDeclarationCollection;
                clone._genericParameters.InitializeParent(clone);
            }
            if (null != _returnType)
            {
                clone._returnType = _returnType.Clone() as TypeReference;
                clone._returnType.InitializeParent(clone);
            }
            if (null != _returnTypeAttributes)
            {
                clone._returnTypeAttributes = _returnTypeAttributes.Clone() as AttributeCollection;
                clone._returnTypeAttributes.InitializeParent(clone);
            }
            return(clone);
        }
        private void CompleteOmittedParameterType(CallableDefinition node)
        {
            ParameterDeclarationCollection parameters = node.Parameters;
            if (0 == parameters.Count) return;

            ParameterDeclaration last = parameters[-1];
            foreach (ParameterDeclaration parameter in parameters)
            {
                if (null == parameter.Type)
                {
                    if (parameters.VariableNumber && last == parameter)
                    {
                        parameter.Type = CodeBuilder.CreateTypeReference(TypeSystemServices.ObjectArrayType);
                    }
                    else
                    {
                        parameter.Type = CodeBuilder.CreateTypeReference(TypeSystemServices.ObjectType);
                    }
                }
            }
        }
Exemplo n.º 9
0
        public override void OnCallableDefinition(AST.CallableDefinition node)
        {
            LoggingService.Debug("OnCallableDefinition: " + node.FullName);
            DomRegion    region = GetRegion(node);
            DefaultClass c      = new DefaultClass(_cu, ClassType.Delegate, GetModifier(node), region, OuterClass);

            ConvertAttributes(node, c);
            c.BaseTypes.Add(c.ProjectContent.SystemTypes.Delegate);
            c.FullyQualifiedName = node.FullName;
            if (_currentClass.Count > 0)
            {
                OuterClass.InnerClasses.Add(c);
            }
            else
            {
                _cu.Classes.Add(c);
            }
            _currentClass.Push(c);             // necessary for CreateReturnType
            ConvertTemplates(node, c);
            IReturnType   returnType   = CreateReturnType(node.ReturnType);
            DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c);

            ConvertParameters(node.Parameters, invokeMethod);
            c.Methods.Add(invokeMethod);
            invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c);
            ConvertParameters(node.Parameters, invokeMethod);
            if (invokeMethod.Parameters == DefaultParameter.EmptyParameterList)
            {
                invokeMethod.Parameters = new List <IParameter>();
            }
            invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty));
            invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty));
            c.Methods.Add(invokeMethod);
            invokeMethod = new DefaultMethod("EndInvoke", returnType, ModifierEnum.Public, DomRegion.Empty, DomRegion.Empty, c);
            invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty));
            c.Methods.Add(invokeMethod);
            _currentClass.Pop();
        }
Exemplo n.º 10
0
 public override void OnCallableDefinition(CallableDefinition node)
 {
     NotImplemented(node, "Unexpected callable definition!");
 }
Exemplo n.º 11
0
		public object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
		{
			B.CallableDefinition cd = new B.CallableDefinition(GetLexicalInfo(delegateDeclaration));
			cd.Name = delegateDeclaration.Name;
			ConvertAttributes(delegateDeclaration.Attributes, cd.Attributes);
			cd.Modifiers = ConvertModifier(delegateDeclaration, B.TypeMemberModifiers.Private);
			ConvertParameters(delegateDeclaration.Parameters, cd.Parameters);
			cd.ReturnType = ConvertTypeReference(delegateDeclaration.ReturnType);
			if (currentType != null)
				currentType.Members.Add(cd);
			else
				module.Members.Add(cd);
			return cd;
		}
Exemplo n.º 12
0
		Method CreateBeginInvokeMethod(CallableDefinition node)
		{
			Method method = CreateRuntimeMethod("BeginInvoke",
						CodeBuilder.CreateTypeReference(node.LexicalInfo, typeof(IAsyncResult)));
			method.Parameters.ExtendWithClones(node.Parameters);
			method.Parameters.Add(
				new ParameterDeclaration("callback",
					CodeBuilder.CreateTypeReference(node.LexicalInfo, typeof(AsyncCallback))));
			method.Parameters.Add(
				new ParameterDeclaration("asyncState",
					CodeBuilder.CreateTypeReference(node.LexicalInfo, TypeSystemServices.ObjectType)));
			return method;
		}
Exemplo n.º 13
0
		Method CreateInvokeMethod(CallableDefinition node)
		{
			Method method = CreateRuntimeMethod("Invoke", node.ReturnType);
			method.Parameters = node.Parameters;
			return method;
		}
Exemplo n.º 14
0
		Method CreateEndInvokeMethod(CallableDefinition node)
		{
			Method method = CreateRuntimeMethod("EndInvoke", node.ReturnType);

			foreach (ParameterDeclaration p in node.Parameters)
				if (p.IsByRef)
					method.Parameters.Add(p.CloneNode());

			method.Parameters.Add(
				new ParameterDeclaration("asyncResult",
					CodeBuilder.CreateTypeReference(node.LexicalInfo, typeof(IAsyncResult))));
			return method;
		}
Exemplo n.º 15
0
 public override void OnCallableDefinition(CallableDefinition node)
 {
     WriteCallableDefinitionHeader("callable ", node);
 }
Exemplo n.º 16
0
	protected void callable_definition(
		TypeMemberCollection container
	) //throws RecognitionException, TokenStreamException
{
		
		IToken  id = null;
		
				CallableDefinition cd = null;
				TypeReference returnType = null;
				GenericParameterDeclarationCollection genericParameters = null;
			
		
		try {      // for error handling
			match(CALLABLE);
			id = LT(1);
			match(ID);
			if (0==inputState.guessing)
			{
				
						cd = new CallableDefinition(ToLexicalInfo(id));
						cd.Name = id.getText();
						cd.Modifiers = _modifiers;
						AddAttributes(cd.Attributes);
						container.Add(cd);
						genericParameters = cd.GenericParameters;
					
			}
			{
				switch ( LA(1) )
				{
				case LBRACK:
				{
					match(LBRACK);
					{
						switch ( LA(1) )
						{
						case OF:
						{
							match(OF);
							break;
						}
						case ID:
						{
							break;
						}
						default:
						{
							throw new NoViableAltException(LT(1), getFilename());
						}
						 }
					}
					generic_parameter_declaration_list(genericParameters);
					match(RBRACK);
					break;
				}
				case LPAREN:
				{
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				 }
			}
			match(LPAREN);
			parameter_declaration_list(cd.Parameters);
			match(RPAREN);
			{
				switch ( LA(1) )
				{
				case AS:
				{
					match(AS);
					returnType=type_reference();
					if (0==inputState.guessing)
					{
						cd.ReturnType=returnType;
					}
					break;
				}
				case EOL:
				case EOS:
				{
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				 }
			}
			eos();
			docstring(cd);
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "callable_definition");
				recover(ex,tokenSet_22_);
			}
			else
			{
				throw ex;
			}
		}
	}
Exemplo n.º 17
0
		private void CompleteOmittedReturnType(CallableDefinition node)
		{
			if (node.ReturnType == null)
				node.ReturnType = CodeBuilder.CreateTypeReference(TypeSystemServices.VoidType);
		}
Exemplo n.º 18
0
		public override void OnCallableDefinition(CallableDefinition node) { }
Exemplo n.º 19
0
		override public object Clone()
		{
		
			CallableDefinition clone = new CallableDefinition();
			clone._lexicalInfo = _lexicalInfo;
			clone._endSourceLocation = _endSourceLocation;
			clone._documentation = _documentation;
			clone._isSynthetic = _isSynthetic;
			clone._entity = _entity;
			if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone();
			clone._modifiers = _modifiers;
			clone._name = _name;
			if (null != _attributes)
			{
				clone._attributes = _attributes.Clone() as AttributeCollection;
				clone._attributes.InitializeParent(clone);
			}
			if (null != _parameters)
			{
				clone._parameters = _parameters.Clone() as ParameterDeclarationCollection;
				clone._parameters.InitializeParent(clone);
			}
			if (null != _genericParameters)
			{
				clone._genericParameters = _genericParameters.Clone() as GenericParameterDeclarationCollection;
				clone._genericParameters.InitializeParent(clone);
			}
			if (null != _returnType)
			{
				clone._returnType = _returnType.Clone() as TypeReference;
				clone._returnType.InitializeParent(clone);
			}
			if (null != _returnTypeAttributes)
			{
				clone._returnTypeAttributes = _returnTypeAttributes.Clone() as AttributeCollection;
				clone._returnTypeAttributes.InitializeParent(clone);
			}
			return clone;


		}
Exemplo n.º 20
0
        void WriteCallableDefinitionHeader(string keyword, CallableDefinition node)
        {
            WriteAttributes(node.Attributes, true);
            WriteOptionalModifiers(node);

            WriteKeyword(keyword);

            IExplicitMember em = node as IExplicitMember;
            if (null != em)
            {
                Visit(em.ExplicitInfo);
            }
            Write(node.Name);
            if (node.GenericParameters.Count > 0)
            {
                WriteGenericParameterList(node.GenericParameters);
            }
            WriteParameterList(node.Parameters);
            if (node.ReturnTypeAttributes.Count > 0)
            {
                Write(" ");
                WriteAttributes(node.ReturnTypeAttributes, false);
            }
            WriteTypeReference(node.ReturnType);
        }