/// <summary> /// Creates a copy of another set of prototype exception spec rules. /// </summary> public RuleBasedPrototypeExceptionSpecs(RuleBasedPrototypeExceptionSpecs other) { this.instructionSpecs = new Dictionary <Type, Func <InstructionPrototype, ExceptionSpecification> >( other.instructionSpecs); this.intrinsicSpecs = new Dictionary <string, Func <IntrinsicPrototype, ExceptionSpecification> >( other.intrinsicSpecs); }
static RuleBasedPrototypeExceptionSpecs() { Default = new RuleBasedPrototypeExceptionSpecs(); // Instruction prototypes that never throw. Default.Register <AllocaArrayPrototype>(ExceptionSpecification.NoThrow); Default.Register <AllocaPrototype>(ExceptionSpecification.NoThrow); Default.Register <BoxPrototype>(ExceptionSpecification.NoThrow); Default.Register <ConstantPrototype>(ExceptionSpecification.NoThrow); Default.Register <CopyPrototype>(ExceptionSpecification.NoThrow); Default.Register <DynamicCastPrototype>(ExceptionSpecification.NoThrow); Default.Register <GetStaticFieldPointerPrototype>(ExceptionSpecification.NoThrow); Default.Register <LoadPrototype>(ExceptionSpecification.NoThrow); Default.Register <ReinterpretCastPrototype>(ExceptionSpecification.NoThrow); Default.Register <StorePrototype>(ExceptionSpecification.NoThrow); // Instruction prototypes that may throw because of implicit null checks. Default.Register <GetFieldPointerPrototype>( new NullCheckExceptionSpecification(0, ExceptionSpecification.ThrowAny)); Default.Register <NewDelegatePrototype>( proto => proto.Lookup == MethodLookup.Virtual ? new NullCheckExceptionSpecification(0, ExceptionSpecification.ThrowAny) : ExceptionSpecification.NoThrow); Default.Register <UnboxPrototype>( new NullCheckExceptionSpecification(0, ExceptionSpecification.ThrowAny)); // Call-like instruction prototypes. Default.Register <CallPrototype>( proto => proto.Lookup == MethodLookup.Static ? proto.Callee.GetExceptionSpecification() : ExceptionSpecification.ThrowAny); Default.Register <NewObjectPrototype>( proto => proto.Constructor.GetExceptionSpecification()); Default.Register <IndirectCallPrototype>(ExceptionSpecification.ThrowAny); // Unchecked arithmetic intrinsics never throw. foreach (var name in ArithmeticIntrinsics.Operators.All) { Default.Register( ArithmeticIntrinsics.GetArithmeticIntrinsicName(name, false), ExceptionSpecification.NoThrow); } // Array intrinsics are a little more complicated. // TODO: model bounds checks somehow. Default.Register( ArrayIntrinsics.Namespace.GetIntrinsicName(ArrayIntrinsics.Operators.GetElementPointer), ExceptionSpecification.ThrowAny); Default.Register( ArrayIntrinsics.Namespace.GetIntrinsicName(ArrayIntrinsics.Operators.LoadElement), ExceptionSpecification.ThrowAny); Default.Register( ArrayIntrinsics.Namespace.GetIntrinsicName(ArrayIntrinsics.Operators.StoreElement), ExceptionSpecification.ThrowAny); Default.Register( ArrayIntrinsics.Namespace.GetIntrinsicName(ArrayIntrinsics.Operators.GetLength), new NullCheckExceptionSpecification(0, ExceptionSpecification.ThrowAny)); Default.Register( ArrayIntrinsics.Namespace.GetIntrinsicName(ArrayIntrinsics.Operators.NewArray), ExceptionSpecification.NoThrow); // Exception intrinsics. Default.Register( ExceptionIntrinsics.Namespace.GetIntrinsicName(ExceptionIntrinsics.Operators.Capture), ExceptionSpecification.NoThrow); Default.Register( ExceptionIntrinsics.Namespace.GetIntrinsicName(ExceptionIntrinsics.Operators.GetCapturedException), ExceptionSpecification.NoThrow); Default.Register( ExceptionIntrinsics.Namespace.GetIntrinsicName(ExceptionIntrinsics.Operators.Rethrow), ExceptionSpecification.ThrowAny); Default.Register( ExceptionIntrinsics.Namespace.GetIntrinsicName(ExceptionIntrinsics.Operators.Throw), proto => ExceptionSpecification.Exact.Create(proto.ParameterTypes[0])); // Object intrinsics. // TODO: model exception thrown by type check. Default.Register( ObjectIntrinsics.Namespace.GetIntrinsicName(ObjectIntrinsics.Operators.UnboxAny), ExceptionSpecification.ThrowAny); // Memory intrinsics. Default.Register( MemoryIntrinsics.Namespace.GetIntrinsicName(MemoryIntrinsics.Operators.AllocaPinned), ExceptionSpecification.NoThrow); }
/// <summary> /// Creates a copy of another set of prototype exception spec rules. /// </summary> public RuleBasedPrototypeExceptionSpecs(RuleBasedPrototypeExceptionSpecs other) { this.store = new RuleBasedSpecStore <ExceptionSpecification>(other.store); }