Beispiel #1
0
 public override void OnMemberReferenceExpression(MemberReferenceExpression node)
 {
     Write("MemberReferenceExpression(");
     BeginNode();
     WriteIndented("Target: "); Visit(node.Target); Write(", "); WriteLine();
     WriteIndented("Name: "); WriteString(node.Name);
     EndNode();
 }
		B.ReferenceExpression MakeReferenceExpression(string fullName)
		{
			string[] parts = fullName.Split('.');
			B.ReferenceExpression r = new B.ReferenceExpression(lastLexicalInfo, parts[0]);
			for (int i = 1; i < parts.Length; i++)
				r = new B.MemberReferenceExpression(lastLexicalInfo, r, parts[i]);
			return r;
		}
		private Expression FixCondition(Expression condition)
		{
			if (IsTryGetParameterInvocation(condition) == false)
				return condition;

			var isNull =
				new MemberReferenceExpression(condition, "_IsIgnoreNullReferencingNotNullObject_");
			return isNull;
		}
 public override void WrapStatementsInBlockIfNeeded(MemberReferenceExpression node, IUpdateCollector<LexicalInfo> updateCollector)
 {
     if (!this.IsInsideBlock(node))
     {
         Statement statement = BooExtensions.FindRootStatement(node);
         updateCollector.Insert(BooExtensions.SourcePosition(BooExtensions.FindExpressionRoot(statement)), "{ ", node.get_LexicalInfo(), null).InclusiveRange = false;
         updateCollector.Insert(new SourcePosition(statement.get_EndSourceLocation().get_Line(), statement.get_EndSourceLocation().get_Column() + 1), " }", node.get_LexicalInfo(), null);
     }
 }
        /// <summary>
        /// Called when we encounters a member reference expression
        /// </summary>
        /// <param name="node">The node.</param>
        public override void OnMemberReferenceExpression(MemberReferenceExpression node)
        {
            if (this.ShouldTransformNodeName(node))
            {
                this.TransformNodeName(node);
            }

            base.OnMemberReferenceExpression(node);
        }
 public override void OnReferenceExpression(ReferenceExpression node) {
     if (node.Name[0] == '_')
     {
         var result = new MemberReferenceExpression(node.LexicalInfo);
         result.Name = node.Name.Substring(1);
         result.Target = instance.CloneNode();
         ReplaceCurrentNode(result);
     }
 }
Beispiel #7
0
 B.ReferenceExpression MakeReferenceExpression(string fullName)
 {
     string[] parts          = fullName.Split('.');
     B.ReferenceExpression r = new B.ReferenceExpression(lastLexicalInfo, parts[0]);
     for (int i = 1; i < parts.Length; i++)
     {
         r = new B.MemberReferenceExpression(lastLexicalInfo, r, parts[i]);
     }
     return(r);
 }
Beispiel #8
0
		override public void OnMemberReferenceExpression(MemberReferenceExpression node)
		{
			var tern = ProcessTargets(node);
			if (tern != null)
			{
				ReplaceCurrentNode(tern);
				return;
			}
			base.OnMemberReferenceExpression(node);
		}
 public override void OnMemberReferenceExpression(MemberReferenceExpression node)
 {
     if (LookingFor(node))
     {
         Found(node);
     }
     else
     {
         base.OnMemberReferenceExpression(node);
     }
 }
        public override void OnMemberReferenceExpression(MemberReferenceExpression node)
        {
            var name = node.ToString();

            if (name.StartsWith("@"))
            {
                ReplaceWithComponentReference(node, name);
                return;
            }

            base.OnMemberReferenceExpression(node);
        }
Beispiel #11
0
 public static ReferenceExpression CreateReferenceExpression(string fullname)
 {
     string[] parts = fullname.Split('.');
     ReferenceExpression expression = new ReferenceExpression(parts[0]);
     expression.IsSynthetic = true;
     for (int i=1; i<parts.Length; ++i)
     {
         expression = new MemberReferenceExpression(expression, parts[i]);
         expression.IsSynthetic = true;
     }
     return expression;
 }
