Esempio n. 1
0
		override public void LeaveExpressionPair(ExpressionPair pair)
		{
			Expression converted = ConvertExpression(pair.First);
			if (null != converted)
			{
				pair.First = converted;
			}

			converted = ConvertExpression(pair.Second);
			if (null != converted)
			{
				pair.Second = converted;
			}
		}
        protected override void AddResolvedNamedArgumentToEval(MethodInvocationExpression eval, ExpressionPair pair, ReferenceExpression instance)
        {
            if (!TypeSystemServices.IsQuackBuiltin(pair.First))
            {
                base.AddResolvedNamedArgumentToEval(eval, pair, instance);
                return;
            }

            MemberReferenceExpression memberRef = new MemberReferenceExpression(
                pair.First.LexicalInfo,
                instance.CloneNode(),
                ((ReferenceExpression)pair.First).Name);
            BindQuack(memberRef);

            eval.Arguments.Add(
                CodeBuilder.CreateAssignment(
                    pair.First.LexicalInfo,
                    memberRef,
                    pair.Second));
        }
Esempio n. 3
0
 private bool ProcessNamedArgument(ExpressionPair arg)
 {
     Visit(arg.Second);
     if (NodeType.ReferenceExpression != arg.First.NodeType)
     {
         Error(arg.First, CompilerErrorFactory.NamedParameterMustBeIdentifier(arg));
         return false;
     }
     return true;
 }
Esempio n. 4
0
        protected virtual void AddResolvedNamedArgumentToEval(MethodInvocationExpression eval, ExpressionPair pair, ReferenceExpression instance)
        {
            IEntity entity = GetEntity(pair.First);
            switch (entity.EntityType)
            {
                case EntityType.Event:
                    {
                        IEvent member = (IEvent)entity;
                        eval.Arguments.Add(
                            CodeBuilder.CreateMethodInvocation(
                                pair.First.LexicalInfo,
                                instance.CloneNode(),
                                member.GetAddMethod(),
                                pair.Second));
                        break;
                    }

                case EntityType.Field:
                    {
                        eval.Arguments.Add(
                            CodeBuilder.CreateAssignment(
                                pair.First.LexicalInfo,
                                CodeBuilder.CreateMemberReference(
                                    instance.CloneNode(),
                                    (IMember)entity),
                                pair.Second));
                        break;
                    }

                case EntityType.Property:
                    {
                        IProperty property = (IProperty)entity;
                        IMethod setter = property.GetSetMethod();
                        if (null == setter)
                        {
                            Error(CompilerErrorFactory.PropertyIsReadOnly(pair.First, property));
                        }
                        else
                        {
                            //EnsureRelatedNodeWasVisited(pair.First, setter);
                            eval.Arguments.Add(
                                CodeBuilder.CreateAssignment(
                                    pair.First.LexicalInfo,
                                    CodeBuilder.CreateMemberReference(
                                        instance.CloneNode(),
                                        property),
                                    pair.Second));
                        }
                        break;
                    }
            }
        }
Esempio n. 5
0
	protected ExpressionPair  expression_pair() //throws RecognitionException, TokenStreamException
{
		ExpressionPair ep;
		
		IToken  t = null;
		
				ep = null;
				Expression key = null;
				Expression value = null;
			
		
		try {      // for error handling
			key=expression();
			t = LT(1);
			match(COLON);
			value=expression();
			if (0==inputState.guessing)
			{
				ep = new ExpressionPair(ToLexicalInfo(t), key, value);
			}
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "expression_pair");
				recover(ex,tokenSet_130_);
			}
			else
			{
				throw ex;
			}
		}
		return ep;
	}
Esempio n. 6
0
 public static CompilerError NamedParameterMustBeIdentifier(ExpressionPair pair)
 {
     return new CompilerError("BCE0002", SafeLexicalInfo(pair.First));
 }
Esempio n. 7
0
 public static CompilerError NamedParameterMustBeIdentifier(ExpressionPair pair)
 {
     return Instantiate("BCE0002", pair.First);
 }
