public object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data)
        {
            B.Constructor m = new B.Constructor(GetLexicalInfo(constructorDeclaration));
            m.Modifiers = ConvertModifier(constructorDeclaration, B.TypeMemberModifiers.Private);
            ConvertAttributes(constructorDeclaration.Attributes, m.Attributes);
            if (currentType != null)
            {
                currentType.Members.Add(m);
            }
            ConvertParameters(constructorDeclaration.Parameters, m.Parameters);
            m.EndSourceLocation = GetEndLocation((INode)constructorDeclaration.Body ?? constructorDeclaration);
            m.Body = ConvertMethodBlock(constructorDeclaration.Body);
            ConstructorInitializer ci = constructorDeclaration.ConstructorInitializer;

            if (ci != null && !ci.IsNull)
            {
                B.Expression initializerBase;
                if (ci.ConstructorInitializerType == ConstructorInitializerType.Base)
                {
                    initializerBase = new B.SuperLiteralExpression();
                }
                else
                {
                    initializerBase = new B.SelfLiteralExpression();
                }
                B.MethodInvocationExpression initializer = new B.MethodInvocationExpression(initializerBase);
                ConvertExpressions(ci.Arguments, initializer.Arguments);
                m.Body.Insert(0, new B.ExpressionStatement(initializer));
            }
            return(m);
        }
Ejemplo n.º 2
0
 public static Constructor CreateConstructor(Node lexicalInfoProvider, TypeMemberModifiers modifiers)
 {
     Constructor constructor = new Constructor(lexicalInfoProvider.LexicalInfo);
     constructor.Modifiers = modifiers;
     constructor.IsSynthetic = true;
     return constructor;
 }
 public override void LeaveConstructor(Constructor node)
 {
     if (!node.IsVisibilitySet)
     {
         node.Modifiers |= TypeMemberModifiers.Public;
     }
 }
Ejemplo n.º 4
0
        // create a constructor that delegate to the base class
        private void AddConstructor(ClassDefinition macro)
        {
            var ctor = new Constructor(macro.LexicalInfo);

            ctor.Parameters.Add(
                new ParameterDeclaration("viewEngine",
                                         new SimpleTypeReference("MvcContrib.BrailViewEngine.BooViewEngine"))); // TODO: Update Reference

            //			ctor.Parameters.Add(
            //				new ParameterDeclaration("output",
            //				                         new SimpleTypeReference("System.IO.TextWriter")));
            //			ctor.Parameters.Add(
            //				new ParameterDeclaration("context",
            //				                         new SimpleTypeReference("Castle.MonoRail.Framework.IEngineContext")));
            //
            //			ctor.Parameters.Add(
            //				new ParameterDeclaration("__controller",
            //				                         new SimpleTypeReference("Castle.MonoRail.Framework.IController")));
            //
            //			ctor.Parameters.Add(
            //				new ParameterDeclaration("__controllerContext",
            //										 new SimpleTypeReference("Castle.MonoRail.Framework.IControllerContext")));

            var mie = new MethodInvocationExpression(new SuperLiteralExpression());
            mie.Arguments.Add(AstUtil.CreateReferenceExpression("viewEngine"));
            //			mie.Arguments.Add(AstUtil.CreateReferenceExpression("output"));
            //			mie.Arguments.Add(AstUtil.CreateReferenceExpression("context"));
            //			mie.Arguments.Add(AstUtil.CreateReferenceExpression("__controller"));
            //			mie.Arguments.Add(AstUtil.CreateReferenceExpression("__controllerContext"));

            ctor.Body.Add(mie);

            macro.Members.Add(ctor);
        }
        public override void LeaveConstructor(Constructor node)
        {
            if (node.IsVisibilitySet) return;

            if (!node.IsStatic)
                node.Modifiers |= Context.Parameters.DefaultMethodVisibility;
            else
                node.Modifiers |= TypeMemberModifiers.Private;
        }
Ejemplo n.º 6
0
 public override void LeaveConstructor(Constructor node)
 {
     MakeStaticIfNeeded(node);
     CantBeMarkedTransient(node);
     CantBeMarkedPartial(node);
     CantBeMarkedFinal(node);
     CannotReturnValue(node);
     ConstructorCannotBePolymorphic(node);
 }
