public override void VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     if (node.Parameter.Resolve() == parameter)
     {
         this.searchResult = UsageFinderSearchResult.Used;
     }
 }
        public override ICodeNode VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
        {
            ICodeNode result = base.VisitArgumentReferenceExpression(node);

            // a -> 1
            // b -> 2
            // a -> 1
            // c -> 3

            if (!expressionNumbers.ContainsKey(node))
            {
                int value = -1;
                foreach (var keypair in expressionNumbers)
                {
                    if (keypair.Key.CodeNodeType == CodeNodeType.ArgumentReferenceExpression)
                    {
                        ArgumentReferenceExpression expr = (ArgumentReferenceExpression)keypair.Key;
                        if (expr.Parameter == node.Parameter)
                        {
                            value = keypair.Value;
                            break;
                        }
                    }
                }

                if (value == -1)
                {
                    value = expressionCnt++;
                }

                expressionNumbers.Add(node, value);
            }

            return(result);
        }
 private bool CheckArgumentReference(ArgumentReferenceExpression node)
 {
     if (node == null)
     {
         return(false);
     }
     return((object)node.get_Parameter().Resolve() == (object)this.parameter);
 }
 public override void VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     if ((object)node.get_Parameter().Resolve() == (object)this.parameter)
     {
         this.searchResult = 2;
     }
     return;
 }
 public override ICodeNode VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     V_0 = node.get_Parameter();
     if (!this.parameterToVariableMap.TryGetValue(V_0.Resolve(), out V_1))
     {
         return(node);
     }
     return(new VariableReferenceExpression(V_1, node.get_UnderlyingSameMethodInstructions()));
 }
示例#6
0
            public override ICodeNode VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
            {
                Expression exp;

                if (paramVarSubstitution.TryGetValue(node.Parameter.Resolve(), out exp))
                {
                    return(exp);
                }
                return(base.VisitArgumentReferenceExpression(node));
            }
                public override ICodeNode VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
                {
                    ParameterReference parameterReference = node.Parameter;
                    VariableReference  variableReference;

                    if (parameterToVariableMap.TryGetValue(parameterReference.Resolve(), out variableReference))
                    {
                        return(new VariableReferenceExpression(variableReference, node.UnderlyingSameMethodInstructions));
                    }

                    return(node);
                }
示例#8
0
        internal static bool IsArgumentReferenceToRefParameter(this Expression expression)
        {
            if (expression.CodeNodeType != CodeNodeType.UnaryExpression)
            {
                return false;
            }

            UnaryExpression unary = expression as UnaryExpression;
            if (unary.Operator != UnaryOperator.AddressDereference ||
                unary.Operand.CodeNodeType != CodeNodeType.ArgumentReferenceExpression)
            {
                return false;
            }

            ArgumentReferenceExpression argumentReference = unary.Operand as ArgumentReferenceExpression;
            if (!argumentReference.Parameter.ParameterType.IsByReference)
            {
                return false;
            }

            return true;
        }
示例#9
0
 public virtual ICodeNode VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     return(node);
 }
 public override void VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     this.Parameters.Add(node.Parameter.Resolve());
 }
示例#11
0
 public override void Visit(ArgumentReferenceExpression node)
 {
     UnsupportedExpression(node);
 }
示例#12
0
 private void EmitArgumentReferenceExpression(ArgumentReferenceExpression node, int si)
 {
     this.Text.Emit("movl {0}(%ebp), %eax", this._parameterLocations[node.Parameter.Name]);
 }
示例#13
0
 public override void VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     Push(parameters [method.Parameters.IndexOf((ParameterDefinition)node.Parameter)]);
 }
示例#14
0
 public override ICodeNode VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     node = (ArgumentReferenceExpression)base.VisitArgumentReferenceExpression(node);
     return(new TypedArgumentReferenceExpression(node.Parameter));
 }
