PtrDesc.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**********************************************************************/
  2. /* Pointer Descriptor class for j2cps */
  3. /* */
  4. /* (c) copyright QUT, John Gough 2000-2012, John Gough, 2012-2017 */
  5. /**********************************************************************/
  6. package j2cps;
  7. import java.io.DataOutputStream;
  8. import java.io.IOException;
  9. public class PtrDesc extends TypeDesc {
  10. TypeDesc boundType;
  11. public PtrDesc(TypeDesc baseType) {
  12. this.typeOrd = TypeDesc.arrPtr;
  13. this.boundType = baseType;
  14. if (this.boundType != null) {
  15. this.name = "POINTER TO " + this.boundType.name;
  16. }
  17. }
  18. public PtrDesc(int inNum, int baseNum) {
  19. this.typeOrd = TypeDesc.arrPtr;
  20. this.inTypeNum = inNum;
  21. this.inBaseTypeNum = baseNum;
  22. }
  23. public void Init(TypeDesc baseType) {
  24. this.boundType = baseType;
  25. if (this.boundType != null) { setName(); }
  26. }
  27. public void AddImportToPtr(ClassDesc thisClass) {
  28. if (this.boundType instanceof ClassDesc) {
  29. ((ClassDesc)this.boundType).blame = this.blame;
  30. thisClass.AddImportToClass((ClassDesc)this.boundType);
  31. } else if (this.boundType instanceof ArrayDesc) {
  32. ((ArrayDesc)this.boundType).blame = this.blame;
  33. ((ArrayDesc)this.boundType).AddImportToArray(thisClass);
  34. }
  35. }
  36. public void setName() {
  37. this.name = "POINTER TO " + this.boundType.name;
  38. }
  39. /** Write a pointer type definition to the typelist section of a symbol file.
  40. * <p>
  41. * A pointer type declaration consists of only an array marker
  42. * followed by the type-ordinal of the bound type.
  43. *
  44. * @param out the symbol file output stream
  45. * @param thisPack the package which this symbol file describes
  46. * @throws IOException
  47. */
  48. @Override
  49. public void writeType(DataOutputStream out, PackageDesc thisPack)
  50. throws IOException {
  51. out.writeByte(SymbolFile.ptrSy);
  52. SymbolFile.writeTypeOrd(out,this.boundType);
  53. }
  54. }