Beispiel #12
0
        protected override Statement ExpandImpl(MacroStatement macro){
            if (macro.Arguments.Count == 0)
            {
                Context.Errors.Add(new CompilerError(macro.LexicalInfo,
                                                     "call macro requires at least one reference or string attribute for action name"));
            }
            var basis = new ReferenceExpression("Html");
            var method = new MemberReferenceExpression(basis, "RenderAction");
            var call = new MethodInvocationExpression(method);
            int i = 0;
            var result = new Block();
            foreach (Expression argument in macro.Arguments){
                i++;
                Expression exp = argument;
                if (!(exp is HashLiteralExpression)){
//action and contrller parameters
                    if (!(exp is NullLiteralExpression)){
                        exp = new StringLiteralExpression(argument.ToCodeString());
                    }
                    call.Arguments.Add(exp);
                }
                else{
                    string name = "__rd";
                    result.Add(
                        new DeclarationStatement(
                            new Declaration(name, null),
                            new MethodInvocationExpression(AstUtil.CreateReferenceExpression("RouteValueDictionary"))
                            )
                        );
                    var dict = argument as HashLiteralExpression;
                    foreach (ExpressionPair item in dict.Items){
                        result.Add(
                            new MethodInvocationExpression(
                                AstUtil.CreateReferenceExpression(name + ".Add"),
                                item.First,
                                item.Second
                                )
                            );
                    }
                    if (i == 2){
                        call.Arguments.Add(new NullLiteralExpression());
                    }
                    call.Arguments.Add(AstUtil.CreateReferenceExpression(name));
                }
            }
            result.Add(call);
            return result;
        }
    	public override void LeaveMemberReferenceExpression(MemberReferenceExpression node)
    	{
    		var property = node.Entity as IProperty;
    		if (property == null || node.IsTargetOfAssignment())
    			return;

    		var getter = CodeBuilder.CreatePropertyGet(node.Target, property);

    		// preserve duck typing...
    		if (property.IsDuckTyped)
    			ReplaceCurrentNode(
    				CodeBuilder.CreateCast(
    					TypeSystemServices.DuckType, getter));
    		else
    			ReplaceCurrentNode(getter);
    	}
        private Expression FixCondition(Expression condition){
            if (IsTryGetParameterInvocation(condition) == false){
                return condition;
            }

            string name = ((ReferenceExpression) condition).Name.Substring(1);
            condition = new MethodInvocationExpression(
                new MemberReferenceExpression(new SuperLiteralExpression(), "TryGetParameter"),
                new StringLiteralExpression(name)
                );

            var isNull =
                new MemberReferenceExpression(condition, "_IsIgnoreNullReferencingNotNullObject_");

            return isNull;
        }
        public override void OnMemberReferenceExpression(MemberReferenceExpression node)
        {
            ReferenceExpression reference = node.Target as ReferenceExpression;

            if (reference != null && reference.Name.StartsWith("@"))
            {
                _component = reference;
            }
            else
            {
                _component = AstUtil.CreateMethodInvocationExpression(
                    AstUtil.CreateReferenceExpression(typeof(ComponentReference).FullName),
                    node.Target
                    );
            }

            _method = new StringLiteralExpression(node.Name);
            _found = true;
        }
        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));
        }
Beispiel #17
0
        public override void LeaveMemberReferenceExpression(MemberReferenceExpression node)
        {
            if (null == node.Entity) return;
            if (EntityType.Property != node.Entity.EntityType) return;
            if (AstUtil.IsLhsOfAssignment(node)) return;

            var property = (IProperty) node.Entity;
            MethodInvocationExpression getter = CodeBuilder.CreatePropertyGet(node.Target, property);

            // preserve duck typing...
            if (property.IsDuckTyped)
            {
                ReplaceCurrentNode(
                    CodeBuilder.CreateCast(
                        TypeSystemServices.DuckType, getter));
            }
            else
            {
                ReplaceCurrentNode(getter);
            }
        }