示例#15
0
        private void GenerateParameterEntities(NamespaceDeclaration ns, ParameterEntity entity)
        {
            var type = ns.AddType(new StructDeclaration(entity.Name));

            type.Modifiers = Modifiers.Public | Modifiers.ReadOnly | Modifiers.Partial;

            type.Implements.Add(typeof(IReference));
            type.CustomAttributes.Add(new CustomAttribute(typeof(JsonConverterAttribute))
            {
                Arguments =
                {
                    new CustomAttributeArgument(new TypeOfExpression(typeof(ReferenceJsonConverter)))
                }
            });

            // Add Value Property (readonly)
            var valueField    = new FieldDeclaration("_value", GetPropertyTypeRef(entity.FinalType), Modifiers.Private | Modifiers.ReadOnly);
            var valueProperty = new PropertyDeclaration("Value", GetPropertyTypeRef(entity.FinalType))
            {
                Modifiers = Modifiers.Public,
                Getter    = new PropertyAccessorDeclaration
                {
                    Statements = new ReturnStatement(valueField)
                }
            };

            type.AddMember(valueField);
            type.AddMember(valueProperty);

            foreach (var refe in entity.Refs)
            {
                var addNullCheck = refe.ModelRef.Model != null;

                // Add constructor
                var ctor = type.AddMember(new ConstructorDeclaration()
                {
                    Modifiers = Modifiers.Private,
                    Arguments =
                    {
                        new MethodArgumentDeclaration(GetPropertyTypeRef(refe.ModelRef), refe.Name),
                    },
                    Statements =
                    {
                        new AssignStatement(valueField, GetAssignExpression())
                    }
                });

                if (addNullCheck)
                {
                    ctor.Statements.Insert(0, ctor.Arguments[0].CreateThrowIfNullStatement());
                }

                // Add implicit converter
                var implicitOperator = type.AddMember(new OperatorDeclaration()
                {
                    Modifiers  = Modifiers.Public | Modifiers.Static | Modifiers.Implicit,
                    ReturnType = type,
                    Arguments  =
                    {
                        new MethodArgumentDeclaration(GetPropertyTypeRef(refe.ModelRef), refe.Name),
                    },
                    Statements =
                    {
                        new ReturnStatement(new NewObjectExpression(type, new ArgumentReferenceExpression(refe.Name)))
                    }
                });

                if (addNullCheck)
                {
                    implicitOperator.Statements.Insert(0, implicitOperator.Arguments[0].CreateThrowIfNullStatement());
                }

                Expression GetAssignExpression()
                {
                    Expression value = new ArgumentReferenceExpression(refe.Name);

                    foreach (var member in refe.Properties)
                    {
                        value = value.CreateMemberReferenceExpression(ToPropertyName(member));
                    }

                    return(value);
                }
            }
        }
 public override void VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     TrySetPendingName(node.Parameter.Name, false);
     base.VisitArgumentReferenceExpression(node);
 }
示例#17
0
 public override void VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     cil.EmitInstruction(OpCodes.Ldarg, node.Parameter.Index + 1);
 }
 public override void VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     dummyVar0 = this.get_Parameters().Add(node.get_Parameter().Resolve());
     return;
 }
 public override ICodeNode VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     this.AddReferencedParameter(node.get_Parameter().Resolve());
     return(node);
 }
