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);
        }
Esempio n. 2
0
        public override void OnSelfLiteralExpression(SelfLiteralExpression node)
        {
            base.OnSelfLiteralExpression(node);

            if (node.IsTargetOfMethodInvocation())
            {
                OnExpression(node);
            }
        }
Esempio n. 3
0
		public void LiftCastExpressionWithSelfTarget()
		{
			var self = new SelfLiteralExpression();
			var typeReference = new SimpleTypeReference("T");
			Expression cast = new TryCastExpression(self, typeReference);
			var parameter = ParameterDeclaration.Lift(cast);
			Assert.AreEqual("self", parameter.Name);
			Assert.IsTrue(typeReference.Matches(parameter.Type));
			Assert.AreNotSame(typeReference, parameter.Type);
		}
        override public object Clone()
        {
            SelfLiteralExpression clone = (SelfLiteralExpression)FormatterServices.GetUninitializedObject(typeof(SelfLiteralExpression));

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

            clone._expressionType = _expressionType;
            return(clone);
        }
Esempio n. 5
0
        override public object Clone()
        {
            SelfLiteralExpression clone = new SelfLiteralExpression();

            clone._lexicalInfo       = _lexicalInfo;
            clone._endSourceLocation = _endSourceLocation;
            clone._documentation     = _documentation;
            clone._isSynthetic       = _isSynthetic;
            clone._entity            = _entity;
            if (_annotations != null)
            {
                clone._annotations = (Hashtable)_annotations.Clone();
            }
            clone._expressionType = _expressionType;
            return(clone);
        }
Esempio n. 6
0
        public override void OnSelfLiteralExpression(SelfLiteralExpression node)
        {
            if (null == _externalEnumeratorSelf)
            {
                IType type = node.ExpressionType;
                _externalEnumeratorSelf = DeclareFieldInitializedFromConstructorParameter(
                    _enumerator,
                    _enumeratorConstructor,
                    "self_",
                    type);
            }

            ReplaceCurrentNode(CodeBuilder.CreateReference(node.LexicalInfo, _externalEnumeratorSelf));
        }
Esempio n. 7
0
		override public void OnSelfLiteralExpression(SelfLiteralExpression node)
		{
			LoadSelf(node);
		}
Esempio n. 8
0
        public override void OnSelfLiteralExpression(SelfLiteralExpression node)
        {
            if (null == _currentMethod)
            {
                Error(node, CompilerErrorFactory.SelfOutsideMethod(node));
                return;
            }

            if (_currentMethod.IsStatic)
            {
                if (NodeType.MemberReferenceExpression != node.ParentNode.NodeType)
                {
                    // if we are inside a MemberReferenceExpression
                    // let the MemberReferenceExpression deal with it
                    // as it can provide a better message
                    Error(CompilerErrorFactory.SelfIsNotValidInStaticMember(node));
                }
            }
            node.Entity = _currentMethod;
            node.ExpressionType = _currentMethod.DeclaringType;
        }
Esempio n. 9
0
		override public void OnSelfLiteralExpression(SelfLiteralExpression node)
		{
			ReplaceCurrentNode(CodeBuilder.CreateReference(node.LexicalInfo, ExternalEnumeratorSelf()));
		}
Esempio n. 10
0
 public override void OnSelfLiteralExpression(SelfLiteralExpression node)
 {
     if (node.LexicalInfo != null)
         results.MapParsedNode(new MappedReferenceExpression(results, node));
     base.OnSelfLiteralExpression(node);
 }
Esempio n. 11
0
		public override void OnSelfLiteralExpression(SelfLiteralExpression node)
		{
			_expression = new CodeThisReferenceExpression();
		}
Esempio n. 12
0
 public override void OnSelfLiteralExpression(SelfLiteralExpression node)
 {
     WriteKeyword("self");
 }