Ejemplo n.º 7
0
        public override void OnConstructor(AST.Constructor node)
        {
            if (node.IsSynthetic && node.Parameters.Count == 0)
            {
                return;
            }
            Constructor ctor = new Constructor(GetModifier(node), GetRegion(node), GetClientRegion(node), OuterClass);

            ConvertAttributes(node, ctor);
            ConvertParameters(node.Parameters, ctor);
            _currentClass.Peek().Methods.Add(ctor);
            ctor.UserData = node;
        }
Ejemplo n.º 8
0
		private void GenerateConstructors(TypeDefinition definition)
		{
			ConstructorInfo[] ctors =
				baseClass.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
			foreach (ConstructorInfo ctor in ctors)
			{
				if (ctor.IsPrivate)
					continue;
				Constructor constructor = new Constructor(definition.LexicalInfo);
				definition.Members.Add(constructor);
				MethodInvocationExpression super = new MethodInvocationExpression(new SuperLiteralExpression());
				constructor.Body.Add(super);
				foreach (ParameterInfo info in ctor.GetParameters())
				{
					SimpleTypeReference typeReference =
						new SimpleTypeReference(TypeUtilities.GetFullName(info.ParameterType));
					constructor.Parameters.Add(new ParameterDeclaration(info.Name,
																		typeReference)
						);
					super.Arguments.Add(new ReferenceExpression(info.Name));
				}
			}
		}
Ejemplo n.º 9
0
        public override bool EnterConstructor(Constructor node)
        {
            base.EnterConstructor(node);

            return EnterMethod(node);
        }
Ejemplo n.º 10
0
        public override void LeaveConstructor(Constructor node)
        {
            base.LeaveConstructor(node);

            LeaveMethod(node);
        }
Ejemplo n.º 11
0
 public override void OnConstructor(Constructor node)
 {
     Visit(node.Parameters);
     _emitter.EmitConstructorAttributes(node);
 }
Ejemplo n.º 12
0
        public override void OnConstructor(Constructor constructor)
        {
            if (constructor.IsRuntime) return;

            ConstructorBuilder builder = GetConstructorBuilder(constructor);
            EmitMethod(constructor, builder.GetILGenerator());
        }
Ejemplo n.º 13
0
 void EmitConstructorAttributes(Constructor node)
 {
     ConstructorBuilder builder = (ConstructorBuilder)GetBuilder(node);
     EmitAttributes(node, builder.SetCustomAttribute);
 }
Ejemplo n.º 14
0
 public static CompilerError InstanceMethodInvocationBeforeInitialization(Constructor ctor, MemberReferenceExpression mre)
 {
     return Instantiate("BCE0158", mre, mre.Name, SelfKeyword);
 }
Ejemplo n.º 15
0
 private IMethod EntityFor(Constructor node)
 {
     return (IMethod)EntityFor((TypeMember)node);
 }
Ejemplo n.º 16
0
        //ECMA-335 Partition III Section 1.8.1.4
        //cannot call an instance method before super/self.
        void CheckInstanceMethodInvocationsWithinConstructor(Constructor ctor)
        {
            if (ctor.Body.IsEmpty)
                return;

            foreach (Statement st in ctor.Body.Statements)
            {
                ExpressionStatement est = st as ExpressionStatement;
                if (null == est) continue;

                MethodInvocationExpression mie = est.Expression as MethodInvocationExpression;
                if (null == mie) continue;

                if (mie.Target is SelfLiteralExpression
                    || mie.Target is SuperLiteralExpression)
                    break;//okay we're done checking

                if (mie.Target is MemberReferenceExpression)
                {
                    MemberReferenceExpression mre = (MemberReferenceExpression) mie.Target;
                    if (mre.Target is SelfLiteralExpression
                        || mre.Target is SuperLiteralExpression)
                    {
                        Error(CompilerErrorFactory.InstanceMethodInvocationBeforeInitialization(ctor, mre));
                    }
                }
            }
        }
		public object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data)
		{
			B.Constructor m = new B.Constructor(GetLexicalInfo(constructorDeclaration));
			m.Modifiers = ConvertModifier(constructorDeclaration, B.TypeMemberModifiers.Private);
			ConvertAttributes(constructorDeclaration.Attributes, m.Attributes);
			if (currentType != null) currentType.Members.Add(m);
			ConvertParameters(constructorDeclaration.Parameters, m.Parameters);
			m.EndSourceLocation = GetEndLocation((INode)constructorDeclaration.Body ?? constructorDeclaration);
			m.Body = ConvertMethodBlock(constructorDeclaration.Body);
			ConstructorInitializer ci = constructorDeclaration.ConstructorInitializer;
			if (ci != null && !ci.IsNull) {
				B.Expression initializerBase;
				if (ci.ConstructorInitializerType == ConstructorInitializerType.Base)
					initializerBase = new B.SuperLiteralExpression();
				else
					initializerBase = new B.SelfLiteralExpression();
				B.MethodInvocationExpression initializer = new B.MethodInvocationExpression(initializerBase);
				ConvertExpressions(ci.Arguments, initializer.Arguments);
				m.Body.Insert(0, new B.ExpressionStatement(initializer));
			}
			return m;
		}
