Beispiel #1
0
		public void CfFieldAccessDeref()
		{
			Identifier id1 = new Identifier("v1", PrimitiveType.Word32, null);
            Expression e = new FieldAccess(PrimitiveType.Pointer32, new Dereference(PrimitiveType.Word32, id1), "foo");
			e.Accept(cf);

			Assert.AreEqual("v1->foo", sw.ToString());
		}
		public void ReferenceFieldStaticVSInstance()
		{
			int iterations = 900000000;

			FieldAccess fa = new FieldAccess();
			Object o = null;

			TestName("Static Reference Field Access Tests");
			CodeTimer.Time("Read  static reference field", iterations, () => o = FieldAccess.s_refType);
			CodeTimer.Time("Write static reference field", iterations, () => FieldAccess.s_refType = o);

			TestName("Instance Reference Field Access Tests");
			CodeTimer.Time("Read  instance reference field", iterations, () => o = fa.m_refType);
			CodeTimer.Time("Write instance reference field", iterations, () => fa.m_refType = o);		
		}
Beispiel #3
0
		public void ReadProcessData(XmlElement xmlElement, CreationContext creationContext)
		{
			String attributeName = xmlElement.GetProperty("attribute");
			creationContext.Check(((Object) attributeName != null), "attribute is a required property in element field : " + xmlElement);

			log.Debug("parsing field for attribute '" + attributeName);

			creationContext.AddUnresolvedReference(this, attributeName, creationContext.ProcessBlock, "attribute", typeof (IAttribute));

			this._state = creationContext.State;

			String accessText = xmlElement.GetProperty("access");
			creationContext.Check(((Object) accessText != null), "access is a required property in element field : " + xmlElement);
			this._access = FieldAccessHelper.fromText(accessText);
		}
		public void ValueFieldStaticVSInstance()
		{
			TestName();
			int iterations = 500000000;
            IntPtr p = IntPtr.Zero;

			FieldAccess fa = new FieldAccess();

			TestName("Static Value Field Access Tests");			
			CodeTimer.Time("Read  static value field", iterations, () => p = FieldAccess.s_valType);
			CodeTimer.Time("Write static value field", iterations, () => FieldAccess.s_valType = p);

			TestName("Instance Value Field Access Tests");
			CodeTimer.Time("Read  instance value field", iterations, () => p = fa.m_valType);
			CodeTimer.Time("Write instance value field", iterations, () => fa.m_valType = p);			
		}
Beispiel #5
0
 public static bool IsWritable(FieldAccess fieldAccess)
 {
     return((fieldAccess == FieldAccess.WRITE_ONLY) || (fieldAccess == FieldAccess.READ_WRITE) || (fieldAccess == FieldAccess.WRITE_ONLY_REQUIRED) || (fieldAccess == FieldAccess.READ_WRITE_REQUIRED));
 }
 public void CfScopeResolution()
 {
     var eq = new EquivalenceClass(new TypeVariable("Eq_2", 2));
     var sr = new ScopeResolution(eq);
     var e = new FieldAccess(PrimitiveType.Int32, sr, new StructureField(4, PrimitiveType.Int32, "i0004"));
     e.Accept(cf);
     Assert.AreEqual("Eq_2::i0004", sw.ToString());
 }
 public bool VisitFieldAccess(FieldAccess access) =>
 access.Structure.Accept(this);
Beispiel #8
0
 private void PrintResolvedFieldAccess(FieldAccess node, int indent)
 {
     AppendLine(indent, "FieldInfo = " + node.FieldInfo + " on " + node.FieldInfo.DeclaringType.Name);
     AppendLine(indent, "Operand =");
     PrintNode(node.Operand, indent + 1);
 }
Beispiel #9
0
 public virtual Expression VisitFieldAccess(FieldAccess acc)
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
 public bool VisitFieldAccess(FieldAccess acc)
 {
     throw new NotImplementedException();
 }
Beispiel #11
0
        private static FieldAccess FindFieldAccessor(Type theType)
        {
            var field = FindAutoIdAccessor(theType);

            return(FieldAccess.Create(field));
        }
Beispiel #12
0
 public static bool IsAccessible(FieldAccess fieldAccess)
 {
     return(!(fieldAccess == FieldAccess.NOT_ACCESSIBLE));
 }