Beispiel #18
0
 public MemberReferenceExpression MemberReferenceForEntity(Expression target, IEntity entity)
 {
     MemberReferenceExpression reference = new MemberReferenceExpression(target.LexicalInfo);
     reference.Target = target;
     reference.Name = entity.Name;
     reference.Entity = entity;
     return reference;
 }
Beispiel #19
0
 private IEntity TryToResolveMemberAsExtension(MemberReferenceExpression node)
 {
     IEntity extension = NameResolutionService.ResolveExtension(GetReferenceNamespace(node), node.Name);
     if (null != extension)
         node.Annotate(ResolvedAsExtensionAnnotation);
     return extension;
 }
Beispiel #20
0
        IEntity ResolveMember(MemberReferenceExpression node)
        {
            var entity = node.Entity;
            if (!ShouldRebindMember(entity))
                return entity;

            var ns = GetReferenceNamespace(node);
            var member = NameResolutionService.Resolve(ns, node.Name);
            if (null == member || !IsAccessible(member) || !IsApplicable(member, node))
            {
                var extension = TryToResolveMemberAsExtension(node);
                if (null != extension)
                    return extension;
            }

            if (null != member)
                return Disambiguate(node, member);

            MemberNotFound(node, ns);
            return null;
        }
Beispiel #21
0
        void ProcessLenInvocation(MethodInvocationExpression node)
        {
            if ((node.Arguments.Count < 1) || (node.Arguments.Count > 2))
            {
                Error(node, CompilerErrorFactory.MethodArgumentCount(node.Target, "len", node.Arguments.Count));
                return;
            }

            Expression resultingNode = null;

            Expression target = node.Arguments[0];
            IType type = GetExpressionType(target);
            bool isArray = IsAssignableFrom(TypeSystemServices.ArrayType, type);

            if ((!isArray) && (node.Arguments.Count != 1))
            {
                Error(node, CompilerErrorFactory.MethodArgumentCount(node.Target, "len", node.Arguments.Count));
            }
            if (TypeSystemServices.IsSystemObject(type))
            {
                resultingNode = CodeBuilder.CreateMethodInvocation(MethodCache.RuntimeServices_Len, target);
            }
            else if (TypeSystemServices.StringType == type)
            {
                resultingNode = CodeBuilder.CreateMethodInvocation(target, MethodCache.String_get_Length);
            }
            else if (isArray)
            {
                if (node.Arguments.Count == 1)
                    resultingNode = CodeBuilder.CreateMethodInvocation(target, MethodCache.Array_get_Length);
                else
                    resultingNode = CodeBuilder.CreateMethodInvocation(target, MethodCache.Array_GetLength, node.Arguments[1]);
            }
            else if (IsAssignableFrom(TypeSystemServices.ICollectionType, type))
            {
                resultingNode = CodeBuilder.CreateMethodInvocation(target, MethodCache.ICollection_get_Count);
            }
            else if (GenericsServices.HasConstructedType(type, TypeSystemServices.ICollectionGenericType))
            {
                resultingNode = new MemberReferenceExpression(node.LexicalInfo, target, "Count");
                Visit(resultingNode);
            }
            else
            {
                Error(CompilerErrorFactory.InvalidLen(target, type));
            }

            if (null != resultingNode)
            {
                node.ParentNode.Replace(node, resultingNode);
            }
        }
Beispiel #22
0
 private void MarkRelatedImportAsUsed(MemberReferenceExpression node)
 {
     string ns = null;
     foreach (var import in _currentModule.Imports)
     {
         if (ImportAnnotations.IsUsedImport(import)) continue;
         if (null == ns) ns = node.ToCodeString();
         if (import.Namespace == ns)
         {
             ImportAnnotations.MarkAsUsed(import);
             break;
         }
     }
 }