Esempio n. 13
0
 public SelfLiteralExpression CreateSelfReference(IType self)
 {
     SelfLiteralExpression expression = new SelfLiteralExpression();
     expression.ExpressionType = self;
     return expression;
 }
 public SelfLiteralExpression self_literal()
 {
     SelfLiteralExpression expression = null;
     IToken token = null;
     try
     {
         token = this.LT(1);
         this.match(40);
         if (base.inputState.guessing == 0)
         {
             expression = new SelfLiteralExpression(ToLexicalInfo(token));
         }
     }
     catch (RecognitionException exception)
     {
         if (base.inputState.guessing != 0)
         {
             throw;
         }
         this.reportError(exception);
         this.recover(exception, tokenSet_20_);
         return expression;
     }
     return expression;
 }
Esempio n. 15
0
        //throws RecognitionException, TokenStreamException
        protected SelfLiteralExpression self_literal()
        {
            SelfLiteralExpression e;

            IToken  t = null;
            e = null;

            try {      // for error handling
            t = LT(1);
            match(SELF);
            if (0==inputState.guessing)
            {
                e = new SelfLiteralExpression(SourceLocationFactory.ToLexicalInfo(t));
            }
            }
            catch (RecognitionException ex)
            {
            if (0 == inputState.guessing)
            {
                reportError(ex);
                recover(ex,tokenSet_36_);
            }
            else
            {
                throw ex;
            }
            }
            return e;
        }
		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;
		}
 public MappedReferenceExpression(CompileResults results, SelfLiteralExpression node)
     : base(results, node, "self".Length)
 {
 }
Esempio n. 18
0
 public override void OnSelfLiteralExpression(SelfLiteralExpression node)
 {
     _il.Emit(OpCodes.Ldarg_0);
     if (node.ExpressionType.IsValueType)
     {
         _il.Emit(OpCodes.Ldobj, GetSystemType(node.ExpressionType));
     }
     PushType(node.ExpressionType);
 }
Esempio n. 19
0
		public override void OnSelfLiteralExpression(SelfLiteralExpression node)
		{
			if (callingClass == null)
				ClearResult();
			else
				MakeResult(callingClass.DefaultReturnType);
		}
Esempio n. 20
0
	protected SelfLiteralExpression  self_literal() //throws RecognitionException, TokenStreamException
{
		SelfLiteralExpression e;
		
		IToken  t = null;
		e = null;
		
		try {      // for error handling
			t = LT(1);
			match(SELF);
			if (0==inputState.guessing)
			{
				e = new SelfLiteralExpression(ToLexicalInfo(t));
			}
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "self_literal");
				recover(ex,tokenSet_44_);
			}
			else
			{
				throw ex;
			}
		}
		return e;
	}
Esempio n. 21
0
 public override void OnSelfLiteralExpression(SelfLiteralExpression node)
 {
     var entity = GetSelfEntity();
     node.Entity = entity;
     _references.Add(node);
     _referencedEntities[entity] = null;
 }
Esempio n. 22
0
        protected Expression CreateMemberReferenceTarget(Node sourceNode, IMember member)
        {
            Expression target = null;

            if (member.IsStatic)
            {
                target = CodeBuilder.CreateReference(sourceNode.LexicalInfo, member.DeclaringType);
            }
            else
            {
                //check if found entity can't possibly be a member of self:
                if (member.DeclaringType != CurrentType
                    && !(CurrentType.IsSubclassOf(member.DeclaringType)))
                {
                    Error(CompilerErrorFactory.InstanceRequired(sourceNode, member));
                }
                target = new SelfLiteralExpression(sourceNode.LexicalInfo);
            }
            BindExpressionType(target, member.DeclaringType);
            return target;
        }
Esempio n. 23
0
		override public object Clone()
		{
		
			SelfLiteralExpression clone = new SelfLiteralExpression();
			clone._lexicalInfo = _lexicalInfo;
			clone._endSourceLocation = _endSourceLocation;
			clone._documentation = _documentation;
			clone._isSynthetic = _isSynthetic;
			clone._entity = _entity;
			if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone();
			clone._expressionType = _expressionType;
			return clone;


		}