Beispiel #13
0
 public BitRange VisitFieldAccess(FieldAccess acc)
 {
     throw new NotImplementedException();
 }
Beispiel #14
0
 /// <summary>
 /// Returns the value that corresponds to the given field access.
 /// </summary>
 /// <param name="access">The field access.</param>
 /// <returns>The resolved field type.</returns>
 public            ValueReference this[FieldAccess access]
 {
     get => builder[access.Index];
Beispiel #15
0
        public virtual Expression VisitFieldAccess(FieldAccess acc)
        {
            var str = acc.Structure.Accept(this);

            return(new FieldAccess(acc.DataType, str, acc.Field));
        }
Beispiel #16
0
 void IExpressionVisitor.VisitFieldAccess(FieldAccess acc)
 {
     throw new NotImplementedException();
 }
Beispiel #17
0
 public ValueSet VisitFieldAccess(FieldAccess acc)
 {
     throw new NotImplementedException();
 }
 private void PrintResolvedFieldAccess(FieldAccess node, int indent)
 {
     AppendLine(indent, "FieldInfo = " + node.FieldInfo + " on " + node.FieldInfo.DeclaringType.Name);
     AppendLine(indent, "Operand =");
     PrintNode(node.Operand, indent + 1);
 }
 /// <summary>
 /// Appends the referenced field accessor.
 /// </summary>
 /// <param name="fieldAccess">The field access.</param>
 public void AppendFieldViaPtr(FieldAccess fieldAccess)
 {
     stringBuilder.Append("->");
     AppendFieldName(fieldAccess.Index);
 }
Beispiel #20
0
 public void VisitFieldAccess(FieldAccess access)
 {
     throw new NotImplementedException();
 }
 public override void VisitFieldAccess(FieldAccess acc)
 {
     throw new NotImplementedException();
 }
Beispiel #22
0
 public DataType VisitFieldAccess(FieldAccess acc)
 {
     throw new NotImplementedException();
 }
Beispiel #23
0
 public static bool IsRequired(FieldAccess fieldAccess)
 {
     return((fieldAccess == FieldAccess.WRITE_ONLY_REQUIRED) || (fieldAccess == FieldAccess.READ_WRITE_REQUIRED));
 }
Beispiel #24
0
 public virtual void VisitFieldAccess(FieldAccess acc)
 {
     acc.Structure.Accept(this);
 }
Beispiel #25
0
		public static bool IsWritable(FieldAccess fieldAccess)
		{
			return ((fieldAccess == FieldAccess.WRITE_ONLY) || (fieldAccess == FieldAccess.READ_WRITE) || (fieldAccess == FieldAccess.WRITE_ONLY_REQUIRED) || (fieldAccess == FieldAccess.READ_WRITE_REQUIRED));
		}
Beispiel #26
0
 public SlicerResult VisitFieldAccess(FieldAccess acc, BackwardSlicerContext ctx)
 {
     throw new NotImplementedException();
 }
Beispiel #27
0
            public void FieldAccess(FieldAccess fieldAccess)
            {
                bool fieldAsParameter = _fieldAsParameter;

                bool loadAddress =
                    fieldAccess.FieldInfo.FieldType.IsValueType &&
                    fieldAsParameter &&
                    !fieldAccess.FieldInfo.IsInitOnly;

                if (!(fieldAccess.Operand is TypeAccess))
                {
                    _fieldAsParameter = true;

                    try
                    {
                        fieldAccess.Operand.Accept(this);
                    }
                    finally
                    {
                        _fieldAsParameter = fieldAsParameter;
                    }

                    if (loadAddress)
                        _il.Emit(OpCodes.Ldflda, fieldAccess.FieldInfo);
                    else
                        _il.Emit(OpCodes.Ldfld, fieldAccess.FieldInfo);
                }
                else
                {
                    if (loadAddress)
                        _il.Emit(OpCodes.Ldsflda, fieldAccess.FieldInfo);
                    else
                        _il.Emit(OpCodes.Ldsfld, fieldAccess.FieldInfo);
                }

                if (
                    fieldAccess.FieldInfo.FieldType.IsValueType &&
                    fieldAsParameter &&
                    fieldAccess.FieldInfo.IsInitOnly
                ) {
                    var builder = _il.DeclareLocal(fieldAccess.FieldInfo.FieldType);

                    _il.Emit(OpCodes.Stloc, builder);
                    _il.Emit(OpCodes.Ldloca, builder);
                }
            }
Beispiel #28
0
 public static string ToTestString(this FieldAccess fieldAccess) =>
 $"{fieldAccess.This?.ToTestString() ?? fieldAccess.Object?.ToTestString() ?? fieldAccess.Classname.ToTestString()}" +
 $".{fieldAccess.Field.ToTestString()}";
Beispiel #29
0
        /// <summary>
        /// evaluates expression.
        /// This method is used by TemplateManager extensibility.
        /// </summary>
        public object EvalExpression(Expression exp)
        {
            currentExpression = exp;

            try
            {
                if (exp is StringLiteral)
                {
                    return(((StringLiteral)exp).Content);
                }
                else if (exp is Name)
                {
                    return(GetValue(((Name)exp).Id));
                }
                else if (exp is FieldAccess)
                {
                    FieldAccess fa           = (FieldAccess)exp;
                    object      obj          = EvalExpression(fa.Exp);
                    string      propertyName = fa.Field == "channelid"?"catalogid":fa.Field;//因为obj里面没有channelid,而对应的是catalgoid
                    return(EvalProperty(obj, propertyName));
                }
                else if (exp is MethodCall)
                {
                    MethodCall ma         = (MethodCall)exp;
                    object     obj        = EvalExpression(ma.CallObject);
                    string     methodName = ma.Name;

                    return(EvalMethodCall(obj, methodName, EvalArguments(ma.Args)));
                }
                else if (exp is IntLiteral)
                {
                    return(((IntLiteral)exp).Value);
                }
                else if (exp is DoubleLiteral)
                {
                    return(((DoubleLiteral)exp).Value);
                }
                else if (exp is FCall)
                {
                    FCall fcall = (FCall)exp;
                    if (!functions.ContainsKey(fcall.Name))
                    {
                        string msg = string.Format("函数 '{0}' 未定义.", fcall.Name);
                        throw new TemplateRuntimeException(msg, exp.Line, exp.Col);
                    }

                    TemplateFunction func   = functions[fcall.Name];
                    object[]         values = EvalArguments(fcall.Args);

                    return(func(values));
                }
                else if (exp is StringExpression)
                {
                    StringExpression stringExp = (StringExpression)exp;
                    StringBuilder    sb        = new StringBuilder();
                    foreach (Expression ex in stringExp.Expressions)
                    {
                        sb.Append(EvalExpression(ex));
                    }

                    return(sb.ToString());
                }
                else if (exp is BinaryExpression)
                {
                    return(EvalBinaryExpression(exp as BinaryExpression));
                }
                else if (exp is ArrayAccess)
                {
                    return(EvalArrayAccess(exp as ArrayAccess));
                }
                else
                {
                    throw new TemplateRuntimeException("Invalid expression type: " + exp.GetType().Name, exp.Line, exp.Col);
                }
            }
            catch (TemplateRuntimeException ex)
            {
                DisplayError(ex);
                return(null);
            }
            catch (Exception ex)
            {
                DisplayError(new TemplateRuntimeException(ex.Message, currentExpression.Line, currentExpression.Col));
                return(null);
            }
        }
Beispiel #30
0
		public static bool IsAccessible(FieldAccess fieldAccess)
		{
			return (!(fieldAccess == FieldAccess.NOT_ACCESSIBLE));
		}
Beispiel #31
0
        public Expression VisitPointer(Pointer ptr)
        {
            Expression e = c;

            if (IsSegmentPointer(ptr))
            {
                Identifier segID;
                if (mpSelectorToSegId.TryGetValue(c.ToUInt16(), out segID))
                {
                    return(segID);
                }
                return(e);
            }
            else if (GlobalVars != null)
            {
                // Null pointer.
                if (c.IsZero)
                {
                    var np = Address.Create(ptr, 0);
                    np.TypeVariable = c.TypeVariable;
                    np.DataType     = c.DataType;
                    return(np);
                }

                var addr = program.Platform.MakeAddressFromConstant(c);
                // An invalid pointer -- often used as sentinels in code.
                if (!program.SegmentMap.IsValidAddress(addr))
                {
                    //$TODO: probably should use a reinterpret_cast here.
                    var ce = new Cast(c.DataType, c);
                    ce.TypeVariable = c.TypeVariable;
                    ce.DataType     = ptr;
                    return(ce);
                }

                var dt = ptr.Pointee.ResolveAs <DataType>();
                if (IsCharPtrToReadonlySection(c, dt))
                {
                    PromoteToCString(c, dt);
                    return(ReadNullTerminatedString(c, dt));
                }
                StructureField f          = EnsureFieldAtOffset(GlobalVars, dt, c.ToInt32());
                var            ptrGlobals = new Pointer(GlobalVars, platform.PointerType.Size);
                e = new FieldAccess(ptr.Pointee, new Dereference(ptrGlobals, globals), f);
                if (dereferenced)
                {
                    e.DataType = ptr.Pointee;
                }
                else
                {
                    var array = f.DataType as ArrayType;
                    if (array != null) // C language rules 'promote' arrays to pointers.
                    {
                        e.DataType = program.TypeFactory.CreatePointer(
                            array.ElementType,
                            platform.PointerType.Size);
                    }
                    else
                    {
                        e = new UnaryExpression(Operator.AddrOf, ptr, e);
                    }
                }
            }
            return(e);
        }
Beispiel #32
0
		public static bool IsRequired(FieldAccess fieldAccess)
		{
			return ((fieldAccess == FieldAccess.WRITE_ONLY_REQUIRED) || (fieldAccess == FieldAccess.READ_WRITE_REQUIRED));
		}
Beispiel #33
0
 public virtual Expression VisitFieldAccess(FieldAccess acc)
 {
     acc.Structure = acc.Structure.Accept(this);
     return(acc);
 }
        private void HandleCompositeCommand(JdwpPacket packet)
        {
            var data = packet.Data;
            var suspendPolicy = (Jdwp.SuspendPolicy) data.GetByte();
            var count = data.GetInt();

            for (var i = 0; i < count; i++)
            {
                var eventKind = (Jdwp.EventKind) data.GetByte();
                JdwpEvent evt;
                switch (eventKind)
                {
                    case Jdwp.EventKind.VmInit:
                        evt = new VmStart(data);
                        break;
                    case Jdwp.EventKind.SingleStep:
                        evt = new SingleStep(data);
                        break;
                    case Jdwp.EventKind.BreakPoint:
                        evt = new Breakpoint(data);
                        break;
                    case Jdwp.EventKind.MethodEntry:
                        evt = new MethodEntry(data);
                        break;
                    case Jdwp.EventKind.MethodExit:
                        evt = new MethodExit(data);
                        break;
                    case Jdwp.EventKind.Exception:
                        evt = new Exception(data);
                        break;
                    case Jdwp.EventKind.ThreadStart:
                        evt = new ThreadStart(data);
                        break;
                    case Jdwp.EventKind.ThreadEnd:
                        evt = new ThreadDeath(data);
                        break;
                    case Jdwp.EventKind.ClassPrepare:
                        evt = new ClassPrepare(data);
                        break;
                    case Jdwp.EventKind.ClassUnload:
                        evt = new ClassUnload(data);
                        break;
                    case Jdwp.EventKind.FieldAccess:
                        evt = new FieldAccess(data);
                        break;
                    case Jdwp.EventKind.FieldModification:
                        evt = new FieldModification(data);
                        break;
                    case Jdwp.EventKind.VmDeath:
                        evt = new VmDeath(data);
                        break;
                    default:
                        throw new ArgumentException("Unknown event kind in compositive command " + (int)eventKind);
                }
                DLog.Debug(DContext.DebuggerLibDebugger, "JDWP event {0} {1}", eventKind, evt);
                Task.Factory.StartNew(() => {
                    evt.Accept(compositeCommandProcessor, suspendPolicy);
                });
            }
        }
Beispiel #35
0
 public bool VisitFieldAccess(FieldAccess acc, TypeVariable tv)
 {
     throw new NotImplementedException();
 }
Beispiel #36
0
        Expression PrimaryExpression()
        {
            if (Current.TokenKind == TokenKind.StringStart)
            {
                return(ReadString());
            }
            else if (Current.TokenKind == TokenKind.ID)
            {
                Token id = Consume();

                Expression exp = null;

                // if ( follows ID, we have a function call
                if (Current.TokenKind == TokenKind.LParen)
                {
                    Consume();  // consume LParen
                    Expression[] args = ReadArguments();
                    Consume(TokenKind.RParen);

                    exp = new FCall(id.Line, id.Col, id.Data, args);
                }
                else  // else, we just have id
                {
                    exp = new Name(id.Line, id.Col, id.Data);
                }

                // while we have ".", keep chaining up field access or method call
                while (Current.TokenKind == TokenKind.Dot || Current.TokenKind == TokenKind.LBracket)
                {
                    if (Current.TokenKind == TokenKind.Dot)
                    {
                        Consume();                           // consume DOT
                        Token field = Consume(TokenKind.ID); // consume ID after dot

                        // if "(" after ID, then it's a method call
                        if (Current.TokenKind == TokenKind.LParen)
                        {
                            Consume();                 // consume "("
                            Expression[] args = ReadArguments();
                            Consume(TokenKind.RParen); // read ")"

                            exp = new MethodCall(field.Line, field.Col, exp, field.Data, args);
                        }
                        else
                        {
                            exp = new FieldAccess(field.Line, field.Col, exp, field.Data);
                        }
                    }
                    else // must be LBracket
                    {
                        // array access
                        Token bracket = Current;
                        Consume(); // consume [
                        Expression indexExp = TopExpression();
                        Consume(TokenKind.RBracket);

                        exp = new ArrayAccess(bracket.Line, bracket.Col, exp, indexExp);
                    }
                }

                return(exp);
            }
            else if (Current.TokenKind == TokenKind.Integer)
            {
                int        value      = Int32.Parse(Current.Data);
                IntLiteral intLiteral = new IntLiteral(Current.Line, Current.Col, value);
                Consume(); // consume int
                return(intLiteral);
            }
            else if (Current.TokenKind == TokenKind.Double)
            {
                double        value    = Double.Parse(Current.Data);
                DoubleLiteral dLiteral = new DoubleLiteral(Current.Line, Current.Col, value);
                Consume(); // consume int
                return(dLiteral);
            }
            else if (Current.TokenKind == TokenKind.LParen)
            {
                Consume();                 // eat (
                Expression exp = TopExpression();
                Consume(TokenKind.RParen); // eat )

                return(exp);
            }
            else
            {
                throw new ParseException("Invalid token in expression: " + Current.TokenKind + ". Was expecting ID or string.", Current.Line, Current.Col);
            }
        }
        private void HandleCompositeCommand(JdwpPacket packet)
        {
            var data = packet.Data;
            var suspendPolicy = (Jdwp.SuspendPolicy) data.GetByte();
            var count = data.GetInt();

            for (var i = 0; i < count; i++)
            {
                var eventKind = (Jdwp.EventKind) data.GetByte();
                JdwpEvent evt;
                switch (eventKind)
                {
                    case Jdwp.EventKind.VmInit:
                        evt = new VmStart(data);
                        break;
                    case Jdwp.EventKind.SingleStep:
                        evt = new SingleStep(data);
                        break;
                    case Jdwp.EventKind.BreakPoint:
                        evt = new Breakpoint(data);
                        break;
                    case Jdwp.EventKind.MethodEntry:
                        evt = new MethodEntry(data);
                        break;
                    case Jdwp.EventKind.MethodExit:
                        evt = new MethodExit(data);
                        break;
                    case Jdwp.EventKind.Exception:
                        evt = new Exception(data);
                        break;
                    case Jdwp.EventKind.ThreadStart:
                        evt = new ThreadStart(data);
                        break;
                    case Jdwp.EventKind.ThreadEnd:
                        evt = new ThreadDeath(data);
                        break;
                    case Jdwp.EventKind.ClassPrepare:
                        evt = new ClassPrepare(data);
                        break;
                    case Jdwp.EventKind.ClassUnload:
                        evt = new ClassUnload(data);
                        break;
                    case Jdwp.EventKind.FieldAccess:
                        evt = new FieldAccess(data);
                        break;
                    case Jdwp.EventKind.FieldModification:
                        evt = new FieldModification(data);
                        break;
                    case Jdwp.EventKind.VmDeath:
                        evt = new VmDeath(data);
                        break;
                    default:
                        throw new ArgumentException("Unknown event kind in compositive command " + (int)eventKind);
                }
                DLog.Debug(DContext.DebuggerLibDebugger, "JDWP event {0} {1}", eventKind, evt);
                Task.Factory.StartNew(() => {
                    evt.Accept(compositeCommandProcessor, suspendPolicy);
                }).ContinueWith(task =>
                {
                    DLog.Error(DContext.DebuggerLibJdwpConnection, "HandleCompositeCommand: Internal failure on event processing. SuspendPolicy was {1}; IsCancelled={0}. Exception={1}", suspendPolicy, task.IsCanceled, task.Exception);
                    if (suspendPolicy != Jdwp.SuspendPolicy.None)
                    {
                        // we should better resume the VM, as the command handler may have failed to do so.
                        if(Connected)
                            VirtualMachine.ResumeAsync();
                    }
                }, TaskContinuationOptions.NotOnRanToCompletion);
            }
        }
Beispiel #38
0
		public void VisitFieldAccess(FieldAccess acc)
		{
			int prec = SetPrecedence(PrecedenceFieldAccess);
			Dereference d = acc.Structure as Dereference;
            if (d != null)
            {
                d.Expression.Accept(this);
                writer.Write("->{0}", acc.Field.Name);
            }
            else
            {
                var scope = acc.Structure as ScopeResolution;
                if (scope != null)
                {
                    scope.Accept(this);
                    writer.Write("::{0}", acc.Field.Name);
                }
                else
                {
                    acc.Structure.Accept(this);
                    writer.Write(".{0}", acc.Field.Name);
                }
            }
			ResetPresedence(prec);
		}
Beispiel #39
0
 /// <summary>
 /// Returns the field type that corresponds to the given field access.
 /// </summary>
 /// <param name="access">The field access.</param>
 /// <returns>The resolved field type.</returns>
 public                                              TypeNode this[FieldAccess access] => allFieldsBuilder[access.Index];
		public override void VisitFieldAccess(FieldAccess acc)
		{
			throw new NotImplementedException();
		}
Beispiel #41
0
 public void VisitFieldAccess(FieldAccess access)
 {
     throw new NotImplementedException();
 }
		public virtual void VisitFieldAccess(FieldAccess acc)
		{
			acc.Structure.Accept(this);
		}
Beispiel #43
0
        private void visitExpression(Expression expression)
        {
            if (expression is Name)
            {
                WriteLine("Name: " + ((Name)expression).Id);
            }
            else if (expression is FCall)
            {
                FCall fcall = (FCall)expression;

                WriteLine("FCall: " + fcall.Name);

                WriteLine("Parameters: ");

                foreach (Expression exp in fcall.Args)
                {
                    visitExpression(exp);
                }
            }
            else if (expression is FieldAccess)
            {
                FieldAccess fa = (FieldAccess)expression;
                WriteLine("FieldAccess: " + fa.Exp + "." + fa.Field);
            }
            else if (expression is StringLiteral)
            {
                StringLiteral literal = (StringLiteral)expression;

                if (literal.Content.Length > 50)
                {
                    WriteLine("String: " + literal.Content.Substring(0, 50) + "...");
                }
                else
                {
                    WriteLine("String: " + literal.Content);
                }
            }
            else if (expression is StringExpression)
            {
                StringExpression sexp = (StringExpression)expression;
                WriteLine("StringExpression");

                foreach (Expression exp in sexp.Expressions)
                {
                    visitExpression(exp);
                }
            }
            else if (expression is BinaryExpression)
            {
                BinaryExpression sexp = (BinaryExpression)expression;
                WriteLine("BinaryExpression");

                visitExpression(sexp.Lhs);

                WriteLine("Operator " + sexp.Operator.ToString());

                visitExpression(sexp.Rhs);
            }
            else
            {
                WriteLine("Expression: " + expression.GetType().ToString());
            }
        }