Ejemplo n.º 18
0
 public override void LeaveConstructor(Constructor node)
 {
     LeaveMember(node);
 }
Ejemplo n.º 19
0
 public override void OnConstructor(Constructor node)
 {
     CheckExtensionSemantics(node);
 }
Ejemplo n.º 20
0
 public override void OnConstructor(Constructor node)
 {
     if (null == node.Entity)
     {
         node.Entity = new InternalConstructor(TypeSystemServices, node);
     }
     _parameters.Add(node);
 }
Ejemplo n.º 21
0
 public override void OnConstructor(Constructor node)
 {
     OnMethod(node);
 }
Ejemplo n.º 22
0
	protected void method(
		TypeMemberCollection container
	) //throws RecognitionException, TokenStreamException
{
		
		IToken  t = null;
		IToken  spliceBegin = null;
		IToken  c = null;
		IToken  d = null;
		IToken  cc = null;
		IToken  dd = null;
		
				Method m = null;
				TypeReference rt = null;
				TypeReference it = null;
				ExplicitMemberInfo emi = null;
				ParameterDeclarationCollection parameters = null;
				GenericParameterDeclarationCollection genericParameters = null;
				Block body = null;
				StatementCollection statements = null;
				Expression nameSplice = null;
				TypeMember typeMember = null;
				IToken id = null;
			
		
		try {      // for error handling
			{
				switch ( LA(1) )
				{
				case DEF:
				{
					t = LT(1);
					match(DEF);
					{
						switch ( LA(1) )
						{
						case EVENT:
						case GET:
						case INTERNAL:
						case PUBLIC:
						case PROTECTED:
						case REF:
						case SET:
						case YIELD:
						case ID:
						case SPLICE_BEGIN:
						{
							{
								{
									{
										if ((LA(1)==ID) && (LA(2)==DOT))
										{
											emi=explicit_member_info();
										}
										else if ((tokenSet_33_.member(LA(1))) && (tokenSet_34_.member(LA(2)))) {
										}
										else
										{
											throw new NoViableAltException(LT(1), getFilename());
										}
										
									}
									{
										switch ( LA(1) )
										{
										case EVENT:
										case GET:
										case INTERNAL:
										case PUBLIC:
										case PROTECTED:
										case REF:
										case SET:
										case YIELD:
										case ID:
										{
											id=member();
											break;
										}
										case SPLICE_BEGIN:
										{
											spliceBegin = LT(1);
											match(SPLICE_BEGIN);
											nameSplice=atom();
											break;
										}
										default:
										{
											throw new NoViableAltException(LT(1), getFilename());
										}
										 }
									}
								}
								if (0==inputState.guessing)
								{
									
														IToken token = id ?? spliceBegin;
														if (emi != null) {
															m = new Method(emi.LexicalInfo);
														} else {
															m = new Method(ToLexicalInfo(token));
														}
														m.Name = token.getText();
														m.ExplicitInfo  = emi;
														
														if (nameSplice != null) {
															typeMember = new SpliceTypeMember(m, nameSplice);
														} else {
															typeMember = m;
														}
													
								}
							}
							break;
						}
						case CONSTRUCTOR:
						{
							c = LT(1);
							match(CONSTRUCTOR);
							if (0==inputState.guessing)
							{
								typeMember = m = new Constructor(ToLexicalInfo(c));
							}
							break;
						}
						case DESTRUCTOR:
						{
							d = LT(1);
							match(DESTRUCTOR);
							if (0==inputState.guessing)
							{
								typeMember = m = new Destructor(ToLexicalInfo(d));
							}
							break;
						}
						default:
						{
							throw new NoViableAltException(LT(1), getFilename());
						}
						 }
					}
					break;
				}
				case CONSTRUCTOR:
				{
					cc = LT(1);
					match(CONSTRUCTOR);
					if (0==inputState.guessing)
					{
						typeMember = m = new Constructor(ToLexicalInfo(cc));
					}
					break;
				}
				case DESTRUCTOR:
				{
					dd = LT(1);
					match(DESTRUCTOR);
					if (0==inputState.guessing)
					{
						typeMember = m = new Destructor(ToLexicalInfo(dd));
					}
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				 }
			}
			if (0==inputState.guessing)
			{
				
						m.Modifiers = _modifiers;
						AddAttributes(m.Attributes);
						parameters = m.Parameters;
						genericParameters = m.GenericParameters;
						body = m.Body;
						statements = body.Statements;
					
			}
			{
				if ((LA(1)==LBRACK) && (LA(2)==OF||LA(2)==ID))
				{
					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);
				}
				else if ((tokenSet_35_.member(LA(1))) && (tokenSet_36_.member(LA(2)))) {
				}
				else
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				
			}
			{
				switch ( LA(1) )
				{
				case LPAREN:
				{
					match(LPAREN);
					parameter_declaration_list(parameters);
					match(RPAREN);
					break;
				}
				case AS:
				case LBRACK:
				case COLON:
				{
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				 }
			}
			attributes();
			if (0==inputState.guessing)
			{
				AddAttributes(m.ReturnTypeAttributes);
			}
			{
				switch ( LA(1) )
				{
				case AS:
				{
					match(AS);
					rt=type_reference();
					if (0==inputState.guessing)
					{
						m.ReturnType = rt;
					}
					break;
				}
				case COLON:
				{
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				 }
			}
			begin_block_with_doc(m, body);
			block(statements);
			end(body);
			if (0==inputState.guessing)
			{
				
						container.Add(typeMember);
						m.EndSourceLocation = body.EndSourceLocation;
					
			}
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "method");
				recover(ex,tokenSet_22_);
			}
			else
			{
				throw ex;
			}
		}
	}
