njvmutil.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. {
  2. Copyright (c) 20011 by Jonas Maebe
  3. JVM version of some node tree helper routines
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit njvmutil;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,
  22. ngenutil;
  23. type
  24. tjvmnodeutils = class(tnodeutils)
  25. class function initialize_data_node(p:tnode):tnode; override;
  26. class function finalize_data_node(p:tnode):tnode; override;
  27. end;
  28. implementation
  29. uses
  30. verbose,constexp,
  31. symconst,symtype,symdef,symsym,symbase,symtable,defutil,
  32. nbas,ncnv,ncon,ninl,ncal,
  33. pass_1;
  34. class function tjvmnodeutils.initialize_data_node(p:tnode):tnode;
  35. begin
  36. if not assigned(p.resultdef) then
  37. typecheckpass(p);
  38. if ((p.resultdef.typ=stringdef) and
  39. not is_shortstring(p.resultdef) and
  40. not is_longstring(p.resultdef)) or
  41. is_dynamic_array(p.resultdef) then
  42. begin
  43. { Always initialise with empty string/array rather than nil. Java
  44. makes a distinction between an empty string/array and a null
  45. string/array, but we don't. We therefore have to pick which one we
  46. use to represent empty strings/arrays. I've chosen empty rather than
  47. null structures, because otherwise it becomes impossible to return
  48. an empty string to Java code (it would return null).
  49. On the consumer side, we do interpret both null and empty as the same
  50. thing, so Java code can pass in null strings/arrays and we'll
  51. interpret them correctly.
  52. }
  53. result:=cinlinenode.create(in_setlength_x,false,
  54. ccallparanode.create(genintconstnode(0),
  55. ccallparanode.create(p,nil)));
  56. end
  57. else
  58. { records/arrays/... are automatically initialised }
  59. result:=cnothingnode.create;
  60. end;
  61. class function tjvmnodeutils.finalize_data_node(p:tnode):tnode;
  62. begin
  63. // do nothing
  64. result:=cnothingnode.create;
  65. end;
  66. begin
  67. cnodeutils:=tjvmnodeutils;
  68. end.