Esempio n. 8
0
 bool SetFieldOrProperty(IAstAttribute aa, ExpressionPair p)
 {
     ReferenceExpression name = p.First as ReferenceExpression;
     if (null == name)
     {
         _context.Errors.Add(CompilerErrorFactory.NamedParameterMustBeIdentifier(p));
         return false;
     }
     else
     {
         Reflection.MemberInfo[] members = _type.FindMembers(
             Reflection.MemberTypes.Property | Reflection.MemberTypes.Field,
             Reflection.BindingFlags.Instance | Reflection.BindingFlags.Public,
             Type.FilterName, name.Name);
         if (members.Length > 0)
         {
             if (members.Length > 1)
             {
                 _context.Errors.Add(CompilerErrorFactory.AmbiguousReference(name, members));
                 return false;
             }
             else
             {
                 Reflection.MemberInfo m = members[0];
                 Reflection.PropertyInfo property = m as Reflection.PropertyInfo;
                 if (null != property)
                 {
                     property.SetValue(aa, p.Second, null);
                 }
                 else
                 {
                     Reflection.FieldInfo field = m as Reflection.FieldInfo;
                     if (null != field)
                     {
                         field.SetValue(aa, p.Second);
                     }
                     else
                     {
                         throw new InvalidOperationException();
                     }
                 }
             }
         }
         else
         {
             _context.Errors.Add(CompilerErrorFactory.NotAPublicFieldOrProperty(name, name.Name, _type.FullName));
             return false;
         }
     }
     return true;
 }
Esempio n. 9
0
 public override void OnExpressionPair(ExpressionPair pair)
 {
     Visit(pair.First);
     Write(": ");
     Visit(pair.Second);
 }
Esempio n. 10
0
        bool SetFieldOrProperty(IAstAttribute aa, ExpressionPair p)
        {
            var name = p.First as ReferenceExpression;
            if (name == null)
            {
                _context.Errors.Add(CompilerErrorFactory.NamedParameterMustBeIdentifier(p));
                return false;
            }

            var members = FindMembers(name);
            if (members.Length <= 0)
            {
                _context.Errors.Add(CompilerErrorFactory.NotAPublicFieldOrProperty(name, name.Name, Type()));
                return false;
            }

            if (members.Length > 1)
            {
                _context.Errors.Add(CompilerErrorFactory.AmbiguousReference(name, members));
                return false;
            }

            var member = members[0];
            var property = member as PropertyInfo;
            if (property != null)
            {
                property.SetValue(aa, p.Second, null);
                return true;
            }

            var field = (FieldInfo)member;
            field.SetValue(aa, p.Second);
            return true;
        }
 public ExpressionPair expression_pair()
 {
     ExpressionPair pair = null;
     IToken token = null;
     try
     {
         Expression expression = this.expression();
         token = this.LT(1);
         this.match(0x42);
         Expression expression2 = this.expression();
         if (base.inputState.guessing == 0)
         {
             pair = new ExpressionPair(ToLexicalInfo(token), expression, expression2);
         }
     }
     catch (RecognitionException exception)
     {
         if (base.inputState.guessing != 0)
         {
             throw;
         }
         this.reportError(exception);
         this.recover(exception, tokenSet_40_);
         return pair;
     }
     return pair;
 }
Esempio n. 12
0
		override public object Clone()
		{
		
			ExpressionPair clone = new ExpressionPair();
			clone._lexicalInfo = _lexicalInfo;
			clone._endSourceLocation = _endSourceLocation;
			clone._documentation = _documentation;
			clone._isSynthetic = _isSynthetic;
			clone._entity = _entity;
			if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone();
			if (null != _first)
			{
				clone._first = _first.Clone() as Expression;
				clone._first.InitializeParent(clone);
			}
			if (null != _second)
			{
				clone._second = _second.Clone() as Expression;
				clone._second.InitializeParent(clone);
			}
			return clone;


		}