Beispiel #23
0
 private bool IsBeingAssignedTo(MemberReferenceExpression node)
 {
     Node current = node;
     Node parent = current.ParentNode;
     BinaryExpression be = parent as BinaryExpression;
     while (null == be)
     {
         current = parent;
         parent = parent.ParentNode;
         if (parent == null || !(parent is Expression))
             return false;
         be = parent as BinaryExpression;
     }
     return be.Left == current;
 }
Beispiel #24
0
        private bool IsApplicable(IEntity entity, MemberReferenceExpression node)
        {
            //ProcessLenInvocation - Visit(resultingNode), call for node without parent
            if (node == null || node.ParentNode == null)
                return true;
            if (AstUtil.IsTargetOfMethodInvocation(node)
                && !IsCallableEntity(entity))
                return false;

            return true;
        }
Beispiel #25
0
        public override void LeaveReturnStatement(ReturnStatement node)
        {
            if (null == node.Expression)
                return;

            // forces anonymous types to be correctly
            // instantiated
            IType expressionType = GetConcreteExpressionType(node.Expression);
            if (TypeSystemServices.VoidType == expressionType
                && node.ContainsAnnotation(OptionalReturnStatementAnnotation))
            {
                node.ParentNode.Replace(
                    node,
                    new ExpressionStatement(node.Expression));
                return;
            }

            IType returnType = _currentMethod.ReturnType;
            if (TypeSystemServices.IsUnknown(returnType))
                _currentMethod.AddReturnExpression(node.Expression);
            else
                AssertTypeCompatibility(node.Expression, returnType, expressionType);

            //bind to nullable Value if needed
            if (TypeSystemServices.IsNullable(expressionType) && !TypeSystemServices.IsNullable(returnType))
            {
                // TODO: move to later steps or introduce an implicit conversion operator
                var mre = new MemberReferenceExpression(node.Expression.LexicalInfo, node.Expression, "Value");
                Visit(mre);
                node.Replace(node.Expression, mre);
            }
        }
Beispiel #26
0
 INamespace GetReferenceNamespace(MemberReferenceExpression expression)
 {
     Expression target = expression.Target;
     INamespace ns = target.ExpressionType;
     if (null != ns)
     {
         return GetConcreteExpressionType(target);
     }
     return (INamespace)GetEntity(target);
 }
Beispiel #27
0
        public override void LeaveMemberReferenceExpression(MemberReferenceExpression node)
        {
            _context.TraceVerbose("LeaveMemberReferenceExpression: {0}", node);

            if (TypeSystemServices.IsError(node.Target))
                Error(node);
            else
                ProcessMemberReferenceExpression(node);
        }
Beispiel #28
0
        bool BindNullableOperation(BinaryExpression node)
        {
            if (!IsNullableOperation(node))
                return false;

            if (BinaryOperatorType.ReferenceEquality == node.Operator)
            {
                node.Operator = BinaryOperatorType.Equality;
                return BindNullableComparison(node);
            }
            else if (BinaryOperatorType.ReferenceInequality == node.Operator)
            {
                node.Operator = BinaryOperatorType.Inequality;
                return BindNullableComparison(node);
            }

            IType lhs = GetExpressionType(node.Left);
            IType rhs = GetExpressionType(node.Right);
            bool lhsIsNullable = TypeSystemServices.IsNullable(lhs);
            bool rhsIsNullable = TypeSystemServices.IsNullable(rhs);

            if (BinaryOperatorType.Assign == node.Operator)
            {
                if (lhsIsNullable)
                {
                    if (rhsIsNullable)
                        return false;
                    BindNullableInitializer(node, node.Right, lhs);
                    return false;
                }
            }

            if (lhsIsNullable)
            {
                MemberReferenceExpression mre = new MemberReferenceExpression(node.Left, "Value");
                node.Replace(node.Left, mre);
                Visit(mre);
                mre.Annotate("nullableTarget", true);
            }
            if (rhsIsNullable)
            {
                MemberReferenceExpression mre = new MemberReferenceExpression(node.Right, "Value");
                node.Replace(node.Right, mre);
                Visit(mre);
                mre.Annotate("nullableTarget", true);
            }

            return false;
        }