示例#20
0
 public override ICodeNode VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     return(base.VisitArgumentReferenceExpression(node));
 }
        private void GenerateParameterEntity(ParameterEntity entity)
        {
            var unit = CreateUnit("Models/" + entity.Name + ".cs");
            var ns   = unit.AddNamespace(RootNamespace);
            var type = ns.AddType(new StructDeclaration(entity.Name));

            type.Modifiers = Modifiers.Public | Modifiers.ReadOnly | Modifiers.Partial;

            type.Implements.Add(WellKnownTypes.IGitLabObjectReferenceTypeReference.MakeGeneric(entity.FinalType.ToArgumentTypeReference()));
            type.CustomAttributes.Add(new CustomAttribute(typeof(JsonConverterAttribute))
            {
                Arguments =
                {
                    new CustomAttributeArgument(new TypeOfExpression(WellKnownTypes.GitLabObjectReferenceJsonConverterFactoryTypeReference)),
                },
            });

            // Add Value Property (readonly)
            var valueField    = new FieldDeclaration("_value", GetPropertyTypeRef(entity.FinalType), Modifiers.Private | Modifiers.ReadOnly);
            var valueProperty = new PropertyDeclaration("Value", GetPropertyTypeRef(entity.FinalType))
            {
                Modifiers = Modifiers.Public,
                Getter    = new PropertyAccessorDeclaration
                {
                    Statements = new ReturnStatement(valueField),
                },
            };

            type.AddMember(valueField);
            type.AddMember(valueProperty);

            foreach (var entityRef in entity.Refs)
            {
                var addNullCheck = entityRef.ModelRef.Model != null;

                // Add constructor
                var ctor = type.AddMember(new ConstructorDeclaration()
                {
                    Modifiers = Modifiers.Private,
                    Arguments =
                    {
                        new MethodArgumentDeclaration(GetPropertyTypeRef(entityRef.ModelRef), ToArgumentName(entityRef.Name)),
                    },
                    Statements =
                    {
                        new AssignStatement(valueField, GetAssignExpression()),
                    },
                });

                if (addNullCheck)
                {
                    ctor.Statements.Insert(0, ctor.Arguments[0].CreateThrowIfNullStatement());
                }

                // FromXXX
                var fromMethod = type.AddMember(new MethodDeclaration()
                {
                    Name       = "From" + ToPropertyName(entityRef.Name),
                    Modifiers  = Modifiers.Public | Modifiers.Static,
                    ReturnType = type,
                    Arguments  =
                    {
                        new MethodArgumentDeclaration(GetPropertyTypeRef(entityRef.ModelRef), ToArgumentName(entityRef.Name)),
                    },
                    Statements = new ReturnStatement(new NewObjectExpression(type, new ArgumentReferenceExpression(ToArgumentName(entityRef.Name)))),
                });

                if (addNullCheck)
                {
                    fromMethod.Statements.Insert(0, fromMethod.Arguments[0].CreateThrowIfNullStatement());
                }

                // Add implicit converter
                type.AddMember(new OperatorDeclaration
                {
                    Modifiers  = Modifiers.Public | Modifiers.Static | Modifiers.Implicit,
                    ReturnType = type,
                    Arguments  =
                    {
                        new MethodArgumentDeclaration(GetPropertyTypeRef(entityRef.ModelRef), ToArgumentName(entityRef.Name)),
                    },
                    Statements =
                    {
                        new ReturnStatement(new MethodInvokeExpression(new MemberReferenceExpression(type, fromMethod.Name), new ArgumentReferenceExpression(ToArgumentName(entityRef.Name)))),
                    },
                });

                // Add implicit converter nullable
                var nullableImplicitConverter = type.AddMember(new OperatorDeclaration
                {
                    Modifiers  = Modifiers.Public | Modifiers.Static | Modifiers.Implicit,
                    ReturnType = new TypeReference(type).MakeNullable(),
                    Arguments  =
                    {
                        new MethodArgumentDeclaration(GetPropertyTypeRef(entityRef.ModelRef).MakeNullable(), ToArgumentName(entityRef.Name)),
                    },
                });

                if (entityRef.ModelRef.IsValueType)
                {
                    nullableImplicitConverter.Statements.Add(
                        new ConditionStatement
                    {
                        Condition      = new MemberReferenceExpression(new ArgumentReferenceExpression(ToArgumentName(entityRef.Name)), "HasValue"),
                        TrueStatements = new ReturnStatement(
                            new MethodInvokeExpression(
                                new MemberReferenceExpression(type, fromMethod.Name),
                                new MemberReferenceExpression(new ArgumentReferenceExpression(ToArgumentName(entityRef.Name)), "Value"))),
                        FalseStatements = new ReturnStatement(LiteralExpression.Null()),
                    });
                }
                else
                {
                    nullableImplicitConverter.Statements.Add(
                        new ConditionStatement
                    {
                        Condition = new MethodInvokeExpression(
                            new MemberReferenceExpression(typeof(object), nameof(object.ReferenceEquals)),
                            new ArgumentReferenceExpression(ToArgumentName(entityRef.Name)),
                            LiteralExpression.Null()),
                        TrueStatements  = new ReturnStatement(LiteralExpression.Null()),
                        FalseStatements = new ReturnStatement(new MethodInvokeExpression(new MemberReferenceExpression(type, fromMethod.Name), new ArgumentReferenceExpression(ToArgumentName(entityRef.Name)))),
                    });
                }

                Expression GetAssignExpression()
                {
                    Expression value = new ArgumentReferenceExpression(ToArgumentName(entityRef.Name));

                    foreach (var member in entityRef.PropertyPath)
                    {
                        value = value.CreateMemberReferenceExpression(ToPropertyName(member));
                    }

                    return(value);
                }
            }

            // ToString
            GenerateParameterEntityToString(entity, type, valueProperty);

            // Equals, GetHashCode, ==, !=
            type.Implements.Add(new TypeReference(typeof(IEquatable <>)).MakeGeneric(type));
            GenerateParameterEntityEqualMethod(type);
            GenerateParameterEntityEqualTypedMethod(type, valueProperty);
            GenerateParameterEntityEqualityOperators(type);
            GenerateParameterEntityGetHashCode(type, valueProperty);
        }
 public override void VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     this.TrySetPendingName(node.get_Parameter().get_Name(), false);
     this.VisitArgumentReferenceExpression(node);
     return;
 }
示例#23
0
 public virtual void VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
 }
 private bool CheckArgumentReference(ArgumentReferenceExpression node)
 {
     return(node != null && node.Parameter.Resolve() == parameter);
 }
 public override void Visit(ArgumentReferenceExpression node)
 {
     CannotOptimize(node);
 }
示例#26
0
 public override void VisitArgumentReferenceExpression(ArgumentReferenceExpression node)
 {
     Write(node.Parameter.Name);
 }