type.bmx 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537
  1. ' Copyright (c) 2013-2025 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, ignoreObjectSubclasses: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_LONGINT:Int =$80000
  180. Const T_ULONGINT:Int =$100000
  181. Const T_MAX_DISTANCE:Int = $FFFF
  182. Method Copy:TType()
  183. Local ty:TType = OnCopy()
  184. ty._flags = _flags
  185. ty._arrayOf = _arrayOf
  186. Return ty
  187. End Method
  188. Method ToStringParts:String()
  189. Local s:String
  190. If _flags & T_PTR Then
  191. s:+ " Ptr"
  192. Else If _flags & T_PTRPTR Then
  193. s:+ " Ptr Ptr"
  194. Else If _flags & T_PTRPTRPTR Then
  195. s:+ " Ptr Ptr Ptr"
  196. End If
  197. If _flags & T_VAR Then
  198. s:+ " Var"
  199. End If
  200. If _flags & T_VARPTR Then
  201. s:+ " VarPtr"
  202. End If
  203. Return s
  204. End Method
  205. Method IsFlagEquivalent:Int(ty:TType)
  206. Return _flags = ty._flags Or ..
  207. (Not IsPointerType(Self, 0, TType.T_POINTER) And (ty._flags & T_VAR)) Or ..
  208. (Not IsPointerType(ty, 0, TType.T_POINTER) And (_flags & T_VAR)) Or ..
  209. (IsPointerType(Self, 0, TType.T_POINTER) And (ty._flags & T_VARPTR)) Or ..
  210. (IsPointerType(ty, 0, TType.T_POINTER) And (_flags & T_VARPTR))
  211. End Method
  212. End Type
  213. Function NewType:TType(kind:Int = 0)
  214. Local ty:TType
  215. Select kind
  216. Case TType.T_BYTE
  217. ty = New TByteType
  218. Case TType.T_SHORT
  219. ty = New TShortType
  220. Case TType.T_INT
  221. ty = New TIntType
  222. Case TType.T_UINT
  223. ty = New TUIntType
  224. Case TType.T_LONG
  225. ty = New TLongType
  226. Case TType.T_ULONG
  227. ty = New TULongType
  228. Case TType.T_SIZET
  229. ty = New TSizeTType
  230. Case TType.T_INT128
  231. ty = New TInt128Type
  232. Case TType.T_FLOAT
  233. ty = New TFloatType
  234. Case TType.T_DOUBLE
  235. ty = New TDoubleType
  236. Case TType.T_FLOAT64
  237. ty = New TFloat64Type
  238. Case TType.T_FLOAT128
  239. ty = New TFloat128Type
  240. Case TType.T_DOUBLE128
  241. ty = New TDouble128Type
  242. Case TType.T_STRING
  243. ty = New TStringType
  244. Case TType.T_ARRAY
  245. ty = New TArrayType
  246. Case TType.T_FUNCTIONPTR
  247. ty = New TFunctionPtrType
  248. Case TType.T_ENUM
  249. ty = New TEnumType
  250. Case TType.T_LONGINT
  251. ty = New TLongIntType
  252. Case TType.T_ULONGINT
  253. ty = New TULongIntType
  254. Default
  255. Err "Don't have a pointer type for " + kind
  256. End Select
  257. Return ty
  258. End Function
  259. Function NewPointerType:TType(kind:Int = 0)
  260. Local ty:TType = NewType(kind)
  261. Return TType.MapToPointerType(ty)
  262. End Function
  263. Function IsPointerType:Int(ty:TType, kind:Int = 0, pType:Int = TType.T_PTR)
  264. ' TODO :
  265. If kind Then
  266. If IsType(ty, kind) Then
  267. Return ty._flags & pType
  268. Else
  269. Return False
  270. End If
  271. Else
  272. Return ty._flags & pType
  273. End If
  274. End Function
  275. Function IsNumericType:Int(ty:TType)
  276. Return (TNumericType(ty) <> Null) And Not IsPointerType(ty, 0, TType.T_POINTER)
  277. End Function
  278. Function IsType:Int(ty:TType, kind:Int)
  279. Select kind
  280. Case TType.T_BYTE
  281. Return TByteType(ty) <> Null
  282. Case TType.T_SHORT
  283. Return TShortType(ty) <> Null
  284. Case TType.T_INT
  285. Return TIntType(ty) <> Null
  286. Case TType.T_UINT
  287. Return TUIntType(ty) <> Null
  288. Case TType.T_LONG
  289. Return TLongType(ty) <> Null
  290. Case TType.T_ULONG
  291. Return TULongType(ty) <> Null
  292. Case TType.T_SIZET
  293. Return TSizeTType(ty) <> Null
  294. Case TType.T_INT128
  295. Return TInt128Type(ty) <> Null
  296. Case TType.T_FLOAT
  297. Return TFloatType(ty) <> Null
  298. Case TType.T_DOUBLE
  299. Return TDoubleType(ty) <> Null
  300. Case TType.T_FLOAT64
  301. Return TFloat64Type(ty) <> Null
  302. Case TType.T_FLOAT128
  303. Return TFloat128Type(ty) <> Null
  304. Case TType.T_DOUBLE128
  305. Return TDouble128Type(ty) <> Null
  306. Case TType.T_STRING
  307. Return TStringType(ty) <> Null
  308. Case TType.T_ARRAY
  309. Return TArrayType(ty) <> Null
  310. Case TType.T_FUNCTIONPTR
  311. Return TFunctionPtrType(ty) <> Null
  312. Case TType.T_ENUM
  313. Return TEnumType(ty) <> Null
  314. Case TType.T_LONGINT
  315. Return TLongIntType(ty) <> Null
  316. Case TType.T_ULONGINT
  317. Return TULongIntType(ty) <> Null
  318. End Select
  319. Return False
  320. End Function
  321. Type TVoidType Extends TType
  322. Method EqualsType:Int( ty:TType )
  323. If opt_issuperstrict Then
  324. Return TVoidType( ty )<>Null
  325. Else
  326. Return TVoidType( ty )<>Null Or TIntType( ty) <> Null
  327. End If
  328. End Method
  329. Method ToString$()
  330. Return "Void"
  331. End Method
  332. Method OnCopy:TType()
  333. Return New TVoidType
  334. End Method
  335. End Type
  336. Type TNullType Extends TType
  337. Method EqualsType:Int( ty:TType )
  338. Return False
  339. End Method
  340. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  341. Return True
  342. End Method
  343. Method ToString$()
  344. Return "NULL"
  345. End Method
  346. Method OnCopy:TType()
  347. Return New TNullType
  348. End Method
  349. End Type
  350. Type TBoolType Extends TType
  351. Method EqualsType:Int( ty:TType )
  352. Return TBoolType( ty )<>Null
  353. End Method
  354. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  355. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or TBoolType( ty )<>Null Or (Not noExtendString And TStringType( ty )<>Null)
  356. End Method
  357. Method WidensToType:Int( ty:TType )
  358. Return IsNumericType(ty)
  359. End Method
  360. Method DistanceToType:Int(ty:TType)
  361. If TBoolType(ty)<>Null Then
  362. Return 0
  363. End If
  364. If TIntType(ty)<>Null Then
  365. Return 1
  366. End If
  367. If TByteType(ty)<>Null Then
  368. Return 2
  369. End If
  370. If TShortType(ty)<>Null Then
  371. Return 2
  372. End If
  373. If TLongType(ty)<>Null Then
  374. Return 3
  375. End If
  376. Return 4
  377. End Method
  378. Method ToString$()
  379. Return "Bool"
  380. End Method
  381. Method GetSize:Int()
  382. Return 4
  383. End Method
  384. Method OnCopy:TType()
  385. Return New TBoolType
  386. End Method
  387. End Type
  388. Type TNumericType Extends TType
  389. Method ToPointer:TType()
  390. Local ty:TType = Copy()
  391. Return MapToPointerType(ty)
  392. End Method
  393. End Type
  394. Type TIntegralType Extends TNumericType
  395. End Type
  396. Type TIntType Extends TIntegralType
  397. Method EqualsType:Int( ty:TType )
  398. Return TIntType( ty )<>Null And (_flags = ty._flags Or ..
  399. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  400. End Method
  401. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  402. 'If TObjectType( ty )
  403. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  404. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True,,,,SCOPE_CLASS_HEIRARCHY )
  405. ' Return ctor And ctor.IsCtor()
  406. 'EndIf
  407. If _flags & T_VARPTR And (TIntType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  408. 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)
  409. End Method
  410. Method WidensToType:Int( ty:TType )
  411. 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) Or (TLongIntType(ty)<>Null And ty.GetSize()=8)
  412. End Method
  413. Method DistanceToType:Int(ty:TType)
  414. If IsPointerType(ty, 0, T_POINTER) Then
  415. If IsPointerType(Self, 0, T_POINTER) Then
  416. Return 0
  417. Else
  418. Return T_MAX_DISTANCE
  419. End If
  420. End If
  421. If TIntType(ty)<>Null Then
  422. Return 0
  423. End If
  424. If TLongIntType(ty)<>Null And ty.GetSize()=4 Then
  425. Return 1
  426. End If
  427. If WORD_SIZE = 4 And TLParamType(ty)<>Null Then
  428. Return 1
  429. End If
  430. If TLongType(ty)<>Null Then
  431. Return 2
  432. End If
  433. If TLongIntType(ty)<>Null And ty.GetSize()=8 Then
  434. Return 2
  435. End If
  436. If WORD_SIZE = 8 And TLParamType(ty)<>Null Then
  437. Return 3
  438. End If
  439. If TFloatType(ty)<>Null Then
  440. Return 4
  441. End If
  442. If TDoubleType(ty)<>Null Then
  443. Return 6
  444. End If
  445. Return T_MAX_DISTANCE
  446. End Method
  447. Method OnCopy:TType()
  448. Return New TIntType
  449. End Method
  450. Method ToString$()
  451. Return "Int" + ToStringParts()
  452. End Method
  453. Method GetSize:Int()
  454. Return 4
  455. End Method
  456. End Type
  457. Type TUIntType Extends TIntegralType
  458. Method EqualsType:Int( ty:TType )
  459. Return TUIntType( ty )<>Null And (_flags = ty._flags Or ..
  460. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  461. End Method
  462. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  463. 'If TObjectType( ty )
  464. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  465. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  466. ' Return ctor And ctor.IsCtor()
  467. 'EndIf
  468. If _flags & T_VARPTR And (TUIntType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  469. 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))
  470. End Method
  471. Method WidensToType:Int( ty:TType )
  472. 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) Or TLongIntType(ty)<> Null Or (TULongIntType(ty)<> Null And ty.GetSize()=8)
  473. End Method
  474. Method DistanceToType:Int(ty:TType)
  475. If IsPointerType(ty, 0, T_POINTER) Then
  476. If IsPointerType(Self, 0, T_POINTER) Then
  477. Return 0
  478. Else
  479. Return T_MAX_DISTANCE
  480. End If
  481. End If
  482. If TUIntType(ty)<>Null Then
  483. Return 0
  484. End If
  485. If WORD_SIZE = 4 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  486. Return 1
  487. End If
  488. If TULongIntType(ty)<>Null And ty.GetSize()=4 Then
  489. Return 1
  490. End If
  491. If TIntType(ty)<>Null Then
  492. Return 2
  493. End If
  494. If TLongIntType(ty)<>Null And ty.GetSize()=4 Then
  495. Return 2
  496. End If
  497. If WORD_SIZE = 8 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  498. Return 3
  499. End If
  500. If TULongType(ty)<>Null Then
  501. Return 3
  502. End If
  503. If TULongIntType(ty)<>Null And ty.GetSize()=8 Then
  504. Return 3
  505. End If
  506. If TLongType(ty)<>Null Then
  507. Return 4
  508. End If
  509. If TLongIntType(ty)<>Null And ty.GetSize()=8 Then
  510. Return 4
  511. End If
  512. If TFloatType(ty)<>Null Then
  513. Return 5
  514. End If
  515. If TDoubleType(ty)<>Null Then
  516. Return 6
  517. End If
  518. Return T_MAX_DISTANCE
  519. End Method
  520. Method OnCopy:TType()
  521. Return New TUIntType
  522. End Method
  523. Method ToString$()
  524. Return "UInt" + ToStringParts()
  525. End Method
  526. Method GetSize:Int()
  527. Return 4
  528. End Method
  529. End Type
  530. Type TSizeTType Extends TIntegralType
  531. Method EqualsType:Int( ty:TType )
  532. Return TSizeTType( ty )<>Null And (_flags = ty._flags Or ..
  533. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  534. End Method
  535. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  536. 'If TObjectType( ty )
  537. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  538. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  539. ' Return ctor And ctor.IsCtor()
  540. 'EndIf
  541. If _flags & T_VARPTR And (TSizeTType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  542. 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)
  543. End Method
  544. Method WidensToType:Int( ty:TType )
  545. If WORD_SIZE = 4 Then
  546. 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 Or TLongIntType(ty)<>Null Or TULongIntType(ty)<>Null
  547. Else
  548. 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 Or (TLongIntType(ty)<>Null And ty.GetSize()=8) Or (TULongIntType(ty)<>Null And ty.GetSize()=8)
  549. End If
  550. End Method
  551. Method DistanceToType:Int(ty:TType)
  552. If IsPointerType(ty, 0, T_POINTER) Then
  553. If IsPointerType(Self, 0, T_POINTER) Then
  554. Return 0
  555. Else
  556. Return T_MAX_DISTANCE
  557. End If
  558. End If
  559. If TSizeTType(ty)<>Null Then
  560. Return 0
  561. End If
  562. If TWParamType(ty)<>Null Then
  563. Return 1
  564. End If
  565. If WORD_SIZE = 4 Then
  566. If TUIntType(ty)<>Null Then
  567. Return 1
  568. End If
  569. If TULongIntType(ty)<>Null And ty.GetSize()=4 Then
  570. Return 1
  571. End If
  572. If TIntType(ty)<>Null Then
  573. Return 2
  574. End If
  575. If TLongIntType(ty)<>Null And ty.GetSize()=4 Then
  576. Return 2
  577. End If
  578. If TLParamType(ty)<>Null Then
  579. Return 2
  580. End If
  581. If TULongType(ty)<>Null Then
  582. Return 3
  583. End If
  584. If TULongIntType(ty)<>Null And ty.GetSize()=8 Then
  585. Return 3
  586. End If
  587. If TLongType(ty)<>Null Then
  588. Return 4
  589. End If
  590. If TLongIntType(ty)<>Null And ty.GetSize()=8 Then
  591. Return 4
  592. End If
  593. If TFloatType(ty)<>Null Then
  594. Return 5
  595. End If
  596. If TDoubleType(ty)<>Null Then
  597. Return 6
  598. End If
  599. Else
  600. If TULongType(ty)<>Null Then
  601. Return 1
  602. End If
  603. If TULongIntType(ty)<>Null And ty.GetSize()=8 Then
  604. Return 1
  605. End If
  606. If TLongType(ty)<>Null Then
  607. Return 2
  608. End If
  609. If TLongIntType(ty)<>Null And ty.GetSize()=8 Then
  610. Return 2
  611. End If
  612. If TLParamType(ty)<>Null Then
  613. Return 2
  614. End If
  615. If TFloatType(ty)<>Null Then
  616. Return 4
  617. End If
  618. If TDoubleType(ty)<>Null Then
  619. Return 6
  620. End If
  621. If TFloat64Type(ty)<>Null Then
  622. Return 8
  623. End If
  624. End If
  625. Return T_MAX_DISTANCE
  626. End Method
  627. Method OnCopy:TType()
  628. Return New TSizeTType
  629. End Method
  630. Method ToString$()
  631. Return "size_t" + ToStringParts()
  632. End Method
  633. Method GetSize:Int()
  634. Return WORD_SIZE
  635. End Method
  636. End Type
  637. Type TByteType Extends TIntegralType
  638. Method EqualsType:Int( ty:TType )
  639. Return TByteType( ty )<>Null And (_flags = ty._flags Or ..
  640. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  641. End Method
  642. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  643. 'If TObjectType( ty )
  644. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  645. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  646. ' Return ctor And ctor.IsCtor()
  647. 'EndIf
  648. If (_flags & T_VARPTR) And (TByteType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  649. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TByteVarPtrType( ty )<> Null
  650. End Method
  651. Method WidensToType:Int( ty:TType )
  652. 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 Or TLongIntType(ty)<>Null Or TULongIntType(ty)<>Null
  653. End Method
  654. Method DistanceToType:Int(ty:TType)
  655. If IsPointerType(ty, 0, T_POINTER) Then
  656. If IsPointerType(Self, 0, T_POINTER) Then
  657. Return 0
  658. Else
  659. Return T_MAX_DISTANCE
  660. End If
  661. End If
  662. If TByteType(ty)<>Null Then
  663. Return 0
  664. End If
  665. If TShortType(ty)<>Null Then
  666. Return 2
  667. End If
  668. If WORD_SIZE = 4 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  669. Return 4
  670. End If
  671. If TULongIntType(ty) <> Null And ty.GetSize() = 4 Then
  672. Return 4
  673. End If
  674. If TUIntType(ty)<>Null Then
  675. Return 4
  676. End If
  677. If TIntType(ty)<>Null Then
  678. Return 5
  679. End If
  680. If TLongIntType(ty) <> Null And ty.GetSize() = 4 Then
  681. Return 5
  682. End If
  683. If WORD_SIZE = 4 And TLParamType(ty)<>Null Then
  684. Return 5
  685. End If
  686. If WORD_SIZE = 8 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  687. Return 6
  688. End If
  689. If TULongType(ty)<>Null Then
  690. Return 6
  691. End If
  692. If TULongIntType(ty) <> Null And ty.GetSize() = 8 Then
  693. Return 6
  694. End If
  695. If TLongType(ty)<>Null Then
  696. Return 7
  697. End If
  698. If TLongIntType(ty) <> Null And ty.GetSize() = 8 Then
  699. Return 7
  700. End If
  701. If WORD_SIZE = 8 And TLParamType(ty)<>Null Then
  702. Return 7
  703. End If
  704. If TFloatType(ty)<>Null Then
  705. Return 8
  706. End If
  707. If TDoubleType(ty)<>Null Then
  708. Return 10
  709. End If
  710. Return T_MAX_DISTANCE
  711. End Method
  712. Method OnCopy:TType()
  713. Return New TByteType
  714. End Method
  715. Method ToString$()
  716. Return "Byte" + ToStringParts()
  717. End Method
  718. Method GetSize:Int()
  719. Return 1
  720. End Method
  721. End Type
  722. Type TShortType Extends TIntegralType
  723. Method EqualsType:Int( ty:TType )
  724. Return TShortType( ty )<>Null And (_flags = ty._flags Or ..
  725. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  726. End Method
  727. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  728. 'If TObjectType( ty )
  729. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  730. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  731. ' Return ctor And ctor.IsCtor()
  732. 'EndIf
  733. If _flags & T_VARPTR And (TShortType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  734. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TShortVarPtrType( ty )<> Null
  735. End Method
  736. Method WidensToType:Int( ty:TType )
  737. 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 Or TLongIntType(ty)<>Null Or TULongIntType(ty)<>Null
  738. End Method
  739. Method DistanceToType:Int(ty:TType)
  740. If IsPointerType(ty, 0, T_POINTER) Then
  741. If IsPointerType(Self, 0, T_POINTER) Then
  742. Return 0
  743. Else
  744. Return T_MAX_DISTANCE
  745. End If
  746. End If
  747. If TShortType(ty)<>Null Then
  748. Return 0
  749. End If
  750. If WORD_SIZE = 4 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  751. Return 2
  752. End If
  753. If TUIntType(ty)<>Null Then
  754. Return 2
  755. End If
  756. If TLongIntType(ty)<>Null And ty.GetSize()=4 Then
  757. Return 2
  758. End If
  759. If TIntType(ty)<>Null Then
  760. Return 3
  761. End If
  762. If TLongIntType(ty)<>Null And ty.GetSize()=4 Then
  763. Return 3
  764. End If
  765. If WORD_SIZE = 4 And TLParamType(ty)<>Null Then
  766. Return 3
  767. End If
  768. If WORD_SIZE = 8 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  769. Return 4
  770. End If
  771. If TULongType(ty)<>Null Then
  772. Return 4
  773. End If
  774. If TULongIntType(ty)<>Null And ty.GetSize()=8 Then
  775. Return 4
  776. End If
  777. If TLongType(ty)<>Null Then
  778. Return 5
  779. End If
  780. If TLongIntType(ty)<>Null And ty.GetSize()=8 Then
  781. Return 5
  782. End If
  783. If WORD_SIZE = 8 And TLParamType(ty)<>Null Then
  784. Return 5
  785. End If
  786. If TFloatType(ty)<>Null Then
  787. Return 6
  788. End If
  789. If TDoubleType(ty)<>Null Then
  790. Return 8
  791. End If
  792. Return T_MAX_DISTANCE
  793. End Method
  794. Method OnCopy:TType()
  795. Return New TShortType
  796. End Method
  797. Method ToString$()
  798. Return "Short" + ToStringParts()
  799. End Method
  800. Method GetSize:Int()
  801. Return 2
  802. End Method
  803. End Type
  804. Type TLongType Extends TIntegralType ' BaH Long
  805. Method EqualsType:Int( ty:TType )
  806. Return TLongType( ty )<>Null And (_flags = ty._flags Or ..
  807. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  808. End Method
  809. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  810. 'If TObjectType( ty )
  811. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  812. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  813. ' Return ctor And ctor.IsCtor()
  814. 'EndIf
  815. If _flags & T_VARPTR And (TLongType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  816. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TLongVarPtrType( ty )<> Null
  817. End Method
  818. Method WidensToType:Int( ty:TType )
  819. 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
  820. End Method
  821. Method DistanceToType:Int(ty:TType)
  822. If IsPointerType(ty, 0, T_POINTER) Then
  823. If IsPointerType(Self, 0, T_POINTER) Then
  824. Return 0
  825. Else
  826. Return T_MAX_DISTANCE
  827. End If
  828. End If
  829. If TLongType(ty)<>Null Then
  830. Return 0
  831. End If
  832. If WORD_SIZE = 8 And TLParamType(ty)<>Null Then
  833. Return 1
  834. End If
  835. If TLongIntType(ty)<>Null And ty.GetSize()=8 Then
  836. Return 1
  837. End If
  838. If TFloatType(ty)<>Null Then
  839. Return 2
  840. End If
  841. If TDoubleType(ty)<>Null Then
  842. Return 4
  843. End If
  844. If TFloat64Type(ty)<>Null Then
  845. Return 6
  846. End If
  847. Return T_MAX_DISTANCE
  848. End Method
  849. Method OnCopy:TType()
  850. Return New TLongType
  851. End Method
  852. Method ToString$()
  853. Return "Long" + ToStringParts()
  854. End Method
  855. End Type
  856. Type TULongType Extends TIntegralType
  857. Method EqualsType:Int( ty:TType )
  858. Return TULongType( ty )<>Null And (_flags = ty._flags Or ..
  859. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  860. End Method
  861. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  862. 'If TObjectType( ty )
  863. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  864. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  865. ' Return ctor And ctor.IsCtor()
  866. 'EndIf
  867. If _flags & T_VARPTR And (TULongType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  868. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TLongVarPtrType( ty )<> Null
  869. End Method
  870. Method WidensToType:Int( ty:TType )
  871. 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
  872. End Method
  873. Method DistanceToType:Int(ty:TType)
  874. If IsPointerType(ty, 0, T_POINTER) Then
  875. If IsPointerType(Self, 0, T_POINTER) Then
  876. Return 0
  877. Else
  878. Return T_MAX_DISTANCE
  879. End If
  880. End If
  881. If TULongType(ty)<>Null Then
  882. Return 0
  883. End If
  884. If WORD_SIZE = 8 And (TSizeTType(ty)<>Null Or TWParamType(ty)<>Null) Then
  885. Return 1
  886. End If
  887. If TULongIntType(ty)<>Null And ty.GetSize()=8 Then
  888. Return 1
  889. End If
  890. If TLongType(ty)<>Null Then
  891. Return 2
  892. End If
  893. If TLongIntType(ty)<>Null And ty.GetSize()=8 Then
  894. Return 2
  895. End If
  896. If TFloatType(ty)<>Null Then
  897. Return 3
  898. End If
  899. If TDoubleType(ty)<>Null Then
  900. Return 4
  901. End If
  902. If TFloat64Type(ty)<>Null Then
  903. Return 6
  904. End If
  905. Return T_MAX_DISTANCE
  906. End Method
  907. Method OnCopy:TType()
  908. Return New TULongType
  909. End Method
  910. Method ToString$()
  911. Return "ULong" + ToStringParts()
  912. End Method
  913. End Type
  914. Type TLongIntType Extends TIntegralType
  915. Method EqualsType:Int( ty:TType )
  916. Return TLongIntType( ty )<>Null And (_flags = ty._flags Or ..
  917. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  918. End Method
  919. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  920. If _flags & T_VARPTR And (TLongIntType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  921. 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)
  922. End Method
  923. Method WidensToType:Int( ty:TType )
  924. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TLongIntType(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)
  925. End Method
  926. Method DistanceToType:Int(ty:TType)
  927. If IsPointerType(ty, 0, T_POINTER) Then
  928. If IsPointerType(Self, 0, T_POINTER) Then
  929. Return 0
  930. Else
  931. Return T_MAX_DISTANCE
  932. End If
  933. End If
  934. If TLongIntType(ty)<>Null Then
  935. Return 0
  936. End If
  937. Local longIntSize:Int = GetSize()
  938. If longIntSize = 4 And TIntType(ty)<>Null Then
  939. Return 1
  940. End If
  941. If longIntSize = 4 And TLParamType(ty)<>Null Then
  942. Return 1
  943. End If
  944. If longIntSize = 4 And TLongType(ty)<>Null Then
  945. Return 2
  946. End If
  947. If longIntSize = 8 And TLParamType(ty)<>Null Then
  948. Return 3
  949. End If
  950. If longIntSize = 8 And TIntType(ty)<>Null Then
  951. Return 2
  952. End If
  953. If longIntSize = 8 And TLongType(ty)<>Null Then
  954. Return 1
  955. End If
  956. If TFloatType(ty)<>Null Then
  957. Return 4
  958. End If
  959. If TDoubleType(ty)<>Null Then
  960. Return 6
  961. End If
  962. Return T_MAX_DISTANCE
  963. End Method
  964. Method OnCopy:TType()
  965. Return New TLongIntType
  966. End Method
  967. Method ToString$()
  968. Return "LongInt" + ToStringParts()
  969. End Method
  970. Method GetSize:Int()
  971. If WORD_SIZE = 4 Then
  972. Return 4
  973. Else
  974. If opt_platform = "linux" or opt_platform = "macos" Then
  975. Return 8
  976. Else
  977. Return 4
  978. End If
  979. End If
  980. End Method
  981. End Type
  982. Type TULongIntType Extends TIntegralType
  983. Method EqualsType:Int( ty:TType )
  984. Return TULongIntType( ty )<>Null And (_flags = ty._flags Or ..
  985. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  986. End Method
  987. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  988. If _flags & T_VARPTR And (TULongIntType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  989. 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)
  990. End Method
  991. Method WidensToType:Int( ty:TType )
  992. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TULongIntType(ty)<>Null And (ty._flags & T_VAR)) Or TULongType(ty)<>Null Or TFloatType(ty)<>Null Or TDoubleType(ty)<>Null Or (WORD_SIZE=8 And TLParamType(ty)<>Null)
  993. End Method
  994. Method DistanceToType:Int(ty:TType)
  995. If IsPointerType(ty, 0, T_POINTER) Then
  996. If IsPointerType(Self, 0, T_POINTER) Then
  997. Return 0
  998. Else
  999. Return T_MAX_DISTANCE
  1000. End If
  1001. End If
  1002. If TULongIntType(ty)<>Null Then
  1003. Return 0
  1004. End If
  1005. Local longIntSize:Int = GetSize()
  1006. If longIntSize = 4 And TIntType(ty)<>Null Then
  1007. Return 2
  1008. End If
  1009. If longIntSize = 4 And TUIntType(ty)<>Null Then
  1010. Return 1
  1011. End If
  1012. If longIntSize = 4 And TLParamType(ty)<>Null Then
  1013. Return 3
  1014. End If
  1015. If longIntSize = 4 And TLongType(ty)<>Null Then
  1016. Return 4
  1017. End If
  1018. If longIntSize = 8 And TLParamType(ty)<>Null Then
  1019. Return 3
  1020. End If
  1021. If longIntSize = 8 And TIntType(ty)<>Null Then
  1022. Return 4
  1023. End If
  1024. If longIntSize = 8 And TUIntType(ty)<>Null Then
  1025. Return 3
  1026. End If
  1027. If longIntSize = 8 And TLongType(ty)<>Null Then
  1028. Return 1
  1029. End If
  1030. If longIntSize = 8 And TULongType(ty)<>Null Then
  1031. Return 2
  1032. End If
  1033. If TFloatType(ty)<>Null Then
  1034. Return 5
  1035. End If
  1036. If TDoubleType(ty)<>Null Then
  1037. Return 6
  1038. End If
  1039. Return T_MAX_DISTANCE
  1040. End Method
  1041. Method OnCopy:TType()
  1042. Return New TULongIntType
  1043. End Method
  1044. Method ToString$()
  1045. Return "ULongInt" + ToStringParts()
  1046. End Method
  1047. Method GetSize:Int()
  1048. If WORD_SIZE = 4 Then
  1049. Return 4
  1050. Else
  1051. If opt_platform = "linux" or opt_platform = "macos" Then
  1052. Return 8
  1053. Else
  1054. Return 4
  1055. End If
  1056. End If
  1057. End Method
  1058. End Type
  1059. Type TDecimalType Extends TNumericType
  1060. End Type
  1061. Type TFloatType Extends TDecimalType
  1062. Method EqualsType:Int( ty:TType )
  1063. Return TFloatType( ty )<>Null And (_flags = ty._flags Or ..
  1064. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1065. End Method
  1066. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1067. 'If TObjectType( ty )
  1068. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  1069. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  1070. ' Return ctor And ctor.IsCtor()
  1071. 'EndIf
  1072. If _flags & T_VARPTR And (TFloatType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1073. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TFloatVarPtrType( ty )<> Null
  1074. End Method
  1075. Method WidensToType:Int( ty:TType )
  1076. 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
  1077. End Method
  1078. Method DistanceToType:Int(ty:TType)
  1079. If IsPointerType(ty, 0, T_POINTER) Then
  1080. If IsPointerType(Self, 0, T_POINTER) Then
  1081. Return 0
  1082. Else
  1083. Return T_MAX_DISTANCE
  1084. End If
  1085. End If
  1086. If TFloatType(ty)<>Null Then
  1087. Return 0
  1088. End If
  1089. If TDoubleType(ty)<>Null Then
  1090. Return 2
  1091. End If
  1092. Return T_MAX_DISTANCE
  1093. End Method
  1094. Method OnCopy:TType()
  1095. Return New TFloatType
  1096. End Method
  1097. Method ToString$()
  1098. Return "Float" + ToStringParts()
  1099. End Method
  1100. Method GetSize:Int()
  1101. Return 4
  1102. End Method
  1103. End Type
  1104. Type TDoubleType Extends TDecimalType
  1105. Method EqualsType:Int( ty:TType )
  1106. Return TDoubleType( ty )<>Null And (_flags = ty._flags Or ..
  1107. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1108. End Method
  1109. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1110. 'If TObjectType( ty )
  1111. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  1112. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  1113. ' Return ctor And ctor.IsCtor()
  1114. 'EndIf
  1115. If _flags & T_VARPTR And (TDoubleType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1116. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TDoubleVarPtrType( ty )<> Null
  1117. End Method
  1118. Method WidensToType:Int( ty:TType )
  1119. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TDoubleType(ty)<>Null And (ty._flags & T_VAR))
  1120. End Method
  1121. Method DistanceToType:Int(ty:TType)
  1122. If IsPointerType(ty, 0, T_POINTER) Then
  1123. If IsPointerType(Self, 0, T_POINTER) Then
  1124. Return 0
  1125. Else
  1126. Return T_MAX_DISTANCE
  1127. End If
  1128. End If
  1129. If TDoubleType(ty)<>Null Then
  1130. Return 0
  1131. End If
  1132. Return T_MAX_DISTANCE
  1133. End Method
  1134. Method OnCopy:TType()
  1135. Return New TDoubleType
  1136. End Method
  1137. Method ToString$()
  1138. Return "Double" + ToStringParts()
  1139. End Method
  1140. End Type
  1141. Type TIntrinsicType Extends TNumericType
  1142. End Type
  1143. Type TInt128Type Extends TIntrinsicType
  1144. Method EqualsType:Int( ty:TType )
  1145. Return TInt128Type( ty )<>Null And (_flags = ty._flags Or ..
  1146. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1147. End Method
  1148. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1149. 'If TObjectType( ty )
  1150. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  1151. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  1152. ' Return ctor And ctor.IsCtor()
  1153. 'EndIf
  1154. If _flags & T_VARPTR And (TLongType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1155. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TLongVarPtrType( ty )<> Null
  1156. End Method
  1157. Method WidensToType:Int( ty:TType )
  1158. 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
  1159. End Method
  1160. Method DistanceToType:Int(ty:TType)
  1161. If IsPointerType(ty, 0, T_POINTER) Then
  1162. If IsPointerType(Self, 0, T_POINTER) Then
  1163. Return 0
  1164. Else
  1165. Return T_MAX_DISTANCE
  1166. End If
  1167. End If
  1168. If TInt128Type(ty)<>Null Then
  1169. Return 0
  1170. End If
  1171. If TFloat128Type(ty)<>Null Then
  1172. Return 2
  1173. End If
  1174. If TDouble128Type(ty)<>Null Then
  1175. Return 4
  1176. End If
  1177. Return T_MAX_DISTANCE
  1178. End Method
  1179. Method OnCopy:TType()
  1180. Return New TInt128Type
  1181. End Method
  1182. Method ToString$()
  1183. Return "Int128" + ToStringParts()
  1184. End Method
  1185. End Type
  1186. Type TFloat64Type Extends TIntrinsicType
  1187. Method EqualsType:Int( ty:TType )
  1188. Return TFloat64Type( ty )<>Null And (_flags = ty._flags Or ..
  1189. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1190. End Method
  1191. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1192. 'If TObjectType( ty )
  1193. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  1194. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  1195. ' Return ctor And ctor.IsCtor()
  1196. 'EndIf
  1197. If _flags & T_VARPTR And (TFloat64Type(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1198. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TDoubleVarPtrType( ty )<> Null
  1199. End Method
  1200. Method WidensToType:Int( ty:TType )
  1201. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TFloat64Type(ty)<>Null And (ty._flags & T_VAR))
  1202. End Method
  1203. Method DistanceToType:Int(ty:TType)
  1204. If IsPointerType(ty, 0, T_POINTER) Then
  1205. If IsPointerType(Self, 0, T_POINTER) Then
  1206. Return 0
  1207. Else
  1208. Return T_MAX_DISTANCE
  1209. End If
  1210. End If
  1211. If TFloat64Type(ty)<>Null Then
  1212. Return 0
  1213. End If
  1214. Return T_MAX_DISTANCE
  1215. End Method
  1216. Method OnCopy:TType()
  1217. Return New TFloat64Type
  1218. End Method
  1219. Method ToString$()
  1220. Return "Float64" + ToStringParts()
  1221. End Method
  1222. End Type
  1223. Type TFloat128Type Extends TIntrinsicType
  1224. Method EqualsType:Int( ty:TType )
  1225. Return TFloat128Type( ty )<>Null And (_flags = ty._flags Or ..
  1226. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1227. End Method
  1228. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1229. 'If TObjectType( ty )
  1230. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  1231. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  1232. ' Return ctor And ctor.IsCtor()
  1233. 'EndIf
  1234. If _flags & T_VARPTR And (TFloat128Type(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1235. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TDoubleVarPtrType( ty )<> Null
  1236. End Method
  1237. Method WidensToType:Int( ty:TType )
  1238. 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
  1239. End Method
  1240. Method DistanceToType:Int(ty:TType)
  1241. If IsPointerType(ty, 0, T_POINTER) Then
  1242. If IsPointerType(Self, 0, T_POINTER) Then
  1243. Return 0
  1244. Else
  1245. Return T_MAX_DISTANCE
  1246. End If
  1247. End If
  1248. If TFloat128Type(ty)<>Null Then
  1249. Return 0
  1250. End If
  1251. If TDouble128Type(ty)<>Null Then
  1252. Return 2
  1253. End If
  1254. If TInt128Type(ty)<>Null Then
  1255. Return 4
  1256. End If
  1257. Return T_MAX_DISTANCE
  1258. End Method
  1259. Method OnCopy:TType()
  1260. Return New TFloat128Type
  1261. End Method
  1262. Method ToString$()
  1263. Return "Float128" + ToStringParts()
  1264. End Method
  1265. End Type
  1266. Type TDouble128Type Extends TIntrinsicType
  1267. Method EqualsType:Int( ty:TType )
  1268. Return TDouble128Type( ty )<>Null And (_flags = ty._flags Or ..
  1269. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1270. End Method
  1271. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1272. 'If TObjectType( ty )
  1273. ' Local expr:TExpr=New TConstExpr.Create( Self,"" ).Semant()
  1274. ' Local ctor:TFuncDecl=ty.GetClass().FindFuncDecl( "new",[expr],True )
  1275. ' Return ctor And ctor.IsCtor()
  1276. 'EndIf
  1277. If _flags & T_VARPTR And (TDouble128Type(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1278. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TDoubleVarPtrType( ty )<> Null
  1279. End Method
  1280. Method WidensToType:Int( ty:TType )
  1281. 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
  1282. End Method
  1283. Method DistanceToType:Int(ty:TType)
  1284. If IsPointerType(ty, 0, T_POINTER) Then
  1285. If IsPointerType(Self, 0, T_POINTER) Then
  1286. Return 0
  1287. Else
  1288. Return T_MAX_DISTANCE
  1289. End If
  1290. End If
  1291. If TDouble128Type(ty)<>Null Then
  1292. Return 0
  1293. End If
  1294. If TFloat128Type(ty)<>Null Then
  1295. Return 2
  1296. End If
  1297. If TInt128Type(ty)<>Null Then
  1298. Return 4
  1299. End If
  1300. Return T_MAX_DISTANCE
  1301. End Method
  1302. Method OnCopy:TType()
  1303. Return New TDouble128Type
  1304. End Method
  1305. Method ToString$()
  1306. Return "Double128" + ToStringParts()
  1307. End Method
  1308. End Type
  1309. Type TStringType Extends TType
  1310. Field cdecl:TClassDecl
  1311. Method EqualsType:Int( ty:TType )
  1312. Return TStringType( ty )<>Null And (_flags = ty._flags Or (_flags & T_VAR))
  1313. End Method
  1314. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1315. Return EqualsType( ty ) Or (TObjectType( ty ) And TObjectType( ty ).classDecl.ident="Object") Or (TStringType(ty) And (_flags & T_VAR)) ..
  1316. 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)) ..
  1317. Or IsPointerType(ty) Or (TStringType(ty) And (_flags & T_CHAR_PTR)) Or (TStringType(ty) And (_flags & T_SHORT_PTR))
  1318. End Method
  1319. Method GetClass:TClassDecl()
  1320. If cdecl Return cdecl
  1321. Local modid$="brl.classes"
  1322. Local mdecl:TModuleDecl=_env.FindModuleDecl( modid )
  1323. If Not mdecl Err "Module '"+modid+"' not found"
  1324. 'clsid=ident[i+1..] ' BaH
  1325. 'DebugStop
  1326. cdecl=TClassDecl(mdecl.FindDecl( "string" ))
  1327. 'Return _env.FindClassDecl( "brl.classes.string" )
  1328. Return cdecl
  1329. End Method
  1330. Method Semant:TType(option:Int = 0, callback:TCallback = Null)
  1331. GetClass()
  1332. Return Self
  1333. End Method
  1334. Method OnCopy:TType()
  1335. Local ty:TStringType = New TStringType
  1336. ty.cdecl = cdecl
  1337. If _flags & T_CHAR_PTR Then
  1338. ty._flags :| T_CHAR_PTR
  1339. End If
  1340. If _flags & T_SHORT_PTR Then
  1341. ty._flags :| T_SHORT_PTR
  1342. End If
  1343. Return ty
  1344. End Method
  1345. Method ToString$()
  1346. Return "String" + ToStringParts()
  1347. End Method
  1348. Method DistanceToType:Int(ty:TType)
  1349. If TStringType(ty) Then
  1350. Return 0
  1351. End If
  1352. ' prefer Object
  1353. If TObjectType(ty)
  1354. If TObjectType(ty).classDecl.ident = "Object" Then
  1355. Return $F
  1356. End If
  1357. End If
  1358. Return T_MAX_DISTANCE
  1359. End Method
  1360. End Type
  1361. Type TArrayType Extends TType
  1362. Field elemType:TType
  1363. Field dims:Int
  1364. Field isStatic:Int
  1365. Field length:String
  1366. Method Create:TArrayType( elemType:TType, dims:Int = 1, flags:Int = 0, isStatic:Int = False, length:Int = 0 )
  1367. Self.elemType=elemType
  1368. Self.dims = dims
  1369. Self._flags = flags
  1370. Self.isStatic = isStatic
  1371. Self.length = length
  1372. Return Self
  1373. End Method
  1374. Method ActualType:TType()
  1375. Local ty:TType=elemType.ActualType()
  1376. If ty=elemType Return Self
  1377. Return New TArrayType.Create( ty )
  1378. End Method
  1379. Method EqualsType:Int( ty:TType )
  1380. Local arrayType:TArrayType=TArrayType( ty )
  1381. Return arrayType And elemType.EqualsType( arrayType.elemType ) And dims = arrayType.dims And arrayType.isStatic = isStatic And arrayType.length = length
  1382. End Method
  1383. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1384. Local arrayType:TArrayType=TArrayType( ty )
  1385. Return (arrayType And dims = arrayType.dims And ..
  1386. (arrayType.isStatic = isStatic And arrayType.length = length) And ..
  1387. ( TVoidType( elemType ) ..
  1388. Or elemType.EqualsType( arrayType.elemType ) ..
  1389. Or ((TObjectType(elemType) Or TStringType(elemType) Or TArrayType(elemType)) And ..
  1390. (elemType.ExtendsType( arrayType.elemType ) ..
  1391. Or (TObjectType(arrayType.elemType) And TObjectType( arrayType.elemType ).classDecl.ident="Object") ..
  1392. ))) ..
  1393. ) ..
  1394. Or IsPointerType(ty, 0, TType.T_POINTER) <> Null Or (TObjectType( ty ) And TObjectType( ty ).classDecl.ident="Object")
  1395. End Method
  1396. Method Semant:TType(option:Int = False, callback:TCallback = Null)
  1397. Local ty:TType=elemType.Semant(option, callback)
  1398. If ty<>elemType Return New TArrayType.Create( ty, dims, _flags, isStatic, Int(length) )
  1399. Return Self
  1400. End Method
  1401. Method GetClass:TClassDecl()
  1402. 'Return _env.FindClassDecl( "array" )
  1403. Return TClassDecl( _env.FindDecl( "___array" ) )
  1404. End Method
  1405. Method OnCopy:TType()
  1406. Local ty:TArrayType = New TArrayType
  1407. ty.elemType = elemType
  1408. ty.dims = dims
  1409. ty.isStatic = isStatic
  1410. ty.length = length
  1411. Return ty
  1412. End Method
  1413. Method ToString$()
  1414. Local t:String = elemType.ToString()
  1415. If isStatic Then
  1416. t = "Static " + t + " Array[" + length + "]"
  1417. Else
  1418. t :+ " Array"
  1419. End If
  1420. Return t
  1421. End Method
  1422. Method DistanceToType:Int(ty:TType)
  1423. If TArrayType(ty) Then
  1424. Return 0
  1425. End If
  1426. ' prefer Object
  1427. If TObjectType(ty)
  1428. If TObjectType(ty).classDecl.ident = "Object" Then
  1429. Return $F
  1430. End If
  1431. End If
  1432. Return T_MAX_DISTANCE
  1433. End Method
  1434. End Type
  1435. Type TObjectType Extends TType
  1436. Field classDecl:TClassDecl
  1437. Field instance:Int
  1438. Method Create:TObjectType( classDecl:TClassDecl )
  1439. Self.classDecl=classDecl
  1440. Return Self
  1441. End Method
  1442. Method ActualType:TType()
  1443. If classDecl.actual=classDecl Return Self
  1444. Return New TObjectType.Create( TClassDecl(classDecl.actual) )
  1445. End Method
  1446. Method EqualsType:Int( ty:TType )
  1447. Local objty:TObjectType=TObjectType( ty )
  1448. Return TNullDecl(classDecl) <> Null Or (objty And (classDecl=objty.classDecl) And (Not classDecl.IsStruct() Or IsFlagEquivalent(ty)))' Or classDecl.ExtendsClass( objty.classDecl ))) 'Or TObjectVarPtrType(ty) <> Null
  1449. End Method
  1450. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False )
  1451. If classDecl.IsStruct() Then
  1452. If (_flags & T_VARPTR Or IsPointerType(Self, 0, T_POINTER)) And (TNumericType(ty) <> Null) And IsPointerType(ty, 0, T_POINTER) Then
  1453. Return True
  1454. End If
  1455. Return False
  1456. End If
  1457. Local objty:TObjectType=TObjectType( ty )
  1458. If objty Return classDecl.ExtendsClass( objty.classDecl, ignoreObjectSubclasses )
  1459. If IsPointerType( ty, T_BYTE ) Return True
  1460. End Method
  1461. Method GetClass:TClassDecl()
  1462. Return classDecl
  1463. End Method
  1464. Method ToString$()
  1465. Return classDecl.ToTypeString() + ToStringParts()
  1466. End Method
  1467. Method OnCopy:TType()
  1468. Local ty:TObjectType = New TObjectType
  1469. ty.classDecl = classDecl
  1470. ty.instance = instance
  1471. Return ty
  1472. End Method
  1473. Method DistanceToType:Int(ty:TType)
  1474. If TObjectType(ty) Then
  1475. If classDecl = TObjectType(ty).classDecl Then
  1476. Return 0
  1477. End If
  1478. If classDecl.ExtendsClass(TObjectType(ty).classDecl) Then
  1479. Return $F
  1480. End If
  1481. End If
  1482. If classDecl.IsStruct() Then
  1483. If (_flags & T_VARPTR Or IsPointerType(Self, 0, T_POINTER)) And (TNumericType(ty) <> Null) And IsPointerType(ty, 0, T_POINTER) Then
  1484. Return $10
  1485. End If
  1486. End If
  1487. Return T_MAX_DISTANCE
  1488. End Method
  1489. End Type
  1490. Type TClassType Extends TType
  1491. Field classDecl:TClassDecl
  1492. Field instance:Int
  1493. Method Create:TClassType( classDecl:TClassDecl )
  1494. Self.classDecl=classDecl
  1495. Return Self
  1496. End Method
  1497. Method GetClass:TClassDecl()
  1498. Return classDecl
  1499. End Method
  1500. Method OnCopy:TType()
  1501. Local ty:TClassType = New TClassType
  1502. ty.classDecl = classDecl
  1503. ty.instance = instance
  1504. Return ty
  1505. End Method
  1506. Method ToString:String()
  1507. Return "Type"
  1508. End Method
  1509. End Type
  1510. Type TIdentType Extends TType
  1511. Field ident$
  1512. Field args:TType[]
  1513. Method Create:TIdentType( ident$,args:TType[] = Null )
  1514. Self.ident=ident
  1515. If args = Null Then
  1516. Self.args = New TType[0]
  1517. Else
  1518. Self.args=args
  1519. End If
  1520. Return Self
  1521. End Method
  1522. Method CopyToDest:TIdentType(dst:TIdentType)
  1523. dst.ident = ident
  1524. dst.args = args
  1525. Return dst
  1526. End Method
  1527. Method CopyToPointer:TIdentType(dst:TIdentType)
  1528. dst = TIdentType(MapToPointerType(dst))
  1529. dst.ident = ident
  1530. dst.args = args
  1531. Return dst
  1532. End Method
  1533. Method ActualType:TType()
  1534. InternalErr "TIdentType.ActualType"
  1535. End Method
  1536. Method EqualsType:Int( ty:TType )
  1537. InternalErr "TIdentType.EqualsType"
  1538. End Method
  1539. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1540. InternalErr "TIdentType.ExtendsType"
  1541. End Method
  1542. 'Method Semant:TType()
  1543. ' If ident Return New TObjectType.Create( FindClass() )
  1544. ' Return New TObjectType.Create( TClassDecl.nullObjectClass )
  1545. 'End Method
  1546. Method Semant:TType(ignoreNotFoundError:Int = 0, callback:TCallback = Null)
  1547. 'If ident="IPair" DebugStop
  1548. If Not ident Return TType.nullObjectType
  1549. Local targs:TType[args.Length]
  1550. For Local i:Int=0 Until args.Length
  1551. targs[i]=args[i].Semant(ignoreNotFoundError, callback)
  1552. Next
  1553. Local tyid$,ty:TType
  1554. Local i:Int=ident.FindLast( "." )
  1555. If i=-1
  1556. tyid=ident.ToLower()
  1557. If tyid = "self" Then
  1558. ' find owning class
  1559. Local scope:TClassDecl = _env.ClassScope()
  1560. If scope Then
  1561. tyid = scope.ident
  1562. ty = New TClassType.Create(scope)
  1563. ' test for method scope - self is already an instance
  1564. Local funcScope:TFuncDecl = _env.FuncScope()
  1565. If funcScope.IsAnyMethod() Then
  1566. TClassType(ty).instance = True
  1567. End If
  1568. Else
  1569. Err "'Self' can only be used within methods."
  1570. End If
  1571. End If
  1572. If Not ty Then
  1573. ty=_env.FindType( tyid,targs, callback )
  1574. End If
  1575. ' finally scan all modules for it
  1576. If Not ty Then
  1577. For Local mdecl:TModuleDecl = EachIn _appInstance.globalImports.Values()
  1578. ty=mdecl.FindType( tyid,targs, callback )
  1579. If ty Exit
  1580. Next
  1581. Else If TIdentType(ty) Then
  1582. If ty = Self Then
  1583. Throw "Recursive type definition for '"+tyid+"'"
  1584. End If
  1585. ty = ty.Semant()
  1586. End If
  1587. Else
  1588. Local id:String = ident.ToLower()
  1589. i = id.Find( "." )
  1590. ' try scope search first
  1591. tyid=id[..i]
  1592. If tyid = "self" Then
  1593. ' find owning class
  1594. Local scope:TClassDecl = _env.ClassScope()
  1595. If scope Then
  1596. tyid = scope.ident
  1597. ty = New TClassType.Create(scope)
  1598. ' test for method scope - self is already an instance
  1599. Local funcScope:TFuncDecl = _env.FuncScope()
  1600. If funcScope.IsAnyMethod() Then
  1601. TClassType(ty).instance = True
  1602. End If
  1603. Else
  1604. Err "'Self' can only be used within methods."
  1605. End If
  1606. End If
  1607. If Not ty Then
  1608. ty=_env.FindType( tyid,targs, callback )
  1609. End If
  1610. If Not ty Then
  1611. i = id.FindLast( "." )
  1612. ' try scope search first
  1613. tyid=id[..i]
  1614. ty=_env.FindType( tyid,targs, callback )
  1615. If Not ty Then
  1616. ' no? now try module search
  1617. Local modid$=id[..i]
  1618. Local mdecl:TModuleDecl=_env.FindModuleDecl( modid )
  1619. If Not mdecl Err "Module '"+modid+"' not found"
  1620. tyid=id[i+1..]
  1621. ty=mdecl.FindType( tyid,targs, callback )
  1622. End If
  1623. End If
  1624. EndIf
  1625. If Not ty Then
  1626. If ignoreNotFoundError Then
  1627. Return Null
  1628. End If
  1629. Err "Type '"+tyid+"' not found"
  1630. End If
  1631. If (_flags & T_VAR) Then
  1632. If TObjectType(ty) Then
  1633. ty = New TObjectType.Create(TObjectType(ty).classDecl)
  1634. ty._flags :| T_VAR
  1635. Else If TEnumType(ty) Then
  1636. ty = New TEnumType.Create(TEnumType(ty).decl)
  1637. ty._flags :| T_VAR
  1638. Else
  1639. ty = ty.Copy()
  1640. ty._flags :| T_VAR
  1641. End If
  1642. End If
  1643. If (_flags & T_POINTER) And TObjectType(ty) Then
  1644. ' FIXME #200
  1645. 'If Not TObjectType(ty).classDecl.IsExtern() Then
  1646. ' Err "Invalid Pointer type."
  1647. 'End If
  1648. ty = New TObjectType.Create(TObjectType(ty).classDecl)
  1649. ty._flags :| (_flags & T_POINTER)
  1650. End If
  1651. Return ty
  1652. End Method
  1653. Method SemantClass:TClassDecl(callback:TCallback = Null)
  1654. Local ty:TObjectType=TObjectType( Semant(False, callback) )
  1655. If Not ty Err "Type is not a class"
  1656. Return ty.classDecl
  1657. End Method
  1658. Method ToString$()
  1659. Local t$
  1660. For Local arg:TIdentType=EachIn args
  1661. If t t:+","
  1662. t:+arg.ToString()
  1663. Next
  1664. If t Return "$"+ident+"<"+t.Replace("$","")+">"
  1665. Return "$"+ident
  1666. End Method
  1667. Method AsString:String()
  1668. Local t:String
  1669. For Local arg:TIdentType=EachIn args
  1670. If t t:+","
  1671. t:+arg.ToString()
  1672. Next
  1673. If t Return ident+"<"+t.Replace("$","")+">"
  1674. Return ident
  1675. End Method
  1676. Method OnCopy:TType()
  1677. Local ty:TIdentType = New TIdentType
  1678. ty.ident = ident
  1679. ty.args = args
  1680. Return ty
  1681. End Method
  1682. End Type
  1683. Type TExternObjectType Extends TType
  1684. Field classDecl:TClassDecl
  1685. Method Create:TExternObjectType( classDecl:TClassDecl )
  1686. Self.classDecl=classDecl
  1687. Return Self
  1688. End Method
  1689. Method ActualType:TType()
  1690. If classDecl.actual=classDecl Return Self
  1691. Return New TExternObjectType.Create( TClassDecl(classDecl.actual) )
  1692. End Method
  1693. Method EqualsType:Int( ty:TType )
  1694. Local objty:TObjectType=TObjectType( ty )
  1695. Return TNullDecl(classDecl) <> Null Or (objty And (classDecl=objty.classDecl Or classDecl.ExtendsClass( objty.classDecl ))) Or TObjectType(ty)
  1696. End Method
  1697. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1698. Local objty:TObjectType=TObjectType( ty )
  1699. If objty Return classDecl.ExtendsClass( objty.classDecl )
  1700. If IsPointerType( ty, T_BYTE ) Return True
  1701. Local op$
  1702. If TBoolType( ty )
  1703. op="ToBool"
  1704. Else If TIntType( ty )
  1705. op="ToInt"
  1706. Else If TFloatType( ty )
  1707. op="ToFloat"
  1708. Else If TStringType( ty )
  1709. op="ToString"
  1710. Else If TLongType( ty ) ' BaH Long
  1711. op="ToLong"
  1712. Else
  1713. Return False
  1714. EndIf
  1715. Local fdecl:TFuncDecl=GetClass().FindFuncDecl( op,Null,True,,,,SCOPE_CLASS_HEIRARCHY )
  1716. Return fdecl And fdecl.IsMethod() And fdecl.retType.EqualsType( ty )
  1717. End Method
  1718. Method GetClass:TClassDecl()
  1719. Return classDecl
  1720. End Method
  1721. Method ToString$()
  1722. Return classDecl.ToTypeString()
  1723. End Method
  1724. Method OnCopy:TType()
  1725. Local ty:TExternObjectType = New TExternObjectType
  1726. ty.classDecl = classDecl
  1727. Return ty
  1728. End Method
  1729. End Type
  1730. Type TFunctionPtrType Extends TType
  1731. Field func:TFuncDecl
  1732. Method Create:TFunctionPtrType(func:TFuncDecl)
  1733. Self.func = func
  1734. Return Self
  1735. End Method
  1736. Method EqualsType:Int( ty:TType )
  1737. If Not TFunctionPtrType(ty) Then Return False
  1738. ' declared function pointer
  1739. Local tyfunc:TFuncDecl = TFunctionPtrType(ty).func
  1740. If Not tyfunc.retType.EqualsType(func.retType) Then Return False
  1741. If Not (tyfunc.argDecls.Length = func.argDecls.Length) Then Return False
  1742. For Local a:Int = 0 Until func.argDecls.Length
  1743. ' does our arg equal declared arg?
  1744. If Not func.argDecls[a].ty.EqualsType(tyfunc.argDecls[a].ty) Then Return False
  1745. Next
  1746. Return True
  1747. End Method
  1748. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1749. If TFunctionPtrType( ty )
  1750. ' declared function pointer
  1751. Local tyfunc:TFuncDecl = TFunctionPtrType(ty).func
  1752. If Not func.retType.ExtendsType(tyfunc.retType) Then Return False
  1753. If Not (func.argDecls.Length = tyfunc.argDecls.Length) Then Return False
  1754. For Local a:Int = 0 Until func.argDecls.Length
  1755. ' does declared arg extend our arg?
  1756. If Not tyfunc.argDecls[a].ty.ExtendsType(func.argDecls[a].ty) Then Return False
  1757. Next
  1758. Return True
  1759. EndIf
  1760. Return IsPointerType( ty, 0, T_POINTER )<>Null
  1761. End Method
  1762. Method equalsDecl:Int(fdecl:TFuncDecl)
  1763. func.Semant
  1764. fdecl.Semant
  1765. ' same number of args?
  1766. If func.argDecls.length <> fdecl.argDecls.length Then
  1767. Return False
  1768. End If
  1769. ' same arg types?
  1770. For Local i:Int = 0 Until func.argDecls.length
  1771. If Not func.argDecls[i].ty.equalsType(fdecl.argDecls[i].ty) Return False
  1772. Next
  1773. ' same return type?
  1774. If Not func.retType.equalsType(fdecl.retType) Then
  1775. ' if function pointer specifies Int return type, our function can specify void...
  1776. If TIntType(func.retType) And TVoidType(fdecl.retType) Then
  1777. Return True
  1778. End If
  1779. Return False
  1780. End If
  1781. Return True
  1782. End Method
  1783. Method ToString$()
  1784. Return func.ToTypeString()
  1785. End Method
  1786. Method OnCopy:TType()
  1787. Local ty:TFunctionPtrType = New TFunctionPtrType
  1788. ty.func = func
  1789. Return ty
  1790. End Method
  1791. Method Semant:TType(option:Int = False, callback:TCallback = Null)
  1792. func.Semant()
  1793. Return Self
  1794. End Method
  1795. End Type
  1796. ' a holder during parsing which becomes the "real" var ptr type during semanting
  1797. Type TVarPtrType Extends TType
  1798. Method OnCopy:TType()
  1799. Return New TVarPtrType
  1800. End Method
  1801. End Type
  1802. Type TParamType Extends TIntegralType
  1803. End Type
  1804. Type TWParamType Extends TParamType
  1805. Method EqualsType:Int( ty:TType )
  1806. Return TWParamType( ty )<>Null And (_flags = ty._flags Or ..
  1807. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1808. End Method
  1809. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1810. If _flags & T_VARPTR And (TWParamType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1811. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TIntVarPtrType( ty )<> Null
  1812. End Method
  1813. Method WidensToType:Int( ty:TType )
  1814. If WORD_SIZE = 4 Then
  1815. 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
  1816. Else
  1817. 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
  1818. End If
  1819. End Method
  1820. Method DistanceToType:Int(ty:TType)
  1821. If IsPointerType(ty, 0, T_POINTER) Then
  1822. If IsPointerType(Self, 0, T_POINTER) Then
  1823. Return 0
  1824. Else
  1825. Return T_MAX_DISTANCE
  1826. End If
  1827. End If
  1828. If TWParamType(ty)<>Null Then
  1829. Return 0
  1830. End If
  1831. If TSizeTType(ty)<>Null Then
  1832. Return 0
  1833. End If
  1834. If WORD_SIZE = 4 Then
  1835. If TUIntType(ty)<>Null Then
  1836. Return 0
  1837. End If
  1838. If TIntType(ty)<>Null Then
  1839. Return 2
  1840. End If
  1841. If TULongType(ty)<>Null Then
  1842. Return 3
  1843. End If
  1844. If TLongType(ty)<>Null Then
  1845. Return 4
  1846. End If
  1847. If TFloatType(ty)<>Null Then
  1848. Return 5
  1849. End If
  1850. If TDoubleType(ty)<>Null Then
  1851. Return 6
  1852. End If
  1853. Else
  1854. If TULongType(ty)<>Null Then
  1855. Return 0
  1856. End If
  1857. If TLongType(ty)<>Null Then
  1858. Return 2
  1859. End If
  1860. If TFloatType(ty)<>Null Then
  1861. Return 4
  1862. End If
  1863. If TDoubleType(ty)<>Null Then
  1864. Return 6
  1865. End If
  1866. If TFloat64Type(ty)<>Null Then
  1867. Return 8
  1868. End If
  1869. End If
  1870. Return T_MAX_DISTANCE
  1871. End Method
  1872. Method OnCopy:TType()
  1873. Return New TWParamType
  1874. End Method
  1875. Method ToString$()
  1876. Return "WPARAM" + ToStringParts()
  1877. End Method
  1878. Method GetSize:Int()
  1879. Return WORD_SIZE
  1880. End Method
  1881. End Type
  1882. Type TLParamType Extends TParamType
  1883. Method EqualsType:Int( ty:TType )
  1884. Return TLParamType( ty )<>Null And (_flags = ty._flags Or ..
  1885. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1886. End Method
  1887. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1888. If _flags & T_VARPTR And (TLParamType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1889. Return (widensTest And WidensToType(ty)) Or (Not widensTest And TNumericType( ty )<>Null) Or (Not noExtendString And TStringType( ty )<>Null) 'Or TIntVarPtrType( ty )<> Null
  1890. End Method
  1891. Method WidensToType:Int( ty:TType )
  1892. If WORD_SIZE = 4 Then
  1893. 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
  1894. Else
  1895. 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
  1896. End If
  1897. End Method
  1898. Method DistanceToType:Int(ty:TType)
  1899. If IsPointerType(ty, 0, T_POINTER) Then
  1900. If IsPointerType(Self, 0, T_POINTER) Then
  1901. Return 0
  1902. Else
  1903. Return T_MAX_DISTANCE
  1904. End If
  1905. End If
  1906. If TLParamType(ty)<>Null Then
  1907. Return 0
  1908. End If
  1909. If WORD_SIZE = 4 Then
  1910. If TIntType(ty)<>Null Then
  1911. Return 0
  1912. End If
  1913. If TLongIntType(ty)<>Null And ty.GetSize()=4 Then
  1914. Return 1
  1915. End If
  1916. If TLongType(ty)<>Null Then
  1917. Return 2
  1918. End If
  1919. If TLongIntType(ty)<>Null And ty.GetSize()=8 Then
  1920. Return 3
  1921. End If
  1922. If TFloatType(ty)<>Null Then
  1923. Return 4
  1924. End If
  1925. If TDoubleType(ty)<>Null Then
  1926. Return 6
  1927. End If
  1928. Else
  1929. If TLongType(ty)<>Null Then
  1930. Return 0
  1931. End If
  1932. If TFloatType(ty)<>Null Then
  1933. Return 2
  1934. End If
  1935. If TDoubleType(ty)<>Null Then
  1936. Return 4
  1937. End If
  1938. If TFloat64Type(ty)<>Null Then
  1939. Return 6
  1940. End If
  1941. End If
  1942. Return T_MAX_DISTANCE
  1943. End Method
  1944. Method OnCopy:TType()
  1945. Return New TLParamType
  1946. End Method
  1947. Method ToString$()
  1948. Return "LPARAM" + ToStringParts()
  1949. End Method
  1950. Method GetSize:Int()
  1951. Return WORD_SIZE
  1952. End Method
  1953. End Type
  1954. Type TEnumType Extends TType
  1955. Field decl:TEnumDecl
  1956. Method Create:TEnumType(decl:TEnumDecl)
  1957. Self.decl = decl
  1958. Return Self
  1959. End Method
  1960. Method EqualsType:Int( ty:TType )
  1961. Local ety:TEnumType = TEnumType(ty)
  1962. Return ety And decl = ety.decl And(_flags = ty._flags Or ..
  1963. (_flags & T_VARPTR And ty._flags & T_PTR) Or (ty._flags & T_VARPTR And _flags & T_PTR) Or (_flags & T_VAR))
  1964. End Method
  1965. Method ExtendsType:Int( ty:TType, noExtendString:Int = False, widensTest:Int = False, ignoreObjectSubclasses:Int = False)
  1966. If _flags & T_VARPTR And (TEnumType(ty) <> Null Or IsPointerType(ty, 0, T_POINTER)) Return True
  1967. Return (widensTest And WidensToType(ty))
  1968. End Method
  1969. Method WidensToType:Int( ty:TType )
  1970. Return (IsPointerType(ty, 0, T_POINTER) And IsPointerType(Self, 0, T_POINTER)) Or (TEnumType(ty)<>Null And TEnumType(ty).decl = decl And (ty._flags & T_VAR))
  1971. End Method
  1972. Method OnCopy:TType()
  1973. Local ty:TEnumType = New TEnumType
  1974. ty.decl = decl
  1975. Return ty
  1976. End Method
  1977. Method IsFlags:Int()
  1978. Return decl.isFlags
  1979. End Method
  1980. Method Value:String(ordinal:Int)
  1981. Return decl.values[ordinal].Value()
  1982. End Method
  1983. Method ToString$()
  1984. Return decl.ident ' + " " + ToStringParts()
  1985. End Method
  1986. Method GetClassScope:TScopeDecl()
  1987. Return decl
  1988. End Method
  1989. End Type
  1990. Type TTemplateArg
  1991. Field ident:String
  1992. Field superTy:TType[]
  1993. Method ExtendsType(ty:TType)
  1994. If Not superTy Then
  1995. superTy = New TType[0]
  1996. End If
  1997. superTy :+ [ty]
  1998. End Method
  1999. Method ToString:String()
  2000. Local s:String = ident
  2001. If superTy Then
  2002. s :+ " Extends "
  2003. For Local i:Int = 0 Until superTy.length
  2004. If i Then
  2005. s:+ " And "
  2006. End If
  2007. s :+ superTy[i].ToString()
  2008. Next
  2009. End If
  2010. End Method
  2011. End Type