Beispiel #29
0
        bool BindNullableComparison(BinaryExpression node)
        {
            if (!IsNullableOperation(node))
                return false;

            if (IsNull(node.Left) || IsNull(node.Right))
            {
                Expression nullable = IsNull(node.Left) ? node.Right : node.Left;
                Expression val = new MemberReferenceExpression(nullable, "HasValue");
                node.Replace(node.Left, val);
                Visit(val);
                Expression nil = new BoolLiteralExpression(false);
                node.Replace(node.Right, nil);
                Visit(nil);
                BindExpressionType(node, TypeSystemServices.BoolType);
                return true;
            }

            BinaryExpression valueCheck = new BinaryExpression(
                (node.Operator == BinaryOperatorType.Inequality)
                    ? BinaryOperatorType.BitwiseOr
                    : BinaryOperatorType.BitwiseAnd,
                new BinaryExpression(
                    GetCorrespondingHasValueOperator(node.Operator),
                    CreateNullableHasValueOrTrueExpression(node.Left),
                    CreateNullableHasValueOrTrueExpression(node.Right)
                ),
                new BinaryExpression(
                    node.Operator,
                    CreateNullableGetValueOrDefaultExpression(node.Left),
                    CreateNullableGetValueOrDefaultExpression(node.Right)
                )
            );
            node.ParentNode.Replace(node, valueCheck);
            Visit(valueCheck);
            return true;
        }
Beispiel #30
0
 public override bool EnterMemberReferenceExpression(MemberReferenceExpression node)
 {
     return null == node.ExpressionType;
 }
Beispiel #31
0
        protected virtual void ProcessMemberReferenceExpression(MemberReferenceExpression node)
        {
            var entity = ResolveMember(node);
            if (null == entity)
                return;

            EnsureRelatedNodeWasVisited(node, entity);
            if (EntityType.Namespace == entity.EntityType)
                MarkRelatedImportAsUsed(node);

            var member = entity as IMember;
            if (member != null)
            {
                if (!AssertTargetContext(node, member))
                {
                    Error(node);
                    return;
                }

                if (EntityType.Method != member.EntityType)
                    BindExpressionType(node, GetInferredType(member));
                else
                    BindExpressionType(node, member.Type);
            }

            // TODO: check for generic methods with no generic args here
            if (EntityType.Property == entity.EntityType)
            {
                IProperty property = (IProperty)entity;
                if (property.IsIndexedProperty())
                {
                    if (!AstUtil.IsTargetOfSlicing(node)
                        && (!property.IsExtension || property.GetParameters().Length > 1))
                    {
                        Error(node, CompilerErrorFactory.PropertyRequiresParameters(MemberAnchorFor(node), entity));
                        return;
                    }
                }
                if (IsWriteOnlyProperty(property) && !IsBeingAssignedTo(node))
                {
                    Error(node, CompilerErrorFactory.PropertyIsWriteOnly(MemberAnchorFor(node), entity));
                }
            }
            else if (EntityType.Event == entity.EntityType)
            {
                if (!AstUtil.IsTargetOfMethodInvocation(node) &&
                    !AstUtil.IsLhsOfInPlaceAddSubtract(node))
                {
                    if (CurrentType == member.DeclaringType)
                    {
                        InternalEvent ev = (InternalEvent)entity;
                        node.Name = ev.BackingField.Name;
                        node.Entity = ev.BackingField;
                        BindExpressionType(node, ev.BackingField.Type);
                        return;
                    }
                    else if (!node.IsTargetOfAssignment()
                             || !IsNull(((BinaryExpression)node.ParentNode).Right))
                    {
                        Error(node, CompilerErrorFactory.EventIsNotAnExpression(node, entity));
                    }
                    else //event=null
                    {
                        EnsureInternalEventInvocation((IEvent) entity, node);
                    }
                }
            }

            Bind(node, entity);
            PostProcessReferenceExpression(node);
        }