jvmdef.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. {
  2. Copyright (c) 2010 by Jonas Maebe
  3. This unit implements some JVM type helper routines (minimal
  4. unit dependencies, usable in symdef).
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {$i fpcdefs.inc}
  19. unit jvmdef;
  20. interface
  21. uses
  22. globtype,
  23. node,
  24. symbase,symtype;
  25. { returns whether a def can make use of an extra type signature (for
  26. Java-style generics annotations; not use for FPC-style generics or their
  27. translations, but to annotate the kind of classref a java.lang.Class is
  28. and things like that) }
  29. function jvmtypeneedssignature(def: tdef): boolean;
  30. { create a signature encoding of a particular type; requires that
  31. jvmtypeneedssignature returned "true" for this type }
  32. procedure jvmaddencodedsignature(def: tdef; bpacked: boolean; var encodedstr: TSymStr);
  33. { Encode a type into the internal format used by the JVM (descriptor).
  34. Returns false if a type is not representable by the JVM,
  35. and in that case also the failing definition. }
  36. function jvmtryencodetype(def: tdef; out encodedtype: TSymStr; forcesignature: boolean; out founderror: tdef): boolean;
  37. { same as above, but throws an internal error on failure }
  38. function jvmencodetype(def: tdef; withsignature: boolean): TSymStr;
  39. { Check whether a type can be used in a JVM methom signature or field
  40. declaration. }
  41. function jvmchecktype(def: tdef; out founderror: tdef): boolean;
  42. { incremental version of jvmtryencodetype() }
  43. function jvmaddencodedtype(def: tdef; bpacked: boolean; var encodedstr: TSymStr; forcesignature: boolean; out founderror: tdef): boolean;
  44. { add type prefix (package name) to a type }
  45. procedure jvmaddtypeownerprefix(owner: tsymtable; var name: TSymStr);
  46. { returns type string for a single-dimensional array (different from normal
  47. typestring in case of a primitive type) }
  48. function jvmarrtype(def: tdef; out primitivetype: boolean): TSymStr;
  49. function jvmarrtype_setlength(def: tdef): char;
  50. { returns whether a def is emulated using an implicit pointer type on the
  51. JVM target (e.g., records, regular arrays, ...) }
  52. function jvmimplicitpointertype(def: tdef): boolean;
  53. { returns the mangled base name for a tsym (type + symbol name, no
  54. visibility etc); also adds signature attribute if requested and
  55. appropriate }
  56. function jvmmangledbasename(sym: tsym; withsignature: boolean): TSymStr;
  57. function jvmmangledbasename(sym: tsym; const usesymname: TSymStr; withsignature: boolean): TSymStr;
  58. { sometimes primitive types have to be boxed/unboxed via class types. This
  59. routine returns the appropriate box type for the passed primitive type }
  60. procedure jvmgetboxtype(def: tdef; out objdef, paradef: tdef);
  61. function jvmgetunboxmethod(def: tdef): string;
  62. implementation
  63. uses
  64. cutils,cclasses,
  65. verbose,systems,
  66. fmodule,
  67. symtable,symconst,symsym,symdef,symcreat,
  68. defutil,paramgr;
  69. {******************************************************************
  70. Type encoding
  71. *******************************************************************}
  72. function jvmtypeneedssignature(def: tdef): boolean;
  73. var
  74. i: longint;
  75. begin
  76. result:=false;
  77. case def.typ of
  78. classrefdef,
  79. setdef:
  80. begin
  81. result:=true;
  82. end;
  83. arraydef :
  84. begin
  85. result:=jvmtypeneedssignature(tarraydef(def).elementdef);
  86. end;
  87. procvardef :
  88. begin
  89. { may change in the future }
  90. end;
  91. procdef :
  92. begin
  93. for i:=0 to tprocdef(def).paras.count-1 do
  94. begin
  95. result:=jvmtypeneedssignature(tparavarsym(tprocdef(def).paras[i]).vardef);
  96. if result then
  97. exit;
  98. end;
  99. end
  100. else
  101. result:=false;
  102. end;
  103. end;
  104. procedure jvmaddencodedsignature(def: tdef; bpacked: boolean; var encodedstr: TSymStr);
  105. var
  106. founderror: tdef;
  107. begin
  108. case def.typ of
  109. pointerdef :
  110. begin
  111. { maybe one day }
  112. internalerror(2011051403);
  113. end;
  114. classrefdef :
  115. begin
  116. { Ljava/lang/Class<+SomeClassType> means
  117. "Ljava/lang/Class<SomeClassType_or_any_of_its_descendents>" }
  118. encodedstr:=encodedstr+'Ljava/lang/Class<+';
  119. jvmaddencodedtype(tclassrefdef(def).pointeddef,false,encodedstr,true,founderror);
  120. encodedstr:=encodedstr+'>;';
  121. end;
  122. setdef :
  123. begin
  124. if tsetdef(def).elementdef.typ=enumdef then
  125. begin
  126. encodedstr:=encodedstr+'Ljava/util/EnumSet<';
  127. jvmaddencodedtype(tenumdef(tsetdef(def).elementdef).getbasedef,false,encodedstr,true,founderror);
  128. encodedstr:=encodedstr+'>;';
  129. end
  130. else
  131. internalerror(2011051404);
  132. end;
  133. arraydef :
  134. begin
  135. if is_array_of_const(def) then
  136. begin
  137. internalerror(2011051405);
  138. end
  139. else if is_packed_array(def) then
  140. begin
  141. internalerror(2011051406);
  142. end
  143. else
  144. begin
  145. encodedstr:=encodedstr+'[';
  146. jvmaddencodedsignature(tarraydef(def).elementdef,false,encodedstr);
  147. end;
  148. end;
  149. procvardef :
  150. begin
  151. { maybe one day }
  152. internalerror(2011051407);
  153. end;
  154. objectdef :
  155. begin
  156. { maybe one day }
  157. end;
  158. undefineddef,
  159. errordef :
  160. begin
  161. internalerror(2011051408);
  162. end;
  163. procdef :
  164. { must be done via jvmencodemethod() }
  165. internalerror(2011051401);
  166. else
  167. internalerror(2011051402);
  168. end;
  169. end;
  170. function jvmaddencodedtype(def: tdef; bpacked: boolean; var encodedstr: TSymStr; forcesignature: boolean; out founderror: tdef): boolean;
  171. var
  172. c: char;
  173. begin
  174. result:=true;
  175. case def.typ of
  176. stringdef :
  177. begin
  178. case tstringdef(def).stringtype of
  179. { translated into java.lang.String }
  180. st_widestring,
  181. st_unicodestring:
  182. result:=jvmaddencodedtype(java_jlstring,false,encodedstr,forcesignature,founderror);
  183. st_ansistring:
  184. result:=jvmaddencodedtype(java_ansistring,false,encodedstr,forcesignature,founderror);
  185. st_shortstring:
  186. result:=jvmaddencodedtype(java_shortstring,false,encodedstr,forcesignature,founderror);
  187. else
  188. { May be handled via wrapping later }
  189. result:=false;
  190. end;
  191. end;
  192. enumdef:
  193. begin
  194. result:=jvmaddencodedtype(tenumdef(def).classdef,false,encodedstr,forcesignature,founderror);
  195. end;
  196. orddef :
  197. begin
  198. { for procedure "results" }
  199. if is_void(def) then
  200. c:='V'
  201. { only Pascal-style booleans conform to Java's definition of
  202. Boolean }
  203. else if is_pasbool(def) and
  204. (def.size=1) then
  205. c:='Z'
  206. else if is_widechar(def) then
  207. c:='C'
  208. else
  209. begin
  210. case def.size of
  211. 1:
  212. c:='B';
  213. 2:
  214. c:='S';
  215. 4:
  216. c:='I';
  217. 8:
  218. c:='J';
  219. else
  220. internalerror(2010121905);
  221. end;
  222. end;
  223. encodedstr:=encodedstr+c;
  224. end;
  225. pointerdef :
  226. begin
  227. if def=voidpointertype then
  228. result:=jvmaddencodedtype(java_jlobject,false,encodedstr,forcesignature,founderror)
  229. else if jvmimplicitpointertype(tpointerdef(def).pointeddef) then
  230. result:=jvmaddencodedtype(tpointerdef(def).pointeddef,false,encodedstr,forcesignature,founderror)
  231. else
  232. begin
  233. { used for internal pointer constructs }
  234. encodedstr:=encodedstr+'[';
  235. result:=jvmaddencodedtype(tpointerdef(def).pointeddef,false,encodedstr,forcesignature,founderror);
  236. end;
  237. end;
  238. floatdef :
  239. begin
  240. case tfloatdef(def).floattype of
  241. s32real:
  242. c:='F';
  243. s64real:
  244. c:='D';
  245. else
  246. result:=false;
  247. end;
  248. encodedstr:=encodedstr+c;
  249. end;
  250. filedef :
  251. result:=false;
  252. recorddef :
  253. begin
  254. encodedstr:=encodedstr+'L'+trecorddef(def).jvm_full_typename(true)+';'
  255. end;
  256. variantdef :
  257. begin
  258. { will be hanlded via wrapping later, although wrapping may
  259. happen at higher level }
  260. result:=false;
  261. end;
  262. classrefdef :
  263. begin
  264. if not forcesignature then
  265. { unfortunately, java.lang.Class is final, so we can't create
  266. different versions for difference class reference types }
  267. encodedstr:=encodedstr+'Ljava/lang/Class;'
  268. { we can however annotate it with extra signature information in
  269. using Java's generic annotations }
  270. else
  271. jvmaddencodedsignature(def,false,encodedstr);
  272. result:=true;
  273. end;
  274. setdef :
  275. begin
  276. if tsetdef(def).elementdef.typ=enumdef then
  277. begin
  278. if forcesignature then
  279. jvmaddencodedsignature(def,false,encodedstr)
  280. else
  281. result:=jvmaddencodedtype(java_juenumset,false,encodedstr,forcesignature,founderror)
  282. end
  283. else
  284. result:=jvmaddencodedtype(java_jubitset,false,encodedstr,forcesignature,founderror)
  285. end;
  286. formaldef :
  287. begin
  288. {$ifndef nounsupported}
  289. { var/const/out x: JLObject }
  290. result:=jvmaddencodedtype(java_jlobject,false,encodedstr,forcesignature,founderror);
  291. {$else}
  292. result:=false;
  293. {$endif}
  294. end;
  295. arraydef :
  296. begin
  297. if is_array_of_const(def) then
  298. {$ifndef nounsupported}
  299. result:=jvmaddencodedtype(java_jlobject,false,encodedstr,forcesignature,founderror)
  300. {$else}
  301. result:=false
  302. {$endif}
  303. else if is_packed_array(def) then
  304. result:=false
  305. else
  306. begin
  307. encodedstr:=encodedstr+'[';
  308. if not jvmaddencodedtype(tarraydef(def).elementdef,false,encodedstr,forcesignature,founderror) then
  309. begin
  310. result:=false;
  311. { report the exact (nested) error defintion }
  312. exit;
  313. end;
  314. end;
  315. end;
  316. procvardef :
  317. begin
  318. {$ifndef nounsupported}
  319. result:=jvmaddencodedtype(java_jlobject,false,encodedstr,forcesignature,founderror);
  320. {$else}
  321. { will be hanlded via wrapping later, although wrapping may
  322. happen at higher level }
  323. result:=false;
  324. {$endif}
  325. end;
  326. objectdef :
  327. case tobjectdef(def).objecttype of
  328. odt_javaclass,
  329. odt_interfacejava:
  330. encodedstr:=encodedstr+'L'+tobjectdef(def).jvm_full_typename(true)+';'
  331. else
  332. result:=false;
  333. end;
  334. undefineddef,
  335. errordef :
  336. result:=false;
  337. procdef :
  338. { must be done via jvmencodemethod() }
  339. internalerror(2010121903);
  340. else
  341. internalerror(2010121904);
  342. end;
  343. if not result then
  344. founderror:=def;
  345. end;
  346. function jvmtryencodetype(def: tdef; out encodedtype: TSymStr; forcesignature: boolean; out founderror: tdef): boolean;
  347. begin
  348. encodedtype:='';
  349. result:=jvmaddencodedtype(def,false,encodedtype,forcesignature,founderror);
  350. end;
  351. procedure jvmaddtypeownerprefix(owner: tsymtable; var name: TSymStr);
  352. var
  353. owningcontainer: tsymtable;
  354. tmpresult: TSymStr;
  355. module: tmodule;
  356. nameendpos: longint;
  357. begin
  358. { see tprocdef.jvmmangledbasename for description of the format }
  359. owningcontainer:=owner;
  360. while (owningcontainer.symtabletype=localsymtable) do
  361. owningcontainer:=owningcontainer.defowner.owner;
  362. case owningcontainer.symtabletype of
  363. globalsymtable,
  364. staticsymtable:
  365. begin
  366. module:=find_module_from_symtable(owningcontainer);
  367. tmpresult:='';
  368. if assigned(module.namespace) then
  369. tmpresult:=module.namespace^+'/';
  370. tmpresult:=tmpresult+module.realmodulename^+'/';
  371. end;
  372. objectsymtable:
  373. case tobjectdef(owningcontainer.defowner).objecttype of
  374. odt_javaclass,
  375. odt_interfacejava:
  376. begin
  377. tmpresult:=tobjectdef(owningcontainer.defowner).jvm_full_typename(true)+'/'
  378. end
  379. else
  380. internalerror(2010122606);
  381. end;
  382. recordsymtable:
  383. tmpresult:=trecorddef(owningcontainer.defowner).jvm_full_typename(true)+'/'
  384. else
  385. internalerror(2010122605);
  386. end;
  387. name:=tmpresult+name;
  388. nameendpos:=pos(' ',name);
  389. if nameendpos=0 then
  390. nameendpos:=length(name)+1;
  391. insert('''',name,nameendpos);
  392. name:=''''+name;
  393. end;
  394. function jvmarrtype(def: tdef; out primitivetype: boolean): TSymStr;
  395. var
  396. errdef: tdef;
  397. begin
  398. if not jvmtryencodetype(def,result,false,errdef) then
  399. internalerror(2011012205);
  400. primitivetype:=false;
  401. if length(result)=1 then
  402. begin
  403. case result[1] of
  404. 'Z': result:='boolean';
  405. 'C': result:='char';
  406. 'B': result:='byte';
  407. 'S': result:='short';
  408. 'I': result:='int';
  409. 'J': result:='long';
  410. 'F': result:='float';
  411. 'D': result:='double';
  412. else
  413. internalerror(2011012206);
  414. end;
  415. primitivetype:=true;
  416. end
  417. else if (result[1]='L') then
  418. begin
  419. { in case of a class reference, strip the leading 'L' and the
  420. trailing ';' }
  421. setlength(result,length(result)-1);
  422. delete(result,1,1);
  423. end;
  424. { for arrays, use the actual reference type }
  425. end;
  426. function jvmarrtype_setlength(def: tdef): char;
  427. var
  428. errdef: tdef;
  429. res: TSymStr;
  430. begin
  431. { keep in sync with rtl/java/jdynarrh.inc and usage in njvminl }
  432. if is_record(def) then
  433. result:='R'
  434. else if is_shortstring(def) then
  435. result:='T'
  436. else if def.typ=setdef then
  437. begin
  438. if tsetdef(def).elementdef.typ=enumdef then
  439. result:='E'
  440. else
  441. result:='L'
  442. end
  443. else
  444. begin
  445. if not jvmtryencodetype(def,res,false,errdef) then
  446. internalerror(2011012209);
  447. if length(res)=1 then
  448. result:=res[1]
  449. else
  450. result:='A';
  451. end;
  452. end;
  453. function jvmimplicitpointertype(def: tdef): boolean;
  454. begin
  455. case def.typ of
  456. arraydef:
  457. result:=(tarraydef(def).highrange>=tarraydef(def).lowrange) or
  458. is_open_array(def) or
  459. is_array_of_const(def) or
  460. is_array_constructor(def);
  461. recorddef,
  462. setdef:
  463. result:=true;
  464. objectdef:
  465. result:=is_object(def);
  466. stringdef :
  467. result:=tstringdef(def).stringtype in [st_shortstring,st_longstring];
  468. else
  469. result:=false;
  470. end;
  471. end;
  472. procedure jvmgetboxtype(def: tdef; out objdef, paradef: tdef);
  473. begin
  474. case def.typ of
  475. orddef:
  476. begin
  477. case torddef(def).ordtype of
  478. pasbool8:
  479. begin
  480. objdef:=tobjectdef(search_system_type('JLBOOLEAN').typedef);
  481. paradef:=pasbool8type;
  482. end;
  483. { wrap all integer types into a JLLONG, so that we don't get
  484. errors after returning a byte assigned to a long etc }
  485. s8bit,
  486. u8bit,
  487. uchar,
  488. bool8bit,
  489. s16bit,
  490. u16bit,
  491. bool16bit,
  492. pasbool16,
  493. s32bit,
  494. u32bit,
  495. bool32bit,
  496. pasbool32,
  497. s64bit,
  498. u64bit,
  499. scurrency,
  500. bool64bit,
  501. pasbool64:
  502. begin
  503. objdef:=tobjectdef(search_system_type('JLLONG').typedef);
  504. paradef:=s64inttype;
  505. end;
  506. uwidechar:
  507. begin
  508. objdef:=tobjectdef(search_system_type('JLCHARACTER').typedef);
  509. paradef:=cwidechartype;
  510. end;
  511. else
  512. internalerror(2011052101);
  513. end;
  514. end;
  515. floatdef:
  516. begin
  517. case tfloatdef(def).floattype of
  518. s32real:
  519. begin
  520. objdef:=tobjectdef(search_system_type('JLFLOAT').typedef);
  521. paradef:=s32floattype;
  522. end;
  523. s64real:
  524. begin
  525. objdef:=tobjectdef(search_system_type('JLDOUBLE').typedef);
  526. paradef:=s64floattype;
  527. end;
  528. else
  529. internalerror(2011052102);
  530. end;
  531. end;
  532. else
  533. internalerror(2011052103);
  534. end;
  535. end;
  536. function jvmgetunboxmethod(def: tdef): string;
  537. begin
  538. case def.typ of
  539. orddef:
  540. begin
  541. case torddef(def).ordtype of
  542. pasbool8:
  543. result:='BOOLEANVALUE';
  544. s8bit,
  545. u8bit,
  546. uchar,
  547. bool8bit:
  548. result:='BYTEVALUE';
  549. s16bit,
  550. u16bit,
  551. bool16bit,
  552. pasbool16:
  553. result:='SHORTVALUE';
  554. s32bit,
  555. u32bit,
  556. bool32bit,
  557. pasbool32:
  558. result:='INTVALUE';
  559. s64bit,
  560. u64bit,
  561. scurrency,
  562. bool64bit,
  563. pasbool64:
  564. result:='LONGVALUE';
  565. uwidechar:
  566. result:='CHARVALUE';
  567. else
  568. internalerror(2011071702);
  569. end;
  570. end;
  571. floatdef:
  572. begin
  573. case tfloatdef(def).floattype of
  574. s32real:
  575. result:='FLOATVALUE';
  576. s64real:
  577. result:='DOUBLEVALUE';
  578. else
  579. internalerror(2011071703);
  580. end;
  581. end;
  582. else
  583. internalerror(2011071704);
  584. end;
  585. end;
  586. function jvmmangledbasename(sym: tsym; const usesymname: TSymStr; withsignature: boolean): TSymStr;
  587. var
  588. container: tsymtable;
  589. vsym: tabstractvarsym;
  590. csym: tconstsym;
  591. begin
  592. case sym.typ of
  593. staticvarsym,
  594. paravarsym,
  595. localvarsym,
  596. fieldvarsym:
  597. begin
  598. vsym:=tabstractvarsym(sym);
  599. result:=jvmencodetype(vsym.vardef,false);
  600. if withsignature and
  601. jvmtypeneedssignature(vsym.vardef) then
  602. begin
  603. result:=result+' signature "';
  604. result:=result+jvmencodetype(vsym.vardef,true)+'"';
  605. end;
  606. if (vsym.typ=paravarsym) and
  607. (vo_is_self in tparavarsym(vsym).varoptions) then
  608. result:='''this'' ' +result
  609. else if (vsym.typ in [paravarsym,localvarsym]) and
  610. ([vo_is_funcret,vo_is_result] * tabstractnormalvarsym(vsym).varoptions <> []) then
  611. result:='''result'' '+result
  612. else
  613. begin
  614. { add array indirection if required }
  615. if (vsym.typ=paravarsym) and
  616. (vsym.vardef.typ=formaldef) or
  617. ((vsym.varspez in [vs_var,vs_out,vs_constref]) and
  618. not jvmimplicitpointertype(vsym.vardef)) then
  619. result:='['+result;
  620. { single quotes for definitions to prevent clashes with Java
  621. opcodes }
  622. if withsignature then
  623. result:=usesymname+''' '+result
  624. else
  625. result:=usesymname+' '+result;
  626. { we have to mangle staticvarsyms in localsymtables to
  627. prevent name clashes... }
  628. if (vsym.typ=staticvarsym) then
  629. begin
  630. container:=sym.Owner;
  631. while (container.symtabletype=localsymtable) do
  632. begin
  633. if tdef(container.defowner).typ<>procdef then
  634. internalerror(2011040303);
  635. { symid is added to prevent problem with overloads }
  636. result:=tprocdef(container.defowner).procsym.realname+'$$'+tostr(tprocdef(container.defowner).procsym.symid)+'$'+result;
  637. container:=container.defowner.owner;
  638. end;
  639. end;
  640. if withsignature then
  641. result:=''''+result
  642. end;
  643. end;
  644. constsym:
  645. begin
  646. csym:=tconstsym(sym);
  647. { some constants can be untyped }
  648. if assigned (csym.constdef) then
  649. begin
  650. result:=jvmencodetype(csym.constdef,false);
  651. if withsignature and
  652. jvmtypeneedssignature(csym.constdef) then
  653. begin
  654. result:=result+' signature "';
  655. result:=result+jvmencodetype(csym.constdef,true)+'"';
  656. end;
  657. end
  658. else
  659. begin
  660. case csym.consttyp of
  661. constord:
  662. result:=jvmencodetype(s32inttype,withsignature);
  663. constreal:
  664. result:=jvmencodetype(s64floattype,withsignature);
  665. constset:
  666. internalerror(2011040701);
  667. constpointer,
  668. constnil:
  669. result:=jvmencodetype(java_jlobject,withsignature);
  670. constwstring,
  671. conststring:
  672. result:=jvmencodetype(java_jlstring,withsignature);
  673. constresourcestring:
  674. internalerror(2011040702);
  675. else
  676. internalerror(2011040703);
  677. end;
  678. end;
  679. if withsignature then
  680. result:=''''+usesymname+''' '+result
  681. else
  682. result:=usesymname+' '+result
  683. end;
  684. else
  685. internalerror(2011021703);
  686. end;
  687. end;
  688. function jvmmangledbasename(sym: tsym; withsignature: boolean): TSymStr;
  689. begin
  690. if (sym.typ=fieldvarsym) and
  691. assigned(tfieldvarsym(sym).externalname) then
  692. result:=jvmmangledbasename(sym,tfieldvarsym(sym).externalname^,withsignature)
  693. else
  694. result:=jvmmangledbasename(sym,sym.RealName,withsignature);
  695. end;
  696. {******************************************************************
  697. jvm type validity checking
  698. *******************************************************************}
  699. function jvmencodetype(def: tdef; withsignature: boolean): TSymStr;
  700. var
  701. errordef: tdef;
  702. begin
  703. if not jvmtryencodetype(def,result,withsignature,errordef) then
  704. internalerror(2011012305);
  705. end;
  706. function jvmchecktype(def: tdef; out founderror: tdef): boolean;
  707. var
  708. encodedtype: TSymStr;
  709. begin
  710. { don't duplicate the code like in objcdef, since the resulting strings
  711. are much shorter here so it's not worth it }
  712. result:=jvmtryencodetype(def,encodedtype,false,founderror);
  713. end;
  714. end.