Ejemplo n.º 23
0
 public Constructor CreateConstructor(TypeMemberModifiers modifiers)
 {
     Constructor constructor = new Constructor();
     constructor.Modifiers = modifiers;
     constructor.IsSynthetic = true;
     EnsureEntityFor(constructor);
     return constructor;
 }
Ejemplo n.º 24
0
 void ConstructorCannotBePolymorphic(Constructor node)
 {
     if (node.IsAbstract || node.IsOverride || node.IsVirtual)
     {
         Error(CompilerErrorFactory.ConstructorCantBePolymorphic(node, EntityFor(node)));
     }
 }
Ejemplo n.º 25
0
        public BooMethodBuilder AddConstructor()
        {
            Constructor constructor = new Constructor();
            constructor.IsSynthetic = true;
            constructor.Modifiers = TypeMemberModifiers.Public;
            constructor.Entity = new InternalConstructor(_codeBuilder.TypeSystemServices, constructor);
            _cd.Members.Add(constructor);

            return new BooMethodBuilder(_codeBuilder, constructor);
        }
Ejemplo n.º 26
0
        //throws RecognitionException, TokenStreamException
        protected void method(
            TypeMemberCollection container
            )
        {
            IToken  t = null;
            IToken  c = null;
            IToken  d = null;

                Method m = null;
                TypeReference rt = null;
                TypeReference it = null;
                ExplicitMemberInfo emi = null;
                ParameterDeclarationCollection parameters = null;
                GenericParameterDeclarationCollection genericParameters = null;
                Block body = null;
                StatementCollection statements = null;
                IToken id = null;

            try {      // for error handling
            t = LT(1);
            match(DEF);
            {
                switch ( LA(1) )
                {
                case EVENT:
                case GET:
                case INTERNAL:
                case PUBLIC:
                case PROTECTED:
                case REF:
                case SET:
                case ID:
                {
                    {
                        if ((LA(1)==ID) && (LA(2)==DOT))
                        {
                            emi=explicit_member_info();
                        }
                        else if ((tokenSet_27_.member(LA(1))) && (LA(2)==LPAREN||LA(2)==LBRACK)) {
                        }
                        else
                        {
                            throw new NoViableAltException(LT(1), getFilename());
                        }

                    }
                    id=member();
                    if (0==inputState.guessing)
                    {

                                    if (emi != null)
                                    {
                                        m = new Method(emi.LexicalInfo);
                                    }
                                    else
                                    {
                                        m = new Method(SourceLocationFactory.ToLexicalInfo(id));
                                    }
                                    m.Name = id.getText();
                                    m.ExplicitInfo  = emi;

                    }
                    break;
                }
                case CONSTRUCTOR:
                {
                    c = LT(1);
                    match(CONSTRUCTOR);
                    if (0==inputState.guessing)
                    {
                        m = new Constructor(SourceLocationFactory.ToLexicalInfo(c));
                    }
                    break;
                }
                case DESTRUCTOR:
                {
                    d = LT(1);
                    match(DESTRUCTOR);
                    if (0==inputState.guessing)
                    {
                        m = new Destructor(SourceLocationFactory.ToLexicalInfo(d));
                    }
                    break;
                }
                default:
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }
                 }
            }
            if (0==inputState.guessing)
            {

                        m.Modifiers = _modifiers;
                        AddAttributes(m.Attributes);
                        parameters = m.Parameters;
                        genericParameters = m.GenericParameters;
                        body = m.Body;
                        statements = body.Statements;

            }
            {
                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(parameters);
            match(RPAREN);
            attributes();
            if (0==inputState.guessing)
            {
                AddAttributes(m.ReturnTypeAttributes);
            }
            {
                switch ( LA(1) )
                {
                case AS:
                {
                    match(AS);
                    rt=type_reference();
                    if (0==inputState.guessing)
                    {
                        m.ReturnType = rt;
                    }
                    break;
                }
                case COLON:
                {
                    break;
                }
                default:
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }
                 }
            }
            begin_block_with_doc(m, body);
            block(statements);
            end(body);
            if (0==inputState.guessing)
            {

                        container.Add(m);

            }
            }
            catch (RecognitionException ex)
            {
            if (0 == inputState.guessing)
            {
                reportError(ex);
                recover(ex,tokenSet_32_);
            }
            else
            {
                throw ex;
            }
            }
        }
