From e6625c9e37c7884a5043d90f5bdbdcc142df168d Mon Sep 17 00:00:00 2001 From: Dino Distefano Date: Fri, 9 Oct 2015 08:53:03 -0700 Subject: [PATCH] Adding models for NSTimer and NSRunLoop Reviewed By: @dulmarod Differential Revision: D2502606 fb-gh-sync-id: 9c26103 --- infer/models/objc/src/NSRunLoop.h | 45 ++++++++++ infer/models/objc/src/NSRunLoop.m | 56 ++++++++++++ infer/models/objc/src/NSTimer.h | 59 ++++++++++++ infer/models/objc/src/NSTimer.m | 144 ++++++++++++++++++++++++++++++ 4 files changed, 304 insertions(+) create mode 100644 infer/models/objc/src/NSRunLoop.h create mode 100644 infer/models/objc/src/NSRunLoop.m create mode 100644 infer/models/objc/src/NSTimer.h create mode 100644 infer/models/objc/src/NSTimer.m diff --git a/infer/models/objc/src/NSRunLoop.h b/infer/models/objc/src/NSRunLoop.h new file mode 100644 index 000000000..17613d68b --- /dev/null +++ b/infer/models/objc/src/NSRunLoop.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + + +#import +#import + + + +@class NSTimer; + + + +@interface NSRunLoop : NSObject + ++ (NSRunLoop*) currentRunLoop; ++ (NSRunLoop*) mainRunLoop; + + +- (void) acceptInputForMode: (NSString*)mode + beforeDate: (NSDate*)limit_date; + +- (void) addTimer: (NSTimer*)timer + forMode: (NSString*)mode; + +- (NSString*) currentMode; + +- (NSDate*) limitDateForMode: (NSString*)mode; + +- (void) run; + +- (BOOL) runMode: (NSString*)mode + beforeDate: (NSDate*)date; + +- (void) runUntilDate: (NSDate*)date; + +@end + + diff --git a/infer/models/objc/src/NSRunLoop.m b/infer/models/objc/src/NSRunLoop.m new file mode 100644 index 000000000..c80958ad9 --- /dev/null +++ b/infer/models/objc/src/NSRunLoop.m @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + + +#import "NSRunLoop.h" + +@implementation NSRunLoop + ++ (NSRunLoop*) currentRunLoop { + + return [NSRunLoop alloc]; +}; + ++ (NSRunLoop*) mainRunLoop { + + return [NSRunLoop alloc]; +}; + + +- (void) acceptInputForMode: (NSString*)mode + beforeDate: (NSDate*)limit_date { +}; + +- (void) addTimer: (NSTimer*)timer + forMode: (NSString*)mode { + +}; + +- (NSString*) currentMode { + return @""; +}; + +- (NSDate*) limitDateForMode: (NSString*)mode { + + return [NSDate alloc]; +}; + +- (void) run {}; + +- (BOOL) runMode: (NSString*)mode + beforeDate: (NSDate*)date { + + int res; + return res; +}; + +- (void) runUntilDate: (NSDate*)date {}; + +@end + diff --git a/infer/models/objc/src/NSTimer.h b/infer/models/objc/src/NSTimer.h new file mode 100644 index 000000000..8ceeeec88 --- /dev/null +++ b/infer/models/objc/src/NSTimer.h @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2015 - present Facebook, Inc. +* All rights reserved. +* +* This source code is licensed under the BSD style license found in the +* LICENSE file in the root directory of this source tree. An additional grant +* of patent rights can be found in the PATENTS file in the same directory. +*/ + +#import + +@class NSInvocation; + + +@interface NSTimer : NSObject +{ + NSTimeInterval _interval; + id _info; + id _target; + SEL _selector; + unsigned _repeats:2; + unsigned _timer_filler:6; +@public + NSDate *_fireDate; + BOOL _is_valid; +} + ++ (NSTimer *) scheduledTimerWithTimeInterval:(NSTimeInterval) ti + invocation:(NSInvocation *) invocation + repeats:(BOOL) f; ++ (NSTimer *) scheduledTimerWithTimeInterval:(NSTimeInterval) ti + target:(id) object + selector:(SEL) selector + userInfo:(id) info + repeats:(BOOL) f; ++ (NSTimer *) timerWithTimeInterval:(NSTimeInterval) ti + invocation:(NSInvocation *) invocation + repeats:(BOOL) f; ++ (NSTimer *) timerWithTimeInterval:(NSTimeInterval) ti + target:(id) object + selector:(SEL) selector + userInfo:(id) info + repeats:(BOOL) f; + +- (void) fire; +- (NSDate *) fireDate; +- (id) initWithFireDate:(NSDate *) date + interval:(NSTimeInterval) seconds + target:(id) target + selector:(SEL) aSelector + userInfo:(id) userInfo + repeats:(BOOL) repeats; +- (void) invalidate; +- (BOOL) isValid; +- (void) setFireDate:(NSDate *) date; +- (NSTimeInterval) timeInterval; +- (id) userInfo; + +@end diff --git a/infer/models/objc/src/NSTimer.m b/infer/models/objc/src/NSTimer.m new file mode 100644 index 000000000..8aaf08e17 --- /dev/null +++ b/infer/models/objc/src/NSTimer.m @@ -0,0 +1,144 @@ +/* +* Copyright (c) 2015 - present Facebook, Inc. +* All rights reserved. +* +* This source code is licensed under the BSD style license found in the +* LICENSE file in the root directory of this source tree. An additional grant +* of patent rights can be found in the PATENTS file in the same directory. +*/ + +#import "NSTimer.h" +#import + +// Note: we do not link timers to NSRunLoop as this is irrelevant for +// our models. If at some point becomes important it needs to be changed. + + +void free(void *ptr); + +@implementation NSTimer + ++ (NSTimer*) timerWithTimeInterval:(NSTimeInterval)seconds + invocation:(NSInvocation *)invocation + repeats:(BOOL)f +{ + NSTimer *t = [self alloc]; + if(t) + { + t->_interval = seconds; + t->_fireDate = [NSDate alloc]; + t->_is_valid = YES; + t->_target = invocation; + t->_repeats = f; + } + return t; +} + ++ (NSTimer*) timerWithTimeInterval:(NSTimeInterval)seconds + target:(id)object + selector:(SEL)selector + userInfo:(id)info + repeats:(BOOL)f +{ + NSDate *d = [NSDate alloc]; + return [[self alloc] initWithFireDate:d + interval:seconds + target:object + selector:selector + userInfo:info + repeats:f]; +} + ++ (NSTimer*) scheduledTimerWithTimeInterval:(NSTimeInterval)ti + invocation:(NSInvocation *)invocation + repeats:(BOOL)f +{ + NSTimer *t = [self timerWithTimeInterval:ti invocation:invocation repeats:f]; + return t; +} + ++ (NSTimer*) scheduledTimerWithTimeInterval:(NSTimeInterval)ti + target:(id)object + selector:(SEL)selector + userInfo:(id)info + repeats:(BOOL)f +{ + NSTimer *t = [self timerWithTimeInterval: ti + target: object + selector: selector + userInfo: info + repeats: f]; + return t; +} + +- (id) initWithFireDate:(NSDate *) date + interval:(NSTimeInterval)seconds + target:(id)object + selector:(SEL)selector + userInfo:(id)info + repeats:(BOOL)f +{ + _interval = seconds; + _fireDate = date; + _is_valid = YES; + _selector = selector; + _target = object; + _info = info; + _repeats = f; + + return self; +} + +- (void) dealloc +{ + _fireDate=nil; + free(self); +} + +- (NSString *) description; +{ + return [NSString alloc]; +} + +// Abstract everything except making the timer invalid if +// cannot repeat +- (void) fire +{ + if(!_repeats) + _is_valid = NO; + } + +- (void) invalidate +{ + _is_valid = NO; +} + +- (BOOL) isValid { + return _is_valid; +} + +- (NSDate *) fireDate { + + return _fireDate; +} + +- (NSTimeInterval) timeInterval { + return _interval; +} + +- (id) userInfo { + return _info; +} + +- (void) setFireDate:(NSDate *)date; +{ + _fireDate =date; +} + +- (int) compare:(NSTimer*)anotherTimer +{ + int res; + return res; +} + +@end \ No newline at end of file