| 1 |
|
| 2 |
|
| 3 |
import sys |
| 4 |
from bgenlocations import TOOLBOXDIR, BGENDIR |
| 5 |
sys.path.append(BGENDIR) |
| 6 |
from scantools import Scanner_OSX |
| 7 |
|
| 8 |
LONG = "CoreFoundation" |
| 9 |
SHORT = "cf" |
| 10 |
OBJECTS = ("CFTypeRef", |
| 11 |
"CFArrayRef", "CFMutableArrayRef", |
| 12 |
"CFDataRef", "CFMutableDataRef", |
| 13 |
"CFDictionaryRef", "CFMutableDictionaryRef", |
| 14 |
"CFStringRef", "CFMutableStringRef", |
| 15 |
"CFURLRef", |
| 16 |
|
| 17 |
) |
| 18 |
|
| 19 |
|
| 20 |
def main(): |
| 21 |
input = [ |
| 22 |
"CFBase.h", |
| 23 |
"CFArray.h", |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
"CFData.h", |
| 28 |
|
| 29 |
"CFDictionary.h", |
| 30 |
|
| 31 |
|
| 32 |
"CFPreferences.h", |
| 33 |
"CFPropertyList.h", |
| 34 |
|
| 35 |
"CFString.h", |
| 36 |
|
| 37 |
|
| 38 |
"CFURL.h", |
| 39 |
] |
| 40 |
output = SHORT + "gen.py" |
| 41 |
defsoutput = TOOLBOXDIR + LONG + ".py" |
| 42 |
scanner = MyScanner(input, output, defsoutput) |
| 43 |
scanner.scan() |
| 44 |
scanner.gentypetest(SHORT+"typetest.py") |
| 45 |
scanner.close() |
| 46 |
print "=== Testing definitions output code ===" |
| 47 |
execfile(defsoutput, {}, {}) |
| 48 |
print "=== Done scanning and generating, now importing the generated code... ===" |
| 49 |
exec "import " + SHORT + "support" |
| 50 |
print "=== Done. It's up to you to compile it now! ===" |
| 51 |
|
| 52 |
class MyScanner(Scanner_OSX): |
| 53 |
|
| 54 |
def destination(self, type, name, arglist): |
| 55 |
classname = "Function" |
| 56 |
listname = "functions" |
| 57 |
if arglist and name[:13] != 'CFPreferences': |
| 58 |
t, n, m = arglist[0] |
| 59 |
if t in OBJECTS and m == "InMode": |
| 60 |
classname = "Method" |
| 61 |
listname = t + "_methods" |
| 62 |
|
| 63 |
if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1: |
| 64 |
t, n, m = arglist[1] |
| 65 |
if t in OBJECTS and m == "InMode": |
| 66 |
classname = "MethodSkipArg1" |
| 67 |
listname = t + "_methods" |
| 68 |
return classname, listname |
| 69 |
|
| 70 |
def writeinitialdefs(self): |
| 71 |
self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 72 |
|
| 73 |
def makeblacklistnames(self): |
| 74 |
return [ |
| 75 |
|
| 76 |
"CFAllocatorGetDefault", |
| 77 |
"CFAllocatorSetDefault", |
| 78 |
"CFAllocatorAllocate", |
| 79 |
"CFAllocatorReallocate", |
| 80 |
"CFAllocatorDeallocate", |
| 81 |
"CFGetAllocator", |
| 82 |
|
| 83 |
"CFArrayGetValueAtIndex", |
| 84 |
|
| 85 |
"CFDataGetBytePtr", |
| 86 |
"CFDataGetMutableBytePtr", |
| 87 |
"CFDataGetBytes", |
| 88 |
|
| 89 |
"CFStringGetPascalString", |
| 90 |
"CFStringGetPascalStringPtr", |
| 91 |
"CFStringGetCStringPtr", |
| 92 |
"CFStringGetCharactersPtr", |
| 93 |
"CFStringGetCString", |
| 94 |
"CFStringGetCharacters", |
| 95 |
"CFURLCreateStringWithFileSystemPath", |
| 96 |
"CFStringCreateMutableWithExternalCharactersNoCopy", |
| 97 |
"CFStringSetExternalCharactersNoCopy", |
| 98 |
"CFStringGetCharacterAtIndex", |
| 99 |
"kCFStringEncodingInvalidId", |
| 100 |
"CFPropertyListCreateFromXMLData", |
| 101 |
] |
| 102 |
|
| 103 |
def makegreylist(self): |
| 104 |
return [] |
| 105 |
|
| 106 |
def makeblacklisttypes(self): |
| 107 |
return [ |
| 108 |
"CFComparatorFunction", |
| 109 |
"CFAllocatorContext", |
| 110 |
"void_ptr_ptr", |
| 111 |
"void_ptr", |
| 112 |
"CFArrayApplierFunction", |
| 113 |
"CFDictionaryApplierFunction", |
| 114 |
"va_list", |
| 115 |
"const_CFStringEncoding_ptr", |
| 116 |
] |
| 117 |
|
| 118 |
def makerepairinstructions(self): |
| 119 |
return [ |
| 120 |
|
| 121 |
([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")], |
| 122 |
[("UcharInBuffer", "*", "*")]), |
| 123 |
|
| 124 |
([("UniChar_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")], |
| 125 |
[("UnicodeInBuffer", "*", "*")]), |
| 126 |
|
| 127 |
|
| 128 |
([("const_char_ptr", "*", "ReturnMode")], |
| 129 |
[("return_stringptr", "*", "*")]), |
| 130 |
|
| 131 |
|
| 132 |
([("CFURLRef", "baseURL", "InMode")], |
| 133 |
[("OptionalCFURLRef", "*", "*")]), |
| 134 |
|
| 135 |
|
| 136 |
([("CFPropertyListRef", "*", "*")], |
| 137 |
[("CFTypeRef", "*", "*")]), |
| 138 |
] |
| 139 |
|
| 140 |
if __name__ == "__main__": |
| 141 |
main() |