FFI: FFI-Tools-mt.6.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

FFI: FFI-Tools-mt.6.mcz

commits-2
Marcel Taeumel uploaded a new version of FFI-Tools to project FFI:
http://source.squeak.org/FFI/FFI-Tools-mt.6.mcz

==================== Summary ====================

Name: FFI-Tools-mt.6
Author: mt
Time: 1 June 2020, 10:07:54.246523 am
UUID: ecaa6159-1abb-7f4f-b725-22098f843230
Ancestors: FFI-Tools-mt.5

Complements FFI-Kernel-mt.83.

=============== Diff against FFI-Tools-mt.5 ===============

Item was added:
+ ----- Method: ExternalType>>printAtomicType:on: (in category '*FFI-Tools-printing') -----
+ printAtomicType: spec on: aStream
+ self assert: (spec anyMask: FFIFlagAtomic).
+ aStream nextPutAll: (#( 'void' 'unsigned char' 'unsigned char' 'signed char'
+ 'unsigned short' 'short' 'unsigned long' 'long'
+ 'unsigned long long' 'long long' 'char' 'signed char'
+ 'float' 'double') at: ((spec bitAnd: FFIAtomicTypeMask) bitShift: FFIAtomicTypeShift negated) + 1).
+ aStream space.
+ (spec anyMask: FFIFlagPointer) ifTrue:
+ [aStream nextPut: $*]!

Item was added:
+ ----- Method: ExternalType>>printStructureField:at:inClass:on:indent: (in category '*FFI-Tools-printing') -----
+ printStructureField: typeTuple at: initialSpecIndex inClass: structureClass on: aStream indent: indent
+ "Print the structure's field starting at initialSpecIndex and answer the index in compiledSpec of the subsequent type."
+ | typeName spec subStructureClass |
+ aStream tab: indent.
+ typeName := typeTuple first.
+ spec := compiledSpec at: initialSpecIndex.
+ (spec anyMask: FFIFlagAtomic) ifTrue:
+ [self printAtomicType: spec on: aStream.
+ aStream nextPutAll: (typeName ifNotNil: [typeName] ifNil: ['foo']).
+ ^initialSpecIndex + 1].
+ subStructureClass := self subStructureClassFor: typeName in: structureClass.
+ (spec bitClear: FFIStructSizeMask) = FFIFlagStructure ifTrue:
+ [| next |
+ next := initialSpecIndex + 1.
+ aStream
+ nextPutAll: subStructureClass compositeKindName;
+ nextPutAll: ' {'.
+ subStructureClass fields withIndexDo:
+ [:tuple :i|
+ aStream cr.
+ next := self printStructureField: tuple
+ at: next
+ inClass: subStructureClass
+ on: aStream
+ indent: indent + 1.
+ aStream nextPut: $;].
+ aStream crtab: indent; nextPut: $}.
+ typeName ifNotNil: [aStream space; nextPutAll: typeName].
+ self assert: (next - 1 = compiledSpec size or: [(compiledSpec at: next) = FFIFlagStructure]).
+ ^next <= compiledSpec size ifTrue: [next + 1] ifFalse: [next]].
+ self assert: (spec anyMask: FFIFlagPointer).
+ (subStructureClass isKindOf: ExternalUnion)
+ ifTrue: [aStream nextPutAll: 'union ']
+ ifFalse: [aStream nextPutAll: 'struct '].
+ aStream nextPutAll: subStructureClass name; nextPutAll: ' *'; nextPutAll: typeName.
+ ^initialSpecIndex + 1!

Item was added:
+ ----- Method: ExternalType>>printTypedefOn: (in category '*FFI-Tools-printing') -----
+ printTypedefOn: s
+ s nextPutAll: 'typedef '.
+ referentClass
+ ifNotNil:
+ [(compiledSpec first bitClear: FFIStructSizeMask) = FFIFlagStructure
+ ifTrue:
+ [| next |
+ next := 2.
+ s
+ nextPutAll: referentClass compositeKindName;
+ nextPutAll: ' {'.
+ referentClass fields withIndexDo:
+ [:tuple :i|
+ s cr.
+ next := self printStructureField: tuple
+ at: next
+ inClass: referentClass
+ on: s
+ indent: 1.
+ s nextPut: $;].
+ s cr; nextPutAll: '} '.
+ self assert: (next - 1 = compiledSpec size or: [(compiledSpec at: next) = FFIFlagStructure])]
+ ifFalse:
+ [self assert: (compiledSpec first bitClear: FFIStructSizeMask) = FFIFlagPointer.
+ s nextPutAll: referentClass name; nextPutAll: ' *foo'.
+ ^self]]
+ ifNil:
+ [self printAtomicType: compiledSpec first on: s].
+ s nextPutAll: (referentClass ifNotNil: [referentClass name] ifNil: ['foo'])!

Item was added:
+ ----- Method: ExternalType>>typedef (in category '*FFI-Tools-printing') -----
+ typedef
+ ^String streamContents: [:s| self printTypedefOn: s]!