Пример #1
0
        public void VisitNode(JSFieldAccess fa)
        {
            var parentBoe = ParentNode as JSBinaryOperatorExpression;
            var isWrite   = (parentBoe != null) &&
                            (parentBoe.Operator is JSAssignmentOperator) &&
                            (CurrentName == "Left");

            var targetVariable = fa.Target as JSVariable;

            if (fa.HasGlobalStateDependency)
            {
                CreateBarrier(new SlotDictionary {
                    {
                        fa.Field.Identifier,
                        isWrite ? SlotFlags.WriteGlobalState
                            : SlotFlags.ReadGlobalState
                    }
                });
            }
            else if (targetVariable != null)
            {
                CreateBarrier(new SlotDictionary {
                    {
                        String.Format("{0}.{1}", targetVariable.Identifier, fa.Field.Identifier),
                        isWrite ? SlotFlags.Assignment
                            : SlotFlags.Read
                    }
                });
            }

            VisitChildren(fa);
        }
Пример #2
0
        public void VisitNode(JSFieldAccess fa)
        {
            var field = fa.Field;
            var v     = ExtractAffectedVariable(fa.ThisReference);

            var parentNodeIndices = GetParentNodeIndices();

            if (fa.HasGlobalStateDependency)
            {
                State.StaticReferences.Add(new FunctionAnalysis1stPass.StaticReference(
                                               parentNodeIndices, StatementIndex, NodeIndex, field.Field.DeclaringType
                                               ));
            }
            else if (v != null)
            {
                State.SideEffects.Add(new FunctionAnalysis1stPass.SideEffect(
                                          parentNodeIndices, StatementIndex, NodeIndex, v, "field modified"
                                          ));
            }

            bool isRead = true;

            var enclosingBoe        = GetEnclosingNodes <JSBinaryOperatorExpression>((boe) => boe.Operator is JSAssignmentOperator).FirstOrDefault();
            var enclosingByRef      = GetEnclosingNodes <JSPassByReferenceExpression>().FirstOrDefault();
            var enclosingInvocation = GetEnclosingNodes <JSInvocationExpressionBase>().FirstOrDefault();

            if (enclosingBoe.Node != null)
            {
                if (enclosingBoe.ChildName == "Left")
                {
                    isRead = false;
                }
            }
            else if (enclosingByRef.Node != null)
            {
                isRead = false;
            }
            else if (enclosingInvocation.Node != null)
            {
                if (enclosingInvocation.ChildName == "ThisReference")
                {
                    isRead = false;
                }
            }

            State.FieldAccesses.Add(new FunctionAnalysis1stPass.FieldAccess(
                                        parentNodeIndices, StatementIndex, NodeIndex,
                                        field, isRead
                                        ));

            VisitChildren(fa);
        }
Пример #3
0
        public void VisitNode(JSFieldAccess fa)
        {
            if (fa.IsWrite)
            {
                throw new Exception("Unhandled field write: " + fa);
            }

            Formatter.WriteSExpr(
                // what?????
                "load_global",
                (_) => {
                _.WriteRaw("${0}", EscapedName(fa));
            }
                );
        }
Пример #4
0
        public void VisitNode(JSFieldAccess fa)
        {
            var field = fa.Field;
            var v     = ExtractAffectedVariable(fa.ThisReference);

            if (fa.HasGlobalStateDependency)
            {
                State.StaticReferences.Add(new FunctionAnalysis1stPass.StaticReference(
                                               GetParentNodeIndices(), StatementIndex, NodeIndex, field.Field.DeclaringType
                                               ));
            }
            else if (v != null)
            {
                State.SideEffects.Add(new FunctionAnalysis1stPass.SideEffect(
                                          GetParentNodeIndices(), StatementIndex, NodeIndex, v
                                          ));
            }

            VisitChildren(fa);
        }
Пример #5
0
        public void VisitNode(JSFieldAccess fa)
        {
            if (fa.IsWrite)
            {
                throw new Exception("Unhandled field write: " + fa);
            }

            if (fa.Field.Field.IsStatic)
            {
                Formatter.WriteRaw(
                    "(call $__get_{0})",
                    EscapedName(fa)
                    );
            }
            else
            {
                Formatter.WriteRaw(
                    "(call $__get_{0} ",
                    EscapedName(fa)
                    );
                Visit(fa.Target);
                Formatter.WriteRaw(")");
            }
        }
Пример #6
0
        protected JSExpression Translate_Ldsfld(ILExpression node, FieldReference field)
        {
            var fieldInfo = TypeInfo.GetField(field);
            if (fieldInfo == null)
                return new JSIgnoredMemberReference(true, null, JSLiteral.New(field.FullName));
            else if (TypeUtil.IsIgnoredType(field.FieldType) || fieldInfo.IsIgnored)
                return new JSIgnoredMemberReference(true, fieldInfo);

            JSExpression result = new JSFieldAccess(
                new JSType(field.DeclaringType),
                new JSField(field, fieldInfo)
            );

            if (CopyOnReturn(field.FieldType))
                result = JSReferenceExpression.New(result);

            return result;
        }
Пример #7
0
        protected JSExpression Translate_Ldfld(ILExpression node, FieldReference field)
        {
            var firstArg = node.Arguments[0];
            var translated = TranslateNode(firstArg);

            // GetCallSite and CreateCallSite produce null expressions, so we want to ignore field references containing them
            if ((translated.IsNull) && !(translated is JSUntranslatableExpression) && !(translated is JSIgnoredMemberReference))
                return new JSNullExpression();

            var fieldInfo = TypeInfo.GetField(field);
            if (TypeUtil.IsIgnoredType(field.FieldType) || (fieldInfo == null) || fieldInfo.IsIgnored)
                return new JSIgnoredMemberReference(true, fieldInfo, translated);

            JSExpression thisExpression;
            if (IsInvalidThisExpression(firstArg)) {
                if (!JSReferenceExpression.TryDereference(JSIL, translated, out thisExpression)) {
                    if (!translated.IsNull)
                        Translator.WarningFormat("Warning: Accessing {0} without a reference as this.", field.FullName);

                    thisExpression = translated;
                }
            } else {
                thisExpression = translated;
            }

            JSExpression result = new JSFieldAccess(
                thisExpression,
                new JSField(field, fieldInfo)
            );

            if (CopyOnReturn(field.FieldType))
                result = JSReferenceExpression.New(result);

            return result;
        }
Пример #8
0
 private string EscapedName(JSFieldAccess fa)
 {
     return(EscapedName(fa.Field));
 }
Пример #9
0
 public void VisitNode(JSFieldAccess fa)
 {
     VisitDotExpression(fa);
 }