Ejemplo n.º 27
0
		void EmitConstructorAttributes(Constructor node, TypeCreator knownTypes)
		{
			ConstructorBuilder builder = (ConstructorBuilder)GetBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
Ejemplo n.º 28
0
 public override void LeaveConstructor(Constructor node)
 {
     CheckParameterUniqueness(node);
 }
Ejemplo n.º 29
0
 public override void OnConstructor(Boo.Lang.Compiler.Ast.Constructor node)
 {
     ConvertMethod(node, new CodeConstructor());
 }
Ejemplo n.º 30
0
        public override void OnConstructor(Constructor node)
        {
            if (WasVisited(node))
            {
                return;
            }
            MarkVisited(node);

            Visit(node.Attributes);
            Visit(node.Parameters);

            InternalConstructor entity = (InternalConstructor)node.Entity;
            ProcessMethodBody(entity);

            if (node.IsRuntime)
            {
                CheckRuntimeMethod(node);
            }
            else
            {
                if (entity.DeclaringType.IsValueType)
                {
                    if (0 == node.Parameters.Count
                        && !node.IsStatic
                        && !node.IsSynthetic)
                    {
                        Error(CompilerErrorFactory.ValueTypesCannotDeclareParameterlessConstructors(node));
                    }
                }
                else if (
                    !entity.HasSelfCall &&
                    !entity.HasSuperCall &&
                    !entity.IsStatic)
                {
                    IType baseType = entity.DeclaringType.BaseType;
                    IConstructor super = GetCorrectConstructor(node, baseType, EmptyExpressionCollection);
                    if (null != super)
                    {
                        node.Body.Statements.Insert(0,
                                                    CodeBuilder.CreateSuperConstructorInvocation(super));
                    }
                }
                if (!entity.IsStatic)
                    CheckInstanceMethodInvocationsWithinConstructor(node);
            }
        }
		public override void OnConstructor(Constructor node)
		{
			_currentMethod = node;
			base.OnConstructor(node);
		}
Ejemplo n.º 32
0
 public Constructor CreateStaticConstructor(TypeDefinition type)
 {
     var constructor = new Constructor();
     constructor.IsSynthetic = true;
     constructor.Modifiers = TypeMemberModifiers.Private | TypeMemberModifiers.Static;
     EnsureEntityFor(constructor);
     type.Members.Add(constructor);
     return constructor;
 }
Ejemplo n.º 33
0
 public override void OnConstructor(Constructor node)
 {
     _parameters.Add(node);
     base.OnConstructor(node);
 }