jvmdef.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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. { var/const/out x: JLObject }
  289. result:=jvmaddencodedtype(java_jlobject,false,encodedstr,forcesignature,founderror);
  290. end;
  291. arraydef :
  292. begin
  293. if is_array_of_const(def) then
  294. {$ifndef nounsupported}
  295. result:=jvmaddencodedtype(java_jlobject,false,encodedstr,forcesignature,founderror)
  296. {$else}
  297. result:=false
  298. {$endif}
  299. else if is_packed_array(def) then
  300. result:=false
  301. else
  302. begin
  303. encodedstr:=encodedstr+'[';
  304. if not jvmaddencodedtype(tarraydef(def).elementdef,false,encodedstr,forcesignature,founderror) then
  305. begin
  306. result:=false;
  307. { report the exact (nested) error defintion }
  308. exit;
  309. end;
  310. end;
  311. end;
  312. procvardef :
  313. begin
  314. {$ifndef nounsupported}
  315. result:=jvmaddencodedtype(java_jlobject,false,encodedstr,forcesignature,founderror);
  316. {$else}
  317. { will be hanlded via wrapping later, although wrapping may
  318. happen at higher level }
  319. result:=false;
  320. {$endif}
  321. end;
  322. objectdef :
  323. case tobjectdef(def).objecttype of
  324. odt_javaclass,
  325. odt_interfacejava:
  326. encodedstr:=encodedstr+'L'+tobjectdef(def).jvm_full_typename(true)+';'
  327. else
  328. result:=false;
  329. end;
  330. undefineddef,
  331. errordef :
  332. result:=false;
  333. procdef :
  334. { must be done via jvmencodemethod() }
  335. internalerror(2010121903);
  336. else
  337. internalerror(2010121904);
  338. end;
  339. if not result then
  340. founderror:=def;
  341. end;
  342. function jvmtryencodetype(def: tdef; out encodedtype: TSymStr; forcesignature: boolean; out founderror: tdef): boolean;
  343. begin
  344. encodedtype:='';
  345. result:=jvmaddencodedtype(def,false,encodedtype,forcesignature,founderror);
  346. end;
  347. procedure jvmaddtypeownerprefix(owner: tsymtable; var name: TSymStr);
  348. var
  349. owningcontainer: tsymtable;
  350. tmpresult: TSymStr;
  351. module: tmodule;
  352. nameendpos: longint;
  353. begin
  354. { see tprocdef.jvmmangledbasename for description of the format }
  355. owningcontainer:=owner;
  356. while (owningcontainer.symtabletype=localsymtable) do
  357. owningcontainer:=owningcontainer.defowner.owner;
  358. case owningcontainer.symtabletype of
  359. globalsymtable,
  360. staticsymtable:
  361. begin
  362. module:=find_module_from_symtable(owningcontainer);
  363. tmpresult:='';
  364. if assigned(module.namespace) then
  365. tmpresult:=module.namespace^+'/';
  366. tmpresult:=tmpresult+module.realmodulename^+'/';
  367. end;
  368. objectsymtable:
  369. case tobjectdef(owningcontainer.defowner).objecttype of
  370. odt_javaclass,
  371. odt_interfacejava:
  372. begin
  373. tmpresult:=tobjectdef(owningcontainer.defowner).jvm_full_typename(true)+'/'
  374. end
  375. else
  376. internalerror(2010122606);
  377. end;
  378. recordsymtable:
  379. tmpresult:=trecorddef(owningcontainer.defowner).jvm_full_typename(true)+'/'
  380. else
  381. internalerror(2010122605);
  382. end;
  383. name:=tmpresult+name;
  384. nameendpos:=pos(' ',name);
  385. if nameendpos=0 then
  386. nameendpos:=length(name)+1;
  387. insert('''',name,nameendpos);
  388. name:=''''+name;
  389. end;
  390. function jvmarrtype(def: tdef; out primitivetype: boolean): TSymStr;
  391. var
  392. errdef: tdef;
  393. begin
  394. if not jvmtryencodetype(def,result,false,errdef) then
  395. internalerror(2011012205);
  396. primitivetype:=false;
  397. if length(result)=1 then
  398. begin
  399. case result[1] of
  400. 'Z': result:='boolean';
  401. 'C': result:='char';
  402. 'B': result:='byte';
  403. 'S': result:='short';
  404. 'I': result:='int';
  405. 'J': result:='long';
  406. 'F': result:='float';
  407. 'D': result:='double';
  408. else
  409. internalerror(2011012206);
  410. end;
  411. primitivetype:=true;
  412. end
  413. else if (result[1]='L') then
  414. begin
  415. { in case of a class reference, strip the leading 'L' and the
  416. trailing ';' }
  417. setlength(result,length(result)-1);
  418. delete(result,1,1);
  419. end;
  420. { for arrays, use the actual reference type }
  421. end;
  422. function jvmarrtype_setlength(def: tdef): char;
  423. var
  424. errdef: tdef;
  425. res: TSymStr;
  426. begin
  427. { keep in sync with rtl/java/jdynarrh.inc and usage in njvminl }
  428. if is_record(def) then
  429. result:='R'
  430. else if is_shortstring(def) then
  431. result:='T'
  432. else if def.typ=setdef then
  433. begin
  434. if tsetdef(def).elementdef.typ=enumdef then
  435. result:='E'
  436. else
  437. result:='L'
  438. end
  439. else
  440. begin
  441. if not jvmtryencodetype(def,res,false,errdef) then
  442. internalerror(2011012209);
  443. if length(res)=1 then
  444. result:=res[1]
  445. else
  446. result:='A';
  447. end;
  448. end;
  449. function jvmimplicitpointertype(def: tdef): boolean;
  450. begin
  451. case def.typ of
  452. arraydef:
  453. result:=(tarraydef(def).highrange>=tarraydef(def).lowrange) or
  454. is_open_array(def) or
  455. is_array_of_const(def) or
  456. is_array_constructor(def);
  457. recorddef,
  458. setdef:
  459. result:=true;
  460. objectdef:
  461. result:=is_object(def);
  462. stringdef :
  463. result:=tstringdef(def).stringtype in [st_shortstring,st_longstring];
  464. else
  465. result:=false;
  466. end;
  467. end;
  468. procedure jvmgetboxtype(def: tdef; out objdef, paradef: tdef);
  469. begin
  470. case def.typ of
  471. orddef:
  472. begin
  473. case torddef(def).ordtype of
  474. pasbool8:
  475. begin
  476. objdef:=tobjectdef(search_system_type('JLBOOLEAN').typedef);
  477. paradef:=pasbool8type;
  478. end;
  479. { wrap all integer types into a JLLONG, so that we don't get
  480. errors after returning a byte assigned to a long etc }
  481. s8bit,
  482. u8bit,
  483. uchar,
  484. bool8bit,
  485. s16bit,
  486. u16bit,
  487. bool16bit,
  488. pasbool16,
  489. s32bit,
  490. u32bit,
  491. bool32bit,
  492. pasbool32,
  493. s64bit,
  494. u64bit,
  495. scurrency,
  496. bool64bit,
  497. pasbool64:
  498. begin
  499. objdef:=tobjectdef(search_system_type('JLLONG').typedef);
  500. paradef:=s64inttype;
  501. end;
  502. uwidechar:
  503. begin
  504. objdef:=tobjectdef(search_system_type('JLCHARACTER').typedef);
  505. paradef:=cwidechartype;
  506. end;
  507. else
  508. internalerror(2011052101);
  509. end;
  510. end;
  511. floatdef:
  512. begin
  513. case tfloatdef(def).floattype of
  514. s32real:
  515. begin
  516. objdef:=tobjectdef(search_system_type('JLFLOAT').typedef);
  517. paradef:=s32floattype;
  518. end;
  519. s64real:
  520. begin
  521. objdef:=tobjectdef(search_system_type('JLDOUBLE').typedef);
  522. paradef:=s64floattype;
  523. end;
  524. else
  525. internalerror(2011052102);
  526. end;
  527. end;
  528. else
  529. internalerror(2011052103);
  530. end;
  531. end;
  532. function jvmgetunboxmethod(def: tdef): string;
  533. begin
  534. case def.typ of
  535. orddef:
  536. begin
  537. case torddef(def).ordtype of
  538. pasbool8:
  539. result:='BOOLEANVALUE';
  540. s8bit,
  541. u8bit,
  542. uchar,
  543. bool8bit:
  544. result:='BYTEVALUE';
  545. s16bit,
  546. u16bit,
  547. bool16bit,
  548. pasbool16:
  549. result:='SHORTVALUE';
  550. s32bit,
  551. u32bit,
  552. bool32bit,
  553. pasbool32:
  554. result:='INTVALUE';
  555. s64bit,
  556. u64bit,
  557. scurrency,
  558. bool64bit,
  559. pasbool64:
  560. result:='LONGVALUE';
  561. uwidechar:
  562. result:='CHARVALUE';
  563. else
  564. internalerror(2011071702);
  565. end;
  566. end;
  567. floatdef:
  568. begin
  569. case tfloatdef(def).floattype of
  570. s32real:
  571. result:='FLOATVALUE';
  572. s64real:
  573. result:='DOUBLEVALUE';
  574. else
  575. internalerror(2011071703);
  576. end;
  577. end;
  578. else
  579. internalerror(2011071704);
  580. end;
  581. end;
  582. function jvmmangledbasename(sym: tsym; const usesymname: TSymStr; withsignature: boolean): TSymStr;
  583. var
  584. container: tsymtable;
  585. vsym: tabstractvarsym;
  586. csym: tconstsym;
  587. begin
  588. case sym.typ of
  589. staticvarsym,
  590. paravarsym,
  591. localvarsym,
  592. fieldvarsym:
  593. begin
  594. vsym:=tabstractvarsym(sym);
  595. result:=jvmencodetype(vsym.vardef,false);
  596. if withsignature and
  597. jvmtypeneedssignature(vsym.vardef) then
  598. begin
  599. result:=result+' signature "';
  600. result:=result+jvmencodetype(vsym.vardef,true)+'"';
  601. end;
  602. if (vsym.typ=paravarsym) and
  603. (vo_is_self in tparavarsym(vsym).varoptions) then
  604. result:='''this'' ' +result
  605. else if (vsym.typ in [paravarsym,localvarsym]) and
  606. ([vo_is_funcret,vo_is_result] * tabstractnormalvarsym(vsym).varoptions <> []) then
  607. result:='''result'' '+result
  608. else
  609. begin
  610. { add array indirection if required }
  611. if (vsym.typ=paravarsym) and
  612. (vsym.vardef.typ=formaldef) or
  613. ((vsym.varspez in [vs_var,vs_out,vs_constref]) and
  614. not jvmimplicitpointertype(vsym.vardef)) then
  615. result:='['+result;
  616. { single quotes for definitions to prevent clashes with Java
  617. opcodes }
  618. if withsignature then
  619. result:=usesymname+''' '+result
  620. else
  621. result:=usesymname+' '+result;
  622. { we have to mangle staticvarsyms in localsymtables to
  623. prevent name clashes... }
  624. if (vsym.typ=staticvarsym) then
  625. begin
  626. container:=sym.Owner;
  627. while (container.symtabletype=localsymtable) do
  628. begin
  629. if tdef(container.defowner).typ<>procdef then
  630. internalerror(2011040303);
  631. { symid is added to prevent problem with overloads }
  632. result:=tprocdef(container.defowner).procsym.realname+'$$'+tostr(tprocdef(container.defowner).procsym.symid)+'$'+result;
  633. container:=container.defowner.owner;
  634. end;
  635. end;
  636. if withsignature then
  637. result:=''''+result
  638. end;
  639. end;
  640. constsym:
  641. begin
  642. csym:=tconstsym(sym);
  643. { some constants can be untyped }
  644. if assigned (csym.constdef) then
  645. begin
  646. result:=jvmencodetype(csym.constdef,false);
  647. if withsignature and
  648. jvmtypeneedssignature(csym.constdef) then
  649. begin
  650. result:=result+' signature "';
  651. result:=result+jvmencodetype(csym.constdef,true)+'"';
  652. end;
  653. end
  654. else
  655. begin
  656. case csym.consttyp of
  657. constord:
  658. result:=jvmencodetype(s32inttype,withsignature);
  659. constreal:
  660. result:=jvmencodetype(s64floattype,withsignature);
  661. constset:
  662. internalerror(2011040701);
  663. constpointer,
  664. constnil:
  665. result:=jvmencodetype(java_jlobject,withsignature);
  666. constwstring,
  667. conststring:
  668. result:=jvmencodetype(java_jlstring,withsignature);
  669. constresourcestring:
  670. internalerror(2011040702);
  671. else
  672. internalerror(2011040703);
  673. end;
  674. end;
  675. if withsignature then
  676. result:=''''+usesymname+''' '+result
  677. else
  678. result:=usesymname+' '+result
  679. end;
  680. else
  681. internalerror(2011021703);
  682. end;
  683. end;
  684. function jvmmangledbasename(sym: tsym; withsignature: boolean): TSymStr;
  685. begin
  686. if (sym.typ=fieldvarsym) and
  687. assigned(tfieldvarsym(sym).externalname) then
  688. result:=jvmmangledbasename(sym,tfieldvarsym(sym).externalname^,withsignature)
  689. else
  690. result:=jvmmangledbasename(sym,sym.RealName,withsignature);
  691. end;
  692. {******************************************************************
  693. jvm type validity checking
  694. *******************************************************************}
  695. function jvmencodetype(def: tdef; withsignature: boolean): TSymStr;
  696. var
  697. errordef: tdef;
  698. begin
  699. if not jvmtryencodetype(def,result,withsignature,errordef) then
  700. internalerror(2011012305);
  701. end;
  702. function jvmchecktype(def: tdef; out founderror: tdef): boolean;
  703. var
  704. encodedtype: TSymStr;
  705. begin
  706. { don't duplicate the code like in objcdef, since the resulting strings
  707. are much shorter here so it's not worth it }
  708. result:=jvmtryencodetype(def,encodedtype,false,founderror);
  709. end;
  710. end.