type.bmx 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182
  1. ' Copyright (c) 2013-2020 Bruce A Henderson
  2. '
  3. ' Based on the public domain Monkey "trans" by Mark Sibly
  4. '
  5. ' This software is provided 'as-is', without any express or implied
  6. ' warranty. In no event will the authors be held liable for any damages
  7. ' arising from the use of this software.
  8. '
  9. ' Permission is granted to anyone to use this software for any purpose,
  10. ' including commercial applications, and to alter it and redistribute it
  11. ' freely, subject to the following restrictions:
  12. '
  13. ' 1. The origin of this software must not be misrepresented; you must not
  14. ' claim that you wrote the original software. If you use this software
  15. ' in a product, an acknowledgment in the product documentation would be
  16. ' appreciated but is not required.
  17. '
  18. ' 2. Altered source versions must be plainly marked as such, and must not be
  19. ' misrepresented as being the original software.
  20. '
  21. ' 3. This notice may not be removed or altered from any source
  22. ' distribution.
  23. '
  24. SuperStrict
  25. Import "config.bmx"
  26. Include "translator.bmx"
  27. Include "decl.bmx"
  28. Include "expr.bmx"
  29. Include "stmt.bmx"
  30. Type TType
  31. Method ActualType:TType()
  32. Return Self
  33. End Method
  34. Method EqualsType:Int( ty:TType )
  35. Return False
  36. End Method
  37. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  38. Return EqualsType( ty )
  39. End Method
  40. Method WidensToType:Int( ty:TType )
  41. Return False
  42. End Method
  43. Method DistanceToType:Int(ty:TType)
  44. Return T_MAX_DISTANCE
  45. End Method
  46. Method Semant:TType(option:Int = False, callback:TCallback = Null)
  47. Return Self
  48. End Method
  49. Method GetClass:TClassDecl()
  50. Return Null
  51. End Method
  52. Method GetClassScope:TScopeDecl()
  53. Return GetClass()
  54. End Method
  55. Method ToString$()
  56. Return "??Type??"
  57. End Method
  58. Method GetSize:Int()
  59. Return WORD_SIZE
  60. End Method
  61. Method ArrayOf:TArrayType()
  62. If Not _arrayOf Then
  63. _arrayOf=New TArrayType.Create( Self )
  64. End If
  65. Return _arrayOf
  66. End Method
  67. Method OnCopy:TType() Abstract
  68. Global voidType:TVoidType=New TVoidType
  69. Global emptyArrayType:TArrayType=New TArrayType.Create( voidType )
  70. Global objectType:TIdentType=New TIdentType.Create( "brl.classes.object" )
  71. Global nullObjectType:TNullType=New TNullType
  72. Global stringType:TStringType=New TStringType
  73. Rem
  74. bbdoc: map to a pointer type
  75. End Rem
  76. Function MapToPointerType:TType(ty:TType)
  77. If ty = stringType Then
  78. ty = ty.Copy()
  79. End If
  80. Local flag:Int = T_POINTER & ty._flags
  81. If flag & T_PTR Then
  82. ty._flags :~ T_PTR
  83. ty._flags :| T_PTRPTR
  84. Return ty
  85. End If
  86. If flag & T_PTRPTR Then
  87. ty._flags :~ T_PTRPTR
  88. ty._flags :| T_PTRPTRPTR
  89. Return ty
  90. End If
  91. ty._flags :| T_PTR
  92. Return ty
  93. End Function
  94. Function MapToVarType:TType(ty:TType)
  95. If ty = stringType Then
  96. ty = ty.Copy()
  97. End If
  98. If Not (ty._flags & T_VAR) Then
  99. ty._flags :| T_VAR
  100. Return ty
  101. End If
  102. ' TODO : error if already mapped?
  103. Return ty
  104. End Function
  105. Rem
  106. bbdoc: map to a var pointer type
  107. End Rem
  108. Function MapToVarPointerType:TType(ty:TType)
  109. If ty = stringType Then
  110. ty = ty.Copy()
  111. End If
  112. If Not (ty._flags & T_VARPTR) Then
  113. ty._flags :| T_VARPTR
  114. Return ty
  115. End If
  116. Return Null
  117. End Function
  118. Rem
  119. bbdoc: map a var pointer to it's pointer equivalent (strip out var)
  120. End Rem
  121. Function MapVarPointerToPointerType:TType(ty:TType)
  122. If ty = stringType Then
  123. ty = ty.Copy()
  124. End If
  125. If (ty._flags & T_VARPTR) Then
  126. ty._flags :~ T_VARPTR
  127. Return MapToPointerType(ty)
  128. End If
  129. Return ty
  130. End Function
  131. Function MapPointerToPrim:TType(ty:TNumericType)
  132. Return MapFromPointer(ty)
  133. End Function
  134. Function MapFromPointer:TType(ty:TType)
  135. Local nty:TType = ty.Copy()
  136. If ty._flags & T_PTRPTRPTR Then
  137. nty._flags :~ T_PTRPTRPTR
  138. nty._flags :| T_PTRPTR
  139. Else If ty._flags & T_PTRPTR Then
  140. nty._flags :~ T_PTRPTR
  141. nty._flags :| T_PTR
  142. Else If ty._flags & T_PTR Then
  143. nty._flags :~ T_PTR
  144. End If
  145. Return nty
  146. End Function
  147. Field _arrayOf:TArrayType
  148. ' one or more of
  149. ' T_VAR, T_VARPTR, T_PTR, T_PTRPTR, T_PTRPTRPTR
  150. Field _flags:Int
  151. Const T_VAR:Int = $01
  152. Const T_VARPTR:Int = $02
  153. Const T_PTR:Int = $04
  154. Const T_PTRPTR:Int = $08
  155. Const T_PTRPTRPTR:Int = $10
  156. ' for strings
  157. Const T_CHAR_PTR:Int = $1000
  158. Const T_SHORT_PTR:Int = $2000
  159. Const T_POINTER:Int = T_PTR | T_PTRPTR | T_PTRPTRPTR
  160. Const T_BYTE:Int = $001
  161. Const T_SHORT:Int = $002
  162. Const T_INT:Int = $004
  163. Const T_LONG:Int = $008
  164. Const T_FLOAT:Int = $010
  165. Const T_DOUBLE:Int = $020
  166. Const T_STRING:Int = $040
  167. Const T_ARRAY:Int = $080
  168. Const T_FUNCTIONPTR:Int = $100
  169. Const T_SIZET:Int = $200
  170. Const T_UINT:Int = $400
  171. Const T_ULONG:Int = $800
  172. Const T_FLOAT64:Int = $1000
  173. Const T_INT128:Int = $2000
  174. Const T_FLOAT128:Int = $4000
  175. Const T_DOUBLE128:Int = $8000
  176. Const T_LPARAM:Int =$10000
  177. Const T_WPARAM:Int =$20000
  178. Const T_ENUM:Int =$40000
  179. Const T_MAX_DISTANCE:Int = $FFFF
  180. Method Copy:TType()
  181. Local ty:TType = OnCopy()
  182. ty._flags = _flags
  183. ty._arrayOf = _arrayOf
  184. Return ty
  185. End Method
  186. Method ToStringParts:String()
  187. Local s:String
  188. If _flags & T_PTR Then
  189. s:+ " Ptr"
  190. Else If _flags & T_PTRPTR Then
  191. s:+ " Ptr Ptr"
  192. Else If _flags & T_PTRPTRPTR Then
  193. s:+ " Ptr Ptr Ptr"
  194. End If
  195. If _flags & T_VAR Then
  196. s:+ " Var"
  197. End If
  198. Return s
  199. End Method
  200. End Type
  201. Function NewType:TType(kind:Int = 0)
  202. Local ty:TType
  203. Select kind
  204. Case TType.T_BYTE
  205. ty = New TByteType
  206. Case TType.T_SHORT
  207. ty = New TShortType
  208. Case TType.T_INT
  209. ty = New TIntType
  210. Case TType.T_UINT
  211. ty = New TUIntType
  212. Case TType.T_LONG
  213. ty = New TLongType
  214. Case TType.T_ULONG
  215. ty = New TULongType
  216. Case TType.T_SIZET
  217. ty = New TSizeTType
  218. Case TType.T_INT128
  219. ty = New TInt128Type
  220. Case TType.T_FLOAT
  221. ty = New TFloatType
  222. Case TType.T_DOUBLE
  223. ty = New TDoubleType
  224. Case TType.T_FLOAT64
  225. ty = New TFloat64Type
  226. Case TType.T_FLOAT128
  227. ty = New TFloat128Type
  228. Case TType.T_DOUBLE128
  229. ty = New TDouble128Type
  230. Case TType.T_STRING
  231. ty = New TStringType
  232. Case TType.T_ARRAY
  233. ty = New TArrayType
  234. Case TType.T_FUNCTIONPTR
  235. ty = New TFunctionPtrType
  236. Case TType.T_ENUM
  237. ty = New TEnumType
  238. Default
  239. Err "Don't have a pointer type for " + kind
  240. End Select
  241. Return ty
  242. End Function
  243. Function NewPointerType:TType(kind:Int = 0)
  244. Local ty:TType = NewType(kind)
  245. Return TType.MapToPointerType(ty)
  246. End Function
  247. Function IsPointerType:Int(ty:TType, kind:Int = 0, pType:Int = TType.T_PTR)
  248. ' TODO :
  249. If kind Then
  250. If IsType(ty, kind) Then
  251. Return ty._flags & pType
  252. Else
  253. Return False
  254. End If
  255. Else
  256. Return ty._flags & pType
  257. End If
  258. End Function
  259. Function IsNumericType:Int(ty:TType)
  260. Return (TNumericType(ty) <> Null) And Not IsPointerType(ty, 0, TType.T_POINTER)
  261. End Function
  262. Function IsType:Int(ty:TType, kind:Int)
  263. Select kind
  264. Case TType.T_BYTE
  265. Return TByteType(ty) <> Null
  266. Case TType.T_SHORT
  267. Return TShortType(ty) <> Null
  268. Case TType.T_INT
  269. Return TIntType(ty) <> Null
  270. Case TType.T_UINT
  271. Return TUIntType(ty) <> Null
  272. Case TType.T_LONG
  273. Return TLongType(ty) <> Null
  274. Case TType.T_ULONG
  275. Return TULongType(ty) <> Null
  276. Case TType.T_SIZET
  277. Return TSizeTType(ty) <> Null
  278. Case TType.T_INT128
  279. Return TInt128Type(ty) <> Null
  280. Case TType.T_FLOAT
  281. Return TFloatType(ty) <> Null
  282. Case TType.T_DOUBLE
  283. Return TDoubleType(ty) <> Null
  284. Case TType.T_FLOAT64
  285. Return TFloat64Type(ty) <> Null
  286. Case TType.T_FLOAT128
  287. Return TFloat128Type(ty) <> Null
  288. Case TType.T_DOUBLE128
  289. Return TDouble128Type(ty) <> Null
  290. Case TType.T_STRING
  291. Return TStringType(ty) <> Null
  292. Case TType.T_ARRAY
  293. Return TArrayType(ty) <> Null
  294. Case TType.T_FUNCTIONPTR
  295. Return TFunctionPtrType(ty) <> Null
  296. Case TType.T_ENUM
  297. Return TEnumType(ty) <> Null
  298. End Select
  299. Return False
  300. End Function
  301. Type TVoidType Extends TType
  302. Method EqualsType:Int( ty:TType )
  303. If opt_issuperstrict Then
  304. Return TVoidType( ty )<>Null
  305. Else
  306. Return TVoidType( ty )<>Null Or TIntType( ty) <> Null
  307. End If
  308. End Method
  309. Method ToString$()
  310. Return "Void"
  311. End Method
  312. Method OnCopy:TType()
  313. Return New TVoidType
  314. End Method
  315. End Type
  316. Type TNullType Extends TType
  317. Method EqualsType:Int( ty:TType )
  318. Return False
  319. End Method
  320. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  321. Return True
  322. End Method
  323. Method ToString$()
  324. Return "NULL"
  325. End Method
  326. Method OnCopy:TType()
  327. Return New TNullType
  328. End Method
  329. End Type
  330. Type TBoolType Extends TType
  331. Method EqualsType:Int( ty:TType )
  332. Return TBoolType( ty )<>Null
  333. End Method
  334. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  335. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or TBoolType( ty )<>Null Or (Not noExtendString And TStringType( ty )<>Null)
  336. End Method
  337. Method WidensToType:Int( ty:TType )
  338. Return IsNumericType(ty)
  339. End Method
  340. Method ToString$()
  341. Return "Bool"
  342. End Method
  343. Method GetSize:Int()
  344. Return 4
  345. End Method
  346. Method OnCopy:TType()
  347. Return New TBoolType
  348. End Method
  349. End Type
  350. Type TNumericType Extends TType
  351. Method ToPointer:TType()
  352. Local ty:TType = Copy()
  353. Return MapToPointerType(ty)
  354. End Method
  355. End Type
  356. Type TIntegralType Extends TNumericType
  357. End Type
  358. Type TIntType Extends TIntegralType
  359. Method EqualsType:Int( ty:TType )
  360. Return TIntType( ty )<>Null And (_flags = ty._flags Or ..
  361. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  362. End Method
  363. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  364. 'If TObjectType( ty )
  365. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  366. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True,,,,SCOPE_CLASS_HEIRARCHY )
  367. ' Return ctor And ctor.IsCtor()
  368. 'EndIf
  369. If _flags & T_VARPTR And (TIntType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  370. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) Or (WORD_SIZE=4 And TLParamType(ty)<>Null)
  371. End Method
  372. Method WidensToType:Int( ty:TType )
  373. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TIntType(ty)<>Null And (ty._flags & T_VAR)) Or TLongType(ty)<>Null Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null Or (WORD_SIZE=8 And TLParamType(ty)<>Null)
  374. End Method
  375. Method DistanceToType:Int(ty:TType)
  376. If IsPointerType(ty, 0, T_POINTER) Then
  377. If IsPointerType(Self, 0, T_POINTER) Then
  378. Return 0
  379. Else
  380. Return T_MAX_DISTANCE
  381. End If
  382. End If
  383. If TIntType(ty)<>Null Then
  384. Return 0
  385. End If
  386. If WORD_SIZE = 4 And TLParamType(ty)<>Null Then
  387. Return 1
  388. End If
  389. If TLongType(ty)<>Null Then
  390. Return 2
  391. End If
  392. If WORD_SIZE = 8 And TLParamType(ty)<>Null Then
  393. Return 3
  394. End If
  395. If TFloatType(ty)<>Null Then
  396. Return 4
  397. End If
  398. If TDoubleType(ty)<>Null Then
  399. Return 6
  400. End If
  401. Return T_MAX_DISTANCE
  402. End Method
  403. Method OnCopy:TType()
  404. Return New TIntType
  405. End Method
  406. Method ToString$()
  407. Return "Int" + ToStringParts()
  408. End Method
  409. Method GetSize:Int()
  410. Return 4
  411. End Method
  412. End Type
  413. Type TUIntType Extends TIntegralType
  414. Method EqualsType:Int( ty:TType )
  415. Return TUIntType( ty )<>Null And (_flags = ty._flags Or ..
  416. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  417. End Method
  418. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  419. 'If TObjectType( ty )
  420. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  421. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  422. ' Return ctor And ctor.IsCtor()
  423. 'EndIf
  424. If _flags & T_VARPTR And (TUIntType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  425. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) Or (WORD_SIZE=4 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null))
  426. End Method
  427. Method WidensToType:Int( ty:TType )
  428. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TUIntType(ty)<>Null And (ty._flags & T_VAR)) Or TIntType(ty)<> Null Or TLongType(ty)<>Null Or TULongType(ty)<>Null Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null Or (WORD_SIZE=8 And TWParamType(ty)<>Null)
  429. End Method
  430. Method DistanceToType:Int(ty:TType)
  431. If IsPointerType(ty, 0, T_POINTER) Then
  432. If IsPointerType(Self, 0, T_POINTER) Then
  433. Return 0
  434. Else
  435. Return T_MAX_DISTANCE
  436. End If
  437. End If
  438. If TUIntType(ty)<>Null Then
  439. Return 0
  440. End If
  441. If WORD_SIZE = 4 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  442. Return 1
  443. End If
  444. If TIntType(ty)<>Null Then
  445. Return 2
  446. End If
  447. If WORD_SIZE = 8 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  448. Return 3
  449. End If
  450. If TULongType(ty)<>Null Then
  451. Return 3
  452. End If
  453. If TLongType(ty)<>Null Then
  454. Return 4
  455. End If
  456. If TFloatType(ty)<>Null Then
  457. Return 5
  458. End If
  459. If TDoubleType(ty)<>Null Then
  460. Return 6
  461. End If
  462. Return T_MAX_DISTANCE
  463. End Method
  464. Method OnCopy:TType()
  465. Return New TUIntType
  466. End Method
  467. Method ToString$()
  468. Return "UInt" + ToStringParts()
  469. End Method
  470. Method GetSize:Int()
  471. Return 4
  472. End Method
  473. End Type
  474. Type TSizeTType Extends TIntegralType
  475. Method EqualsType:Int( ty:TType )
  476. Return TSizeTType( ty )<>Null And (_flags = ty._flags Or ..
  477. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  478. End Method
  479. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  480. 'If TObjectType( ty )
  481. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  482. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  483. ' Return ctor And ctor.IsCtor()
  484. 'EndIf
  485. If _flags & T_VARPTR And (TSizeTType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  486. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) Or (WORD_SIZE=4 And TUIntType(ty)<>Null) Or (WORD_SIZE=8 And TULongType(ty)<>Null)
  487. End Method
  488. Method WidensToType:Int( ty:TType )
  489. If WORD_SIZE = 4 Then
  490. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or ((TSizeTType(ty)<>Null Or TUIntType(ty)<>Null) And (ty._flags & T_VAR)) Or TIntType(ty)<>Null Or TUIntType(ty)<>Null Or TLongType(ty)<>Null Or TULongType(ty)<>Null Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null Or TWParamType(ty)<>Null Or TLParamType(ty)<>Null
  491. Else
  492. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or ((TSizeTType(ty)<>Null Or TULongType(ty)<>Null) And (ty._flags & T_VAR)) Or TLongType(ty)<>Null Or TULongType(ty)<>Null Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null Or TFloat64Type(ty)<>Null Or TWParamType(ty)<>Null Or TLParamType(ty)<>Null
  493. End If
  494. End Method
  495. Method DistanceToType:Int(ty:TType)
  496. If IsPointerType(ty, 0, T_POINTER) Then
  497. If IsPointerType(Self, 0, T_POINTER) Then
  498. Return 0
  499. Else
  500. Return T_MAX_DISTANCE
  501. End If
  502. End If
  503. If TSizeTType(ty)<>Null Then
  504. Return 0
  505. End If
  506. If TWParamType(ty)<>Null Then
  507. Return 1
  508. End If
  509. If WORD_SIZE = 4 Then
  510. If TUIntType(ty)<>Null Then
  511. Return 1
  512. End If
  513. If TIntType(ty)<>Null Then
  514. Return 2
  515. End If
  516. If TLParamType(ty)<>Null Then
  517. Return 2
  518. End If
  519. If TULongType(ty)<>Null Then
  520. Return 3
  521. End If
  522. If TLongType(ty)<>Null Then
  523. Return 4
  524. End If
  525. If TFloatType(ty)<>Null Then
  526. Return 5
  527. End If
  528. If TDoubleType(ty)<>Null Then
  529. Return 6
  530. End If
  531. Else
  532. If TULongType(ty)<>Null Then
  533. Return 1
  534. End If
  535. If TLongType(ty)<>Null Then
  536. Return 2
  537. End If
  538. If TLParamType(ty)<>Null Then
  539. Return 2
  540. End If
  541. If TFloatType(ty)<>Null Then
  542. Return 4
  543. End If
  544. If TDoubleType(ty)<>Null Then
  545. Return 6
  546. End If
  547. If TFloat64Type(ty)<>Null Then
  548. Return 8
  549. End If
  550. End If
  551. Return T_MAX_DISTANCE
  552. End Method
  553. Method OnCopy:TType()
  554. Return New TSizeTType
  555. End Method
  556. Method ToString$()
  557. Return "size_t" + ToStringParts()
  558. End Method
  559. Method GetSize:Int()
  560. Return WORD_SIZE
  561. End Method
  562. End Type
  563. Type TByteType Extends TIntegralType
  564. Method EqualsType:Int( ty:TType )
  565. Return TByteType( ty )<>Null And (_flags = ty._flags Or ..
  566. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  567. End Method
  568. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  569. 'If TObjectType( ty )
  570. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  571. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  572. ' Return ctor And ctor.IsCtor()
  573. 'EndIf
  574. If (_flags & T_VARPTR) And (TByteType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  575. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TByteVarPtrType( ty )<> Null
  576. End Method
  577. Method WidensToType:Int( ty:TType )
  578. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TByteType(ty)<>Null And (ty._flags & T_VAR)) Or TShortType(ty)<>Null Or TIntType(ty)<>Null Or TUIntType(ty)<>Null Or TLongType(ty)<>Null Or TULongType(ty)<>Null Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null Or TWParamType(ty)<>Null Or TLParamType(ty)<>Null
  579. End Method
  580. Method DistanceToType:Int(ty:TType)
  581. If IsPointerType(ty, 0, T_POINTER) Then
  582. If IsPointerType(Self, 0, T_POINTER) Then
  583. Return 0
  584. Else
  585. Return T_MAX_DISTANCE
  586. End If
  587. End If
  588. If TByteType(ty)<>Null Then
  589. Return 0
  590. End If
  591. If TShortType(ty)<>Null Then
  592. Return 2
  593. End If
  594. If WORD_SIZE = 4 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  595. Return 4
  596. End If
  597. If TUIntType(ty)<>Null Then
  598. Return 4
  599. End If
  600. If TIntType(ty)<>Null Then
  601. Return 5
  602. End If
  603. If WORD_SIZE = 4 And TLParamType(ty)<>Null Then
  604. Return 5
  605. End If
  606. If WORD_SIZE = 8 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  607. Return 6
  608. End If
  609. If TULongType(ty)<>Null Then
  610. Return 6
  611. End If
  612. If TLongType(ty)<>Null Then
  613. Return 7
  614. End If
  615. If WORD_SIZE = 8 And TLParamType(ty)<>Null Then
  616. Return 7
  617. End If
  618. If TFloatType(ty)<>Null Then
  619. Return 8
  620. End If
  621. If TDoubleType(ty)<>Null Then
  622. Return 10
  623. End If
  624. Return T_MAX_DISTANCE
  625. End Method
  626. Method OnCopy:TType()
  627. Return New TByteType
  628. End Method
  629. Method ToString$()
  630. Return "Byte" + ToStringParts()
  631. End Method
  632. Method GetSize:Int()
  633. Return 1
  634. End Method
  635. End Type
  636. Type TShortType Extends TIntegralType
  637. Method EqualsType:Int( ty:TType )
  638. Return TShortType( ty )<>Null And (_flags = ty._flags Or ..
  639. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  640. End Method
  641. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  642. 'If TObjectType( ty )
  643. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  644. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  645. ' Return ctor And ctor.IsCtor()
  646. 'EndIf
  647. If _flags & T_VARPTR And (TShortType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  648. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TShortVarPtrType( ty )<> Null
  649. End Method
  650. Method WidensToType:Int( ty:TType )
  651. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TShortType(ty)<>Null And (ty._flags & T_VAR)) Or TIntType(ty)<>Null Or TUIntType(ty)<>Null Or TLongType(ty)<>Null Or TULongType(ty)<>Null Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null Or TWParamType(ty)<>Null Or TLParamType(ty)<>Null
  652. End Method
  653. Method DistanceToType:Int(ty:TType)
  654. If IsPointerType(ty, 0, T_POINTER) Then
  655. If IsPointerType(Self, 0, T_POINTER) Then
  656. Return 0
  657. Else
  658. Return T_MAX_DISTANCE
  659. End If
  660. End If
  661. If TShortType(ty)<>Null Then
  662. Return 0
  663. End If
  664. If WORD_SIZE = 4 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  665. Return 2
  666. End If
  667. If TUIntType(ty)<>Null Then
  668. Return 2
  669. End If
  670. If TIntType(ty)<>Null Then
  671. Return 3
  672. End If
  673. If WORD_SIZE = 4 And TLParamType(ty)<>Null Then
  674. Return 3
  675. End If
  676. If WORD_SIZE = 8 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  677. Return 4
  678. End If
  679. If TULongType(ty)<>Null Then
  680. Return 4
  681. End If
  682. If TLongType(ty)<>Null Then
  683. Return 5
  684. End If
  685. If WORD_SIZE = 8 And TLParamType(ty)<>Null Then
  686. Return 5
  687. End If
  688. If TFloatType(ty)<>Null Then
  689. Return 6
  690. End If
  691. If TDoubleType(ty)<>Null Then
  692. Return 8
  693. End If
  694. Return T_MAX_DISTANCE
  695. End Method
  696. Method OnCopy:TType()
  697. Return New TShortType
  698. End Method
  699. Method ToString$()
  700. Return "Short" + ToStringParts()
  701. End Method
  702. Method GetSize:Int()
  703. Return 2
  704. End Method
  705. End Type
  706. Type TLongType Extends TIntegralType ' BaH Long
  707. Method EqualsType:Int( ty:TType )
  708. Return TLongType( ty )<>Null And (_flags = ty._flags Or ..
  709. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  710. End Method
  711. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  712. 'If TObjectType( ty )
  713. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  714. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  715. ' Return ctor And ctor.IsCtor()
  716. 'EndIf
  717. If _flags & T_VARPTR And (TLongType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  718. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TLongVarPtrType( ty )<> Null
  719. End Method
  720. Method WidensToType:Int( ty:TType )
  721. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TLongType(ty)<>Null And (ty._flags & T_VAR)) Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null Or TFloat64Type(ty)<>Null
  722. End Method
  723. Method DistanceToType:Int(ty:TType)
  724. If IsPointerType(ty, 0, T_POINTER) Then
  725. If IsPointerType(Self, 0, T_POINTER) Then
  726. Return 0
  727. Else
  728. Return T_MAX_DISTANCE
  729. End If
  730. End If
  731. If TLongType(ty)<>Null Then
  732. Return 0
  733. End If
  734. If WORD_SIZE = 8 And TLParamType(ty)<>Null Then
  735. Return 1
  736. End If
  737. If TFloatType(ty)<>Null Then
  738. Return 2
  739. End If
  740. If TDoubleType(ty)<>Null Then
  741. Return 4
  742. End If
  743. If TFloat64Type(ty)<>Null Then
  744. Return 6
  745. End If
  746. Return T_MAX_DISTANCE
  747. End Method
  748. Method OnCopy:TType()
  749. Return New TLongType
  750. End Method
  751. Method ToString$()
  752. Return "Long" + ToStringParts()
  753. End Method
  754. End Type
  755. Type TULongType Extends TIntegralType
  756. Method EqualsType:Int( ty:TType )
  757. Return TULongType( ty )<>Null And (_flags = ty._flags Or ..
  758. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  759. End Method
  760. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  761. 'If TObjectType( ty )
  762. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  763. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  764. ' Return ctor And ctor.IsCtor()
  765. 'EndIf
  766. If _flags & T_VARPTR And (TULongType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  767. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TLongVarPtrType( ty )<> Null
  768. End Method
  769. Method WidensToType:Int( ty:TType )
  770. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TULongType(ty)<>Null And (ty._flags & T_VAR)) Or TDoubleType(ty)<>Null Or TFloat64Type(ty)<>Null
  771. End Method
  772. Method DistanceToType:Int(ty:TType)
  773. If IsPointerType(ty, 0, T_POINTER) Then
  774. If IsPointerType(Self, 0, T_POINTER) Then
  775. Return 0
  776. Else
  777. Return T_MAX_DISTANCE
  778. End If
  779. End If
  780. If TULongType(ty)<>Null Then
  781. Return 0
  782. End If
  783. If WORD_SIZE = 8 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  784. Return 1
  785. End If
  786. If TLongType(ty)<>Null Then
  787. Return 2
  788. End If
  789. If TFloatType(ty)<>Null Then
  790. Return 3
  791. End If
  792. If TDoubleType(ty)<>Null Then
  793. Return 4
  794. End If
  795. If TFloat64Type(ty)<>Null Then
  796. Return 6
  797. End If
  798. Return T_MAX_DISTANCE
  799. End Method
  800. Method OnCopy:TType()
  801. Return New TULongType
  802. End Method
  803. Method ToString$()
  804. Return "ULong" + ToStringParts()
  805. End Method
  806. End Type
  807. Type TDecimalType Extends TNumericType
  808. End Type
  809. Type TFloatType Extends TDecimalType
  810. Method EqualsType:Int( ty:TType )
  811. Return TFloatType( ty )<>Null And (_flags = ty._flags Or ..
  812. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  813. End Method
  814. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  815. 'If TObjectType( ty )
  816. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  817. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  818. ' Return ctor And ctor.IsCtor()
  819. 'EndIf
  820. If _flags & T_VARPTR And (TFloatType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  821. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TFloatVarPtrType( ty )<> Null
  822. End Method
  823. Method WidensToType:Int( ty:TType )
  824. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TFloatType(ty)<>Null And (ty._flags & T_VAR)) Or TDoubleType(ty)<>Null
  825. End Method
  826. Method DistanceToType:Int(ty:TType)
  827. If IsPointerType(ty, 0, T_POINTER) Then
  828. If IsPointerType(Self, 0, T_POINTER) Then
  829. Return 0
  830. Else
  831. Return T_MAX_DISTANCE
  832. End If
  833. End If
  834. If TFloatType(ty)<>Null Then
  835. Return 0
  836. End If
  837. If TDoubleType(ty)<>Null Then
  838. Return 2
  839. End If
  840. Return T_MAX_DISTANCE
  841. End Method
  842. Method OnCopy:TType()
  843. Return New TFloatType
  844. End Method
  845. Method ToString$()
  846. Return "Float" + ToStringParts()
  847. End Method
  848. Method GetSize:Int()
  849. Return 4
  850. End Method
  851. End Type
  852. Type TDoubleType Extends TDecimalType
  853. Method EqualsType:Int( ty:TType )
  854. Return TDoubleType( ty )<>Null And (_flags = ty._flags Or ..
  855. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  856. End Method
  857. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  858. 'If TObjectType( ty )
  859. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  860. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  861. ' Return ctor And ctor.IsCtor()
  862. 'EndIf
  863. If _flags & T_VARPTR And (TDoubleType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  864. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TDoubleVarPtrType( ty )<> Null
  865. End Method
  866. Method WidensToType:Int( ty:TType )
  867. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TDoubleType(ty)<>Null And (ty._flags & T_VAR))
  868. End Method
  869. Method DistanceToType:Int(ty:TType)
  870. If IsPointerType(ty, 0, T_POINTER) Then
  871. If IsPointerType(Self, 0, T_POINTER) Then
  872. Return 0
  873. Else
  874. Return T_MAX_DISTANCE
  875. End If
  876. End If
  877. If TDoubleType(ty)<>Null Then
  878. Return 0
  879. End If
  880. Return T_MAX_DISTANCE
  881. End Method
  882. Method OnCopy:TType()
  883. Return New TDoubleType
  884. End Method
  885. Method ToString$()
  886. Return "Double" + ToStringParts()
  887. End Method
  888. End Type
  889. Type TIntrinsicType Extends TNumericType
  890. End Type
  891. Type TInt128Type Extends TIntrinsicType
  892. Method EqualsType:Int( ty:TType )
  893. Return TInt128Type( ty )<>Null And (_flags = ty._flags Or ..
  894. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  895. End Method
  896. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  897. 'If TObjectType( ty )
  898. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  899. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  900. ' Return ctor And ctor.IsCtor()
  901. 'EndIf
  902. If _flags & T_VARPTR And (TLongType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  903. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TLongVarPtrType( ty )<> Null
  904. End Method
  905. Method WidensToType:Int( ty:TType )
  906. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TInt128Type(ty)<>Null And (ty._flags & T_VAR)) Or TFloat128Type(ty)<>Null Or TDouble128Type(ty)<>Null
  907. End Method
  908. Method DistanceToType:Int(ty:TType)
  909. If IsPointerType(ty, 0, T_POINTER) Then
  910. If IsPointerType(Self, 0, T_POINTER) Then
  911. Return 0
  912. Else
  913. Return T_MAX_DISTANCE
  914. End If
  915. End If
  916. If TInt128Type(ty)<>Null Then
  917. Return 0
  918. End If
  919. If TFloat128Type(ty)<>Null Then
  920. Return 2
  921. End If
  922. If TDouble128Type(ty)<>Null Then
  923. Return 4
  924. End If
  925. Return T_MAX_DISTANCE
  926. End Method
  927. Method OnCopy:TType()
  928. Return New TInt128Type
  929. End Method
  930. Method ToString$()
  931. Return "Int128" + ToStringParts()
  932. End Method
  933. End Type
  934. Type TFloat64Type Extends TIntrinsicType
  935. Method EqualsType:Int( ty:TType )
  936. Return TFloat64Type( ty )<>Null And (_flags = ty._flags Or ..
  937. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  938. End Method
  939. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  940. 'If TObjectType( ty )
  941. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  942. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  943. ' Return ctor And ctor.IsCtor()
  944. 'EndIf
  945. If _flags & T_VARPTR And (TFloat64Type(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  946. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TDoubleVarPtrType( ty )<> Null
  947. End Method
  948. Method WidensToType:Int( ty:TType )
  949. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TFloat64Type(ty)<>Null And (ty._flags & T_VAR))
  950. End Method
  951. Method DistanceToType:Int(ty:TType)
  952. If IsPointerType(ty, 0, T_POINTER) Then
  953. If IsPointerType(Self, 0, T_POINTER) Then
  954. Return 0
  955. Else
  956. Return T_MAX_DISTANCE
  957. End If
  958. End If
  959. If TFloat64Type(ty)<>Null Then
  960. Return 0
  961. End If
  962. Return T_MAX_DISTANCE
  963. End Method
  964. Method OnCopy:TType()
  965. Return New TFloat64Type
  966. End Method
  967. Method ToString$()
  968. Return "Float64" + ToStringParts()
  969. End Method
  970. End Type
  971. Type TFloat128Type Extends TIntrinsicType
  972. Method EqualsType:Int( ty:TType )
  973. Return TFloat128Type( ty )<>Null And (_flags = ty._flags Or ..
  974. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  975. End Method
  976. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  977. 'If TObjectType( ty )
  978. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  979. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  980. ' Return ctor And ctor.IsCtor()
  981. 'EndIf
  982. If _flags & T_VARPTR And (TFloat128Type(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  983. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TDoubleVarPtrType( ty )<> Null
  984. End Method
  985. Method WidensToType:Int( ty:TType )
  986. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TFloat128Type(ty)<>Null And (ty._flags & T_VAR)) Or TInt128Type(ty)<>Null Or TDouble128Type(ty)<>Null
  987. End Method
  988. Method DistanceToType:Int(ty:TType)
  989. If IsPointerType(ty, 0, T_POINTER) Then
  990. If IsPointerType(Self, 0, T_POINTER) Then
  991. Return 0
  992. Else
  993. Return T_MAX_DISTANCE
  994. End If
  995. End If
  996. If TFloat128Type(ty)<>Null Then
  997. Return 0
  998. End If
  999. If TDouble128Type(ty)<>Null Then
  1000. Return 2
  1001. End If
  1002. If TInt128Type(ty)<>Null Then
  1003. Return 4
  1004. End If
  1005. Return T_MAX_DISTANCE
  1006. End Method
  1007. Method OnCopy:TType()
  1008. Return New TFloat128Type
  1009. End Method
  1010. Method ToString$()
  1011. Return "Float128" + ToStringParts()
  1012. End Method
  1013. End Type
  1014. Type TDouble128Type Extends TIntrinsicType
  1015. Method EqualsType:Int( ty:TType )
  1016. Return TDouble128Type( ty )<>Null And (_flags = ty._flags Or ..
  1017. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1018. End Method
  1019. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  1020. 'If TObjectType( ty )
  1021. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  1022. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  1023. ' Return ctor And ctor.IsCtor()
  1024. 'EndIf
  1025. If _flags & T_VARPTR And (TDouble128Type(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1026. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TDoubleVarPtrType( ty )<> Null
  1027. End Method
  1028. Method WidensToType:Int( ty:TType )
  1029. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TDouble128Type(ty)<>Null And (ty._flags & T_VAR)) Or TInt128Type(ty)<>Null Or TFloat128Type(ty)<>Null
  1030. End Method
  1031. Method DistanceToType:Int(ty:TType)
  1032. If IsPointerType(ty, 0, T_POINTER) Then
  1033. If IsPointerType(Self, 0, T_POINTER) Then
  1034. Return 0
  1035. Else
  1036. Return T_MAX_DISTANCE
  1037. End If
  1038. End If
  1039. If TDouble128Type(ty)<>Null Then
  1040. Return 0
  1041. End If
  1042. If TFloat128Type(ty)<>Null Then
  1043. Return 2
  1044. End If
  1045. If TInt128Type(ty)<>Null Then
  1046. Return 4
  1047. End If
  1048. Return T_MAX_DISTANCE
  1049. End Method
  1050. Method OnCopy:TType()
  1051. Return New TDouble128Type
  1052. End Method
  1053. Method ToString$()
  1054. Return "Double128" + ToStringParts()
  1055. End Method
  1056. End Type
  1057. Type TStringType Extends TType
  1058. Field cdecl:TClassDecl
  1059. Method EqualsType:Int( ty:TType )
  1060. Return TStringType( ty )<>Null And (_flags = ty._flags Or (_flags & T_VAR))
  1061. End Method
  1062. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  1063. Return EqualsType( ty ) Or (TObjectType( ty ) And TObjectType( ty ).classDecl.ident="Object") Or (TStringType(ty) And (_flags & T_VAR)) ..
  1064. Or (TStringType(ty) And (ty._flags & T_VAR)) Or (TStringType(ty) And (ty._flags & T_CHAR_PTR)) Or (TStringType(ty) And (ty._flags & T_SHORT_PTR)) ..
  1065. Or IsPointerType(ty) Or (TStringType(ty) And (_flags & T_CHAR_PTR)) Or (TStringType(ty) And (_flags & T_SHORT_PTR))
  1066. End Method
  1067. Method GetClass:TClassDecl()
  1068. If cdecl Return cdecl
  1069. Local modid$="brl.classes"
  1070. Local mdecl:TModuleDecl=_env.FindModuleDecl( modid )
  1071. If Not mdecl Err "Module '"+modid+"' not found"
  1072. 'clsid=ident[i+1..] ' BaH
  1073. 'DebugStop
  1074. cdecl=TClassDecl(mdecl.FindDecl( "string" ))
  1075. 'Return _env.FindClassDecl( "brl.classes.string" )
  1076. Return cdecl
  1077. End Method
  1078. Method Semant:TType(option:Int = 0, callback:TCallback = Null)
  1079. GetClass()
  1080. Return Self
  1081. End Method
  1082. Method OnCopy:TType()
  1083. Local ty:TStringType = New TStringType
  1084. ty.cdecl = cdecl
  1085. If _flags & T_CHAR_PTR Then
  1086. ty._flags :| T_CHAR_PTR
  1087. End If
  1088. If _flags & T_SHORT_PTR Then
  1089. ty._flags :| T_SHORT_PTR
  1090. End If
  1091. Return ty
  1092. End Method
  1093. Method ToString$()
  1094. Return "String" + ToStringParts()
  1095. End Method
  1096. Method DistanceToType:Int(ty:TType)
  1097. If TStringType(ty) Then
  1098. Return 0
  1099. End If
  1100. ' prefer Object
  1101. If TObjectType(ty)
  1102. If TObjectType(ty).classDecl.ident = "Object" Then
  1103. Return $F
  1104. End If
  1105. End If
  1106. Return T_MAX_DISTANCE
  1107. End Method
  1108. End Type
  1109. Type TArrayType Extends TType
  1110. Field elemType:TType
  1111. Field dims:Int
  1112. Field isStatic:Int
  1113. Field length:String
  1114. Method Create:TArrayType( elemType:TType, dims:Int = 1, flags:Int = 0, isStatic:Int = False, length:Int = 0 )
  1115. Self.elemType=elemType
  1116. Self.dims = dims
  1117. Self._flags = flags
  1118. Self.isStatic = isStatic
  1119. Self.length = length
  1120. Return Self
  1121. End Method
  1122. Method ActualType:TType()
  1123. Local ty:TType=elemType.ActualType()
  1124. If ty=elemType Return Self
  1125. Return New TArrayType.Create( ty )
  1126. End Method
  1127. Method EqualsType:Int( ty:TType )
  1128. Local arrayType:TArrayType=TArrayType( ty )
  1129. Return arrayType And elemType.EqualsType( arrayType.elemType ) And dims = arrayType.dims And arrayType.isStatic = isStatic And arrayType.length = length
  1130. End Method
  1131. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  1132. Local arrayType:TArrayType=TArrayType( ty )
  1133. Return (arrayType And dims = arrayType.dims And ..
  1134. (arrayType.isStatic = isStatic And arrayType.length = length) And ..
  1135. ( TVoidType( elemType ) ..
  1136. Or elemType.EqualsType( arrayType.elemType ) ..
  1137. Or ((TObjectType(elemType) Or TStringType(elemType) Or TArrayType(elemType)) And ..
  1138. (elemType.ExtendsType( arrayType.elemType ) ..
  1139. Or (TObjectType(arrayType.elemType) And TObjectType( arrayType.elemType ).classDecl.ident="Object") ..
  1140. ))) ..
  1141. ) ..
  1142. Or IsPointerType(ty, 0, TType.T_POINTER) <> Null Or (TObjectType( ty ) And TObjectType( ty ).classDecl.ident="Object")
  1143. End Method
  1144. Method Semant:TType(option:Int = False, callback:TCallback = Null)
  1145. Local ty:TType=elemType.Semant(option, callback)
  1146. If ty<>elemType Return New TArrayType.Create( ty, dims, _flags, isStatic, Int(length) )
  1147. Return Self
  1148. End Method
  1149. Method GetClass:TClassDecl()
  1150. 'Return _env.FindClassDecl( "array" )
  1151. Return TClassDecl( _env.FindDecl( "___array" ) )
  1152. End Method
  1153. Method OnCopy:TType()
  1154. Local ty:TArrayType = New TArrayType
  1155. ty.elemType = elemType
  1156. ty.dims = dims
  1157. ty.isStatic = isStatic
  1158. ty.length = length
  1159. Return ty
  1160. End Method
  1161. Method ToString$()
  1162. Local t:String = elemType.ToString()
  1163. If isStatic Then
  1164. t :+ " StaticArray[" + length + "]"
  1165. Else
  1166. t :+ " Array"
  1167. End If
  1168. Return t
  1169. End Method
  1170. Method DistanceToType:Int(ty:TType)
  1171. If TArrayType(ty) Then
  1172. Return 0
  1173. End If
  1174. ' prefer Object
  1175. If TObjectType(ty)
  1176. If TObjectType(ty).classDecl.ident = "Object" Then
  1177. Return $F
  1178. End If
  1179. End If
  1180. Return T_MAX_DISTANCE
  1181. End Method
  1182. End Type
  1183. Type TObjectType Extends TType
  1184. Field classDecl:TClassDecl
  1185. Field instance:Int
  1186. Method Create:TObjectType( classDecl:TClassDecl )
  1187. Self.classDecl=classDecl
  1188. Return Self
  1189. End Method
  1190. Method ActualType:TType()
  1191. If classDecl.actual=classDecl Return Self
  1192. Return New TObjectType.Create( TClassDecl(classDecl.actual) )
  1193. End Method
  1194. Method EqualsType:Int( ty:TType )
  1195. Local objty:TObjectType=TObjectType( ty )
  1196. Return TNullDecl(classDecl) <> Null Or (objty And (classDecl=objty.classDecl))' Or classDecl.ExtendsClass( objty.classDecl ))) 'Or TObjectVarPtrType(ty) <> Null
  1197. End Method
  1198. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  1199. If classDecl.IsStruct() Then
  1200. If IsPointerType(Self, 0, T_POINTER) And (TNumericType(ty) <> Null) And IsPointerType(ty, 0, T_POINTER) Then
  1201. Return True
  1202. End If
  1203. Return False
  1204. End If
  1205. Local objty:TObjectType=TObjectType( ty )
  1206. If objty Return classDecl.ExtendsClass( objty.classDecl )
  1207. If IsPointerType( ty, T_BYTE ) Return True
  1208. End Method
  1209. Method GetClass:TClassDecl()
  1210. Return classDecl
  1211. End Method
  1212. Method ToString$()
  1213. Return classDecl.ToTypeString()
  1214. End Method
  1215. Method OnCopy:TType()
  1216. Local ty:TObjectType = New TObjectType
  1217. ty.classDecl = classDecl
  1218. ty.instance = instance
  1219. Return ty
  1220. End Method
  1221. Method DistanceToType:Int(ty:TType)
  1222. If TObjectType(ty) Then
  1223. If classDecl = TObjectType(ty).classDecl Then
  1224. Return 0
  1225. End If
  1226. If classDecl.ExtendsClass(TObjectType(ty).classDecl) Then
  1227. Return $F
  1228. End If
  1229. End If
  1230. Return T_MAX_DISTANCE
  1231. End Method
  1232. End Type
  1233. Type TClassType Extends TType
  1234. Field classDecl:TClassDecl
  1235. Field instance:Int
  1236. Method Create:TClassType( classDecl:TClassDecl )
  1237. Self.classDecl=classDecl
  1238. Return Self
  1239. End Method
  1240. Method GetClass:TClassDecl()
  1241. Return classDecl
  1242. End Method
  1243. Method OnCopy:TType()
  1244. Local ty:TClassType = New TClassType
  1245. ty.classDecl = classDecl
  1246. ty.instance = instance
  1247. Return ty
  1248. End Method
  1249. Method ToString:String()
  1250. Return "Type"
  1251. End Method
  1252. End Type
  1253. Type TIdentType Extends TType
  1254. Field ident$
  1255. Field args:TType[]
  1256. Method Create:TIdentType( ident$,args:TType[] = Null )
  1257. Self.ident=ident
  1258. If args = Null Then
  1259. Self.args = New TType[0]
  1260. Else
  1261. Self.args=args
  1262. End If
  1263. Return Self
  1264. End Method
  1265. Method CopyToDest:TIdentType(dst:TIdentType)
  1266. dst.ident = ident
  1267. dst.args = args
  1268. Return dst
  1269. End Method
  1270. Method CopyToPointer:TIdentType(dst:TIdentType)
  1271. dst = TIdentType(MapToPointerType(dst))
  1272. dst.ident = ident
  1273. dst.args = args
  1274. Return dst
  1275. End Method
  1276. Method ActualType:TType()
  1277. InternalErr "TIdentType.ActualType"
  1278. End Method
  1279. Method EqualsType:Int( ty:TType )
  1280. InternalErr "TIdentType.EqualsType"
  1281. End Method
  1282. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  1283. InternalErr "TIdentType.ExtendsType"
  1284. End Method
  1285. 'Method Semant:TType()
  1286. ' If ident Return New TObjectType.Create( FindClass() )
  1287. ' Return New TObjectType.Create( TClassDecl.nullObjectClass )
  1288. 'End Method
  1289. Method Semant:TType(ignoreNotFoundError:Int = 0, callback:TCallback = Null)
  1290. 'If ident="IPair" DebugStop
  1291. If Not ident Return TType.nullObjectType
  1292. Local targs:TType[args.Length]
  1293. For Local i:Int=0 Until args.Length
  1294. targs[i]=args[i].Semant(ignoreNotFoundError, callback)
  1295. Next
  1296. Local tyid$,ty:TType
  1297. Local i:Int=ident.FindLast( "." )
  1298. If i=-1
  1299. tyid=ident.ToLower()
  1300. If tyid = "self" Then
  1301. ' find owning class
  1302. Local scope:TClassDecl = _env.ClassScope()
  1303. If scope Then
  1304. tyid = scope.ident
  1305. ty = New TClassType.Create(scope)
  1306. ' test for method scope - self is already an instance
  1307. Local funcScope:TFuncDecl = _env.FuncScope()
  1308. If funcScope.IsAnyMethod() Then
  1309. TClassType(ty).instance = True
  1310. End If
  1311. Else
  1312. Err "'Self' can only be used within methods."
  1313. End If
  1314. End If
  1315. If Not ty Then
  1316. ty=_env.FindType( tyid,targs, callback )
  1317. End If
  1318. ' finally scan all modules for it
  1319. If Not ty Then
  1320. For Local mdecl:TModuleDecl = EachIn _appInstance.globalImports.Values()
  1321. ty=mdecl.FindType( tyid,targs, callback )
  1322. If ty Exit
  1323. Next
  1324. Else If TIdentType(ty) Then
  1325. ty = ty.Semant()
  1326. End If
  1327. Else
  1328. Local id:String = ident.ToLower()
  1329. i = id.Find( "." )
  1330. ' try scope search first
  1331. tyid=id[..i]
  1332. If tyid = "self" Then
  1333. ' find owning class
  1334. Local scope:TClassDecl = _env.ClassScope()
  1335. If scope Then
  1336. tyid = scope.ident
  1337. ty = New TClassType.Create(scope)
  1338. ' test for method scope - self is already an instance
  1339. Local funcScope:TFuncDecl = _env.FuncScope()
  1340. If funcScope.IsAnyMethod() Then
  1341. TClassType(ty).instance = True
  1342. End If
  1343. Else
  1344. Err "'Self' can only be used within methods."
  1345. End If
  1346. End If
  1347. If Not ty Then
  1348. ty=_env.FindType( tyid,targs, callback )
  1349. End If
  1350. If Not ty Then
  1351. i = id.FindLast( "." )
  1352. ' try scope search first
  1353. tyid=id[..i]
  1354. ty=_env.FindType( tyid,targs, callback )
  1355. If Not ty Then
  1356. ' no? now try module search
  1357. Local modid$=id[..i]
  1358. Local mdecl:TModuleDecl=_env.FindModuleDecl( modid )
  1359. If Not mdecl Err "Module '"+modid+"' not found"
  1360. tyid=id[i+1..]
  1361. ty=mdecl.FindType( tyid,targs, callback )
  1362. End If
  1363. End If
  1364. EndIf
  1365. If Not ty Then
  1366. If ignoreNotFoundError Then
  1367. Return Null
  1368. End If
  1369. Err "Type '"+tyid+"' not found"
  1370. End If
  1371. If (_flags & T_VAR) Then
  1372. If TObjectType(ty) Then
  1373. ty = New TObjectType.Create(TObjectType(ty).classDecl)
  1374. ty._flags :| T_VAR
  1375. Else If TEnumType(ty) Then
  1376. ty = New TEnumType.Create(TEnumType(ty).decl)
  1377. ty._flags :| T_VAR
  1378. Else
  1379. ty = ty.Copy()
  1380. ty._flags :| T_VAR
  1381. End If
  1382. End If
  1383. If (_flags & T_POINTER) And TObjectType(ty) Then
  1384. ' FIXME #200
  1385. 'If Not TObjectType(ty).classDecl.IsExtern() Then
  1386. ' Err "Invalid Pointer type."
  1387. 'End If
  1388. ty = New TObjectType.Create(TObjectType(ty).classDecl)
  1389. ty._flags :| (_flags & T_POINTER)
  1390. End If
  1391. Return ty
  1392. End Method
  1393. Method SemantClass:TClassDecl(callback:TCallback = Null)
  1394. Local ty:TObjectType=TObjectType( Semant(False, callback) )
  1395. If Not ty Err "Type is not a class"
  1396. Return ty.classDecl
  1397. End Method
  1398. Method ToString$()
  1399. Local t$
  1400. For Local arg:TIdentType=EachIn args
  1401. If t t:+","
  1402. t:+arg.ToString()
  1403. Next
  1404. If t Return "$"+ident+"<"+t.Replace("$","")+">"
  1405. Return "$"+ident
  1406. End Method
  1407. Method OnCopy:TType()
  1408. Local ty:TIdentType = New TIdentType
  1409. ty.ident = ident
  1410. ty.args = args
  1411. Return ty
  1412. End Method
  1413. End Type
  1414. Type TExternObjectType Extends TType
  1415. Field classDecl:TClassDecl
  1416. Method Create:TExternObjectType( classDecl:TClassDecl )
  1417. Self.classDecl=classDecl
  1418. Return Self
  1419. End Method
  1420. Method ActualType:TType()
  1421. If classDecl.actual=classDecl Return Self
  1422. Return New TExternObjectType.Create( TClassDecl(classDecl.actual) )
  1423. End Method
  1424. Method EqualsType:Int( ty:TType )
  1425. Local objty:TObjectType=TObjectType( ty )
  1426. Return TNullDecl(classDecl) <> Null Or (objty And (classDecl=objty.classDecl Or classDecl.ExtendsClass( objty.classDecl ))) Or TObjectType(ty)
  1427. End Method
  1428. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  1429. Local objty:TObjectType=TObjectType( ty )
  1430. If objty Return classDecl.ExtendsClass( objty.classDecl )
  1431. If IsPointerType( ty, T_BYTE ) Return True
  1432. Local op$
  1433. If TBoolType( ty )
  1434. op="ToBool"
  1435. Else If TIntType( ty )
  1436. op="ToInt"
  1437. Else If TFloatType( ty )
  1438. op="ToFloat"
  1439. Else If TStringType( ty )
  1440. op="ToString"
  1441. Else If TLongType( ty ) ' BaH Long
  1442. op="ToLong"
  1443. Else
  1444. Return False
  1445. EndIf
  1446. Local fdecl:TFuncDecl=GetClass().FindFuncDecl( op,Null,True,,,,SCOPE_CLASS_HEIRARCHY )
  1447. Return fdecl And fdecl.IsMethod() And fdecl.retType.EqualsType( ty )
  1448. End Method
  1449. Method GetClass:TClassDecl()
  1450. Return classDecl
  1451. End Method
  1452. Method ToString$()
  1453. Return classDecl.ToTypeString()
  1454. End Method
  1455. Method OnCopy:TType()
  1456. Local ty:TExternObjectType = New TExternObjectType
  1457. ty.classDecl = classDecl
  1458. Return ty
  1459. End Method
  1460. End Type
  1461. Type TFunctionPtrType Extends TType
  1462. Field func:TFuncDecl
  1463. Method Create:TFunctionPtrType(func:TFuncDecl)
  1464. Self.func = func
  1465. Return Self
  1466. End Method
  1467. Method EqualsType:Int( ty:TType )
  1468. If Not TFunctionPtrType(ty) Then Return False
  1469. ' declared function pointer
  1470. Local tyfunc:TFuncDecl = TFunctionPtrType(ty).func
  1471. If Not tyfunc.retType.EqualsType(func.retType) Then Return False
  1472. If Not (tyfunc.argDecls.Length = func.argDecls.Length) Then Return False
  1473. For Local a:Int = 0 Until func.argDecls.Length
  1474. ' does our arg equal declared arg?
  1475. If Not func.argDecls[a].ty.EqualsType(tyfunc.argDecls[a].ty) Then Return False
  1476. Next
  1477. Return True
  1478. End Method
  1479. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  1480. If TFunctionPtrType( ty )
  1481. ' declared function pointer
  1482. Local tyfunc:TFuncDecl = TFunctionPtrType(ty).func
  1483. If Not func.retType.ExtendsType(tyfunc.retType) Then Return False
  1484. If Not (func.argDecls.Length = tyfunc.argDecls.Length) Then Return False
  1485. For Local a:Int = 0 Until func.argDecls.Length
  1486. ' does declared arg extend our arg?
  1487. If Not tyfunc.argDecls[a].ty.ExtendsType(func.argDecls[a].ty) Then Return False
  1488. Next
  1489. Return True
  1490. EndIf
  1491. Return IsPointerType( ty, 0, T_POINTER )<>Null
  1492. End Method
  1493. Method equalsDecl:Int(fdecl:TFuncDecl)
  1494. func.Semant
  1495. fdecl.Semant
  1496. ' same number of args?
  1497. If func.argDecls.length <> fdecl.argDecls.length Then
  1498. Return False
  1499. End If
  1500. ' same arg types?
  1501. For Local i:Int = 0 Until func.argDecls.length
  1502. If Not func.argDecls[i].ty.equalsType(fdecl.argDecls[i].ty) Return False
  1503. Next
  1504. ' same return type?
  1505. If Not func.retType.equalsType(fdecl.retType) Then
  1506. ' if function pointer specifies Int return type, our function can specify void...
  1507. If TIntType(func.retType) And TVoidType(fdecl.retType) Then
  1508. Return True
  1509. End If
  1510. Return False
  1511. End If
  1512. Return True
  1513. End Method
  1514. Method ToString$()
  1515. Return func.ToTypeString()
  1516. End Method
  1517. Method OnCopy:TType()
  1518. Local ty:TFunctionPtrType = New TFunctionPtrType
  1519. ty.func = func
  1520. Return ty
  1521. End Method
  1522. Method Semant:TType(option:Int = False, callback:TCallback = Null)
  1523. func.Semant()
  1524. Return Self
  1525. End Method
  1526. End Type
  1527. ' a holder during parsing which becomes the "real" var ptr type during semanting
  1528. Type TVarPtrType Extends TType
  1529. Method OnCopy:TType()
  1530. Return New TVarPtrType
  1531. End Method
  1532. End Type
  1533. Type TParamType Extends TIntegralType
  1534. End Type
  1535. Type TWParamType Extends TParamType
  1536. Method EqualsType:Int( ty:TType )
  1537. Return TWParamType( ty )<>Null And (_flags = ty._flags Or ..
  1538. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1539. End Method
  1540. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  1541. If _flags & T_VARPTR And (TWParamType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1542. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TIntVarPtrType( ty )<> Null
  1543. End Method
  1544. Method WidensToType:Int( ty:TType )
  1545. If WORD_SIZE = 4 Then
  1546. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or ((TWParamType(ty)<>Null Or TSizeTType(ty)<>Null Or TUIntType(ty)<>Null) And (ty._flags & T_VAR)) Or TIntType(ty)<>Null Or TUIntType(ty)<>Null Or TLongType(ty)<>Null Or TULongType(ty)<>Null Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null
  1547. Else
  1548. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or ((TWParamType(ty)<>Null Or TSizeTType(ty)<>Null Or TULongType(ty)<>Null) And (ty._flags & T_VAR)) Or TLongType(ty)<>Null Or TULongType(ty)<>Null Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null Or TFloat64Type(ty)<>Null
  1549. End If
  1550. End Method
  1551. Method DistanceToType:Int(ty:TType)
  1552. If IsPointerType(ty, 0, T_POINTER) Then
  1553. If IsPointerType(Self, 0, T_POINTER) Then
  1554. Return 0
  1555. Else
  1556. Return T_MAX_DISTANCE
  1557. End If
  1558. End If
  1559. If TWParamType(ty)<>Null Then
  1560. Return 0
  1561. End If
  1562. If TSizeTType(ty)<>Null Then
  1563. Return 0
  1564. End If
  1565. If WORD_SIZE = 4 Then
  1566. If TUIntType(ty)<>Null Then
  1567. Return 0
  1568. End If
  1569. If TIntType(ty)<>Null Then
  1570. Return 2
  1571. End If
  1572. If TULongType(ty)<>Null Then
  1573. Return 3
  1574. End If
  1575. If TLongType(ty)<>Null Then
  1576. Return 4
  1577. End If
  1578. If TFloatType(ty)<>Null Then
  1579. Return 5
  1580. End If
  1581. If TDoubleType(ty)<>Null Then
  1582. Return 6
  1583. End If
  1584. Else
  1585. If TULongType(ty)<>Null Then
  1586. Return 0
  1587. End If
  1588. If TLongType(ty)<>Null Then
  1589. Return 2
  1590. End If
  1591. If TFloatType(ty)<>Null Then
  1592. Return 4
  1593. End If
  1594. If TDoubleType(ty)<>Null Then
  1595. Return 6
  1596. End If
  1597. If TFloat64Type(ty)<>Null Then
  1598. Return 8
  1599. End If
  1600. End If
  1601. Return T_MAX_DISTANCE
  1602. End Method
  1603. Method OnCopy:TType()
  1604. Return New TWParamType
  1605. End Method
  1606. Method ToString$()
  1607. Return "WPARAM" + ToStringParts()
  1608. End Method
  1609. Method GetSize:Int()
  1610. Return WORD_SIZE
  1611. End Method
  1612. End Type
  1613. Type TLParamType Extends TParamType
  1614. Method EqualsType:Int( ty:TType )
  1615. Return TLParamType( ty )<>Null And (_flags = ty._flags Or ..
  1616. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1617. End Method
  1618. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  1619. If _flags & T_VARPTR And (TLParamType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1620. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TIntVarPtrType( ty )<> Null
  1621. End Method
  1622. Method WidensToType:Int( ty:TType )
  1623. If WORD_SIZE = 4 Then
  1624. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or ((TIntType(ty)<>Null Or TLParamType(ty)<>Null) And (ty._flags & T_VAR)) Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null Or TFloat64Type(ty)<>Null
  1625. Else
  1626. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or ((TLongType(ty)<>Null Or TLParamType(ty)<>Null) And (ty._flags & T_VAR)) Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null Or TFloat64Type(ty)<>Null
  1627. End If
  1628. End Method
  1629. Method DistanceToType:Int(ty:TType)
  1630. If IsPointerType(ty, 0, T_POINTER) Then
  1631. If IsPointerType(Self, 0, T_POINTER) Then
  1632. Return 0
  1633. Else
  1634. Return T_MAX_DISTANCE
  1635. End If
  1636. End If
  1637. If TLParamType(ty)<>Null Then
  1638. Return 0
  1639. End If
  1640. If WORD_SIZE = 4 Then
  1641. If TIntType(ty)<>Null Then
  1642. Return 0
  1643. End If
  1644. If TLongType(ty)<>Null Then
  1645. Return 2
  1646. End If
  1647. If TFloatType(ty)<>Null Then
  1648. Return 4
  1649. End If
  1650. If TDoubleType(ty)<>Null Then
  1651. Return 6
  1652. End If
  1653. Else
  1654. If TLongType(ty)<>Null Then
  1655. Return 0
  1656. End If
  1657. If TFloatType(ty)<>Null Then
  1658. Return 2
  1659. End If
  1660. If TDoubleType(ty)<>Null Then
  1661. Return 4
  1662. End If
  1663. If TFloat64Type(ty)<>Null Then
  1664. Return 6
  1665. End If
  1666. End If
  1667. Return T_MAX_DISTANCE
  1668. End Method
  1669. Method OnCopy:TType()
  1670. Return New TLParamType
  1671. End Method
  1672. Method ToString$()
  1673. Return "LPARAM" + ToStringParts()
  1674. End Method
  1675. Method GetSize:Int()
  1676. Return WORD_SIZE
  1677. End Method
  1678. End Type
  1679. Type TEnumType Extends TType
  1680. Field decl:TEnumDecl
  1681. Method Create:TEnumType(decl:TEnumDecl)
  1682. Self.decl = decl
  1683. Return Self
  1684. End Method
  1685. Method EqualsType:Int( ty:TType )
  1686. Local ety:TEnumType = TEnumType(ty)
  1687. Return ety And decl = ety.decl And(_flags = ty._flags Or ..
  1688. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1689. End Method
  1690. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False )
  1691. If _flags & T_VARPTR And (TEnumType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1692. Return (widensTest And WidensToType(ty))
  1693. End Method
  1694. Method WidensToType:Int( ty:TType )
  1695. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TEnumType(ty)<>Null And (ty._flags & T_VAR))
  1696. End Method
  1697. Method OnCopy:TType()
  1698. Local ty:TEnumType = New TEnumType
  1699. ty.decl = decl
  1700. Return ty
  1701. End Method
  1702. Method IsFlags:Int()
  1703. Return decl.isFlags
  1704. End Method
  1705. Method Value:String(ordinal:Int)
  1706. Return decl.values[ordinal].Value()
  1707. End Method
  1708. Method ToString$()
  1709. Return "Enum " + decl.ident + " " + ToStringParts()
  1710. End Method
  1711. Method GetClassScope:TScopeDecl()
  1712. Return decl
  1713. End Method
  1714. End Type
  1715. Type TTemplateArg
  1716. Field ident:String
  1717. Field superTy:TType[]
  1718. Method ExtendsType(ty:TType)
  1719. If Not superTy Then
  1720. superTy = New TType[0]
  1721. End If
  1722. superTy :+ [ty]
  1723. End Method
  1724. Method ToString:String()
  1725. Local s:String = ident
  1726. If superTy Then
  1727. s :+ " Extends "
  1728. For Local i:Int = 0 Until superTy.length
  1729. If i Then
  1730. s:+ " And "
  1731. End If
  1732. s :+ superTy[i].ToString()
  1733. Next
  1734. End If
  1735. End Method
  1736. End Type