[futurebasic] FBtoC: typedef usage

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2009 : Group Archive : Group : All Groups

From: "Edwards, Waverly" <Waverly.Edwards@...>
Date: Sun, 23 Aug 2009 17:36:38 -0500
I'm not sure if this is bug in FBtoC but I was creating some setters and getters and I decided that my definition was a little too long (aesthetics)
I wrote a typedef and changed my function parameters.  Afterwards I received a great number of failures.  The below is a slim version of my
program which targets the problem.


This line in particular is my problem

#define ViewDataPtr as ptr to CustomEditorViewData// typedef just for "dim record", purely aesthetic

I received the following errors in my test.  My question is, should the typedef work as expected.
I know in the old FB that it had a problem with recognizing a pointer to a record and that you just
had to accept defining a pointer as such.  

#define ViewDataPtr as pointer // really want a pointer to a record

The problem is that there is no type checking if you just define it as a pointer because the compiler
cant no what this is a pointer to, which goes to type safety.

What I have that works is this

local fn GetViewData_lineStartH( viewData as ptr to CustomEditorViewData ) as handle
'~'1
end fn = viewData.lineStartH


but what I want is this


local fn GetViewData_lineStartH( viewData as ViewDataPtr ) as handle
'~'1
end fn = viewData.lineStartH


Have I made a mistake or should this work?


Thanks,


W.



FBtoC: translating Temp Project
•• Unknown constant in line 33 of FBtoC Getter and Setter Test: lineStartH
 33:  end fn = viewData.lineStartH
                                 ^
•• Unknown constant in line 38 of FBtoC Getter and Setter Test: totalLines
 38:  end fn = viewData.totalLines
                                 ^
•• Unknown constant in line 43 of FBtoC Getter and Setter Test: maxTextWidth
 43:  end fn = viewData.maxTextWidth
                                   ^
•• Unknown constant in line 48 of FBtoC Getter and Setter Test: caretLocation
 48:  end fn = viewData.caretLocation
                                    ^
•• Unknown constant in line 52 of FBtoC Getter and Setter Test: lineStartH
 52:  viewData.lineStartH = h
                         ^
•• Unknown constant in line 59 of FBtoC Getter and Setter Test: totalLines
 59:  viewData.totalLines = totalLines
                         ^
•• Unknown constant in line 65 of FBtoC Getter and Setter Test: maxTextWidth
 65:  viewData.maxTextWidth = maxTextWidth
                           ^
Translation failed with 7 errors



// begin test code



include "Tlbx CFAttributedString.incl"
include "Tlbx CarbonEvents.incl"
include "Tlbx HIObject.incl"

#define CFMutAttrStr  as CFMutableAttributedStringRef// typedef just for "dim record", purely aesthetic

begin record CustomEditorViewData
dim as pointer          viewBuffer// buffer holding a static line buffer which contain CTLineRefs
dim as handle           lineStartH // handle to array of line-start offsets
dim as long             totalLines  // #lines
dim as long             maxTextWidth // width of longest line minus trailing white space
dim as long             caretLocation// index location of caret
dim as long             lastHorizPos// last saved horizontal position
dim as long             lastVertPos // last saved vertical position
dim as double           viewScale// scale percentage
dim as CFRange          hiliteRange// range index of hilited characters
dim as CFMutAttrStr     attrString// #define CFMutAttrStr as CFMutableAttributedStringRef
dim as HIRect           lastBounds// Used to detect bounds changes before drawing text
dim as HIViewRef        theView// this instance of the Hiview/ControlRef
end record

#define ViewDataPtr as ptr to CustomEditorViewData// typedef just for "dim record", purely aesthetic


local fn GetViewData_lineStartH_Original( viewData as ptr to CustomEditorViewData ) as handle
'~'1
end fn = viewData.lineStartH


local fn GetViewData_lineStartH( viewData as ViewDataPtr ) as handle
'~'1
end fn = viewData.lineStartH


local fn GetViewData_totalLines( viewData as ViewDataPtr ) as long
'~'1
end fn = viewData.totalLines


local fn GetViewData_maxTextWidth( viewData as ViewDataPtr ) as long
'~'1
end fn = viewData.maxTextWidth


local fn GetViewData_caretLocation( viewData as ViewDataPtr ) as long
'~'1
end fn = viewData.caretLocation

local fn SetViewData_lineStartH( viewData as ViewDataPtr , h as handle ) 
'~'1
viewData.lineStartH = h
end fn



local fn SetViewData_totalLines( viewData as ViewDataPtr , totalLines as long )
'~'1
viewData.totalLines = totalLines
end fn


local fn SetViewData_maxTextWidth( viewData as ViewDataPtr , maxTextWidth as long )
'~'1
viewData.maxTextWidth = maxTextWidth
end fn