Exemple #1
0
        /// <summary>
        ///     Translates a member reference, e.g. a field called "_value".
        /// </summary>
        public override StringBuilder VisitMemberReferenceExpression(MemberReferenceExpression memberRefExpr)
        {
            var result = new StringBuilder();

            if (!(memberRefExpr.Target is ThisReferenceExpression))
            {
                result = memberRefExpr.Target.AcceptVisitor(this);
                if (result != null && result.Length > 0)
                {
                    result.Dot();
                }
            }

            var memberName = memberRefExpr.MemberName;

            if (memberRefExpr.Target is BaseReferenceExpression)
            {
                memberName = memberName.Replace("xsl", "gl_");
            }

            // save member reference
            var memberRef = memberRefExpr.Annotation <IMemberDefinition>();

            if (result != null && memberRef != null)
            {
                var instr = GetInstructionFromStmt(memberRefExpr.GetParent <Statement>());
                RefVariables.Add(new VariableDesc {
                    Definition = memberRef, Instruction = instr
                });
            }

            return(result != null?result.Append(memberName) : new StringBuilder());
        }
Exemple #2
0
        private void OnVisitMemberReference(MemberReferenceExpression memberReferenceExpression)
        {
            var resolveResult      = Resolver.Resolve(memberReferenceExpression);
            var methodGroupResolve = resolveResult as MethodGroupResolveResult;
            var memberResolve      = resolveResult as MemberResolveResult;

            if (methodGroupResolve != null)
            {
                //handled by invocation
            }
            else if (memberResolve != null)
            {
                var memberDeclaringType = GetTypeOrCreateExternal(memberResolve.Member.DeclaringType);
                var target             = memberResolve.TargetResult;
                var currentTypeResolve = Resolver.Resolve(memberReferenceExpression.GetParent <TypeDeclaration>());
                if (currentTypeResolve.IsError)
                {
                    return;
                }
                string currentReferenceName = memberReferenceExpression.GetParent <MethodDeclaration>() == null
                    ? "(field initializer)"
                    : memberReferenceExpression.GetParent <MethodDeclaration>().Name;

                var  currentType      = GetTypeOrCreateExternal(currentTypeResolve.Type);
                var  targetType       = GetTypeOrCreateExternal(target.Type);
                bool possibleDownCall = currentType.IsParentOf(memberDeclaringType);
                bool possibleUpCall   = currentType.IsChildOf(memberDeclaringType);
                bool externalReuse    = !possibleUpCall && targetType.IsChildOf(memberDeclaringType);
                bool isDirectRelation = false;

                IEnumerable <IInheritanceRelationship> upcallRelations        = null;
                IEnumerable <IInheritanceRelationship> externalReuseRelations = null;
                if (possibleUpCall)
                {
                    upcallRelations  = currentType.GetPathTo(memberDeclaringType);
                    isDirectRelation = currentType.IsDirectChildOf(memberDeclaringType);
                }
                if (externalReuse)
                {
                    externalReuseRelations = targetType.GetPathTo(memberDeclaringType);
                    isDirectRelation       = targetType.IsDirectChildOf(memberDeclaringType);
                }

                ReuseType reuseType;
                switch (memberResolve.Member.SymbolKind)
                {
                case SymbolKind.Field:
                    reuseType = ReuseType.FieldAccess;
                    //downcall not possible
                    break;

                case SymbolKind.Property:
                case SymbolKind.Indexer:
                case SymbolKind.Event:
                case SymbolKind.Operator:
                case SymbolKind.Constructor:
                //upcall for "Super"
                case SymbolKind.Destructor:
                    reuseType = ReuseType.MethodCall;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                if (possibleUpCall)
                {
                    foreach (var item in upcallRelations)
                    {
                        item.InternalReuse.Add(new Reuse(isDirectRelation, reuseType,
                                                         memberResolve.Member.Name,
                                                         (Class)currentType, currentReferenceName));
                    }
                }
                if (externalReuse)
                {
                    foreach (var item in externalReuseRelations)
                    {
                        item.ExternalReuse.Add(new Reuse(isDirectRelation, reuseType,
                                                         memberResolve.Member.Name,
                                                         (Class)currentType, currentReferenceName));
                    }
                }
            }
            //other cases: Type/Namespace access; not relevant for this case.
        }