ClassDesc.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. /**********************************************************************/
  2. /* Class 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.*;
  8. import java.util.ArrayList;
  9. import java.util.HashMap;
  10. import java.util.Iterator;
  11. public class ClassDesc extends TypeDesc {
  12. // private static final int MAJOR_VERSION = 45;
  13. // private static final int MINOR_VERSION = 3;
  14. private static HashMap<String,ClassDesc> classMap = new HashMap<>();
  15. private static final String jlString = "java.lang.String";
  16. private static final String jlObject = "java.lang.Object";
  17. private static final int noAtt = 0; // no record attribute in cp
  18. private static final int absR = 1; // ABSTRACT record in cp
  19. private static final int limR = 2; // LIMITED record in cp
  20. // No equivalent in java!
  21. private static final int extR = 3; // EXTENSIBLE record in cp
  22. private static final int iFace = 4; // JAVA interface
  23. public static boolean useJar = false;
  24. public static boolean verbose = false;
  25. public static boolean VERBOSE = false;
  26. public static boolean summary = false;
  27. public static boolean nocpsym = false;
  28. @Override
  29. public String toString() {
  30. if (this.name != null)
  31. return this.name;
  32. else
  33. return "anon-ClassDesc";
  34. }
  35. ConstantPool cp;
  36. ClassDesc superClass;
  37. int access;
  38. int outBaseTypeNum=0;
  39. int superNum=0;
  40. int numInts=0;
  41. int intNums[];
  42. public String
  43. /**
  44. * Qualified name of the class e.g. java/lang/Object
  45. */
  46. qualName,
  47. /**
  48. * Java language name of the class e.g. java.lang.Object
  49. */
  50. javaName,
  51. /**
  52. * Unqualified name of the class e.g. Object
  53. */
  54. objName;
  55. ClassDesc[] interfaces;
  56. boolean
  57. isInterface = false,
  58. read = false,
  59. done = false;
  60. public boolean hasNoArgConstructor = false;
  61. /**
  62. * Packages imported by this class
  63. */
  64. public ArrayList<PackageDesc> imports = new ArrayList<>();
  65. /**
  66. * Fields declared in this class
  67. */
  68. public ArrayList<FieldInfo> fieldList = new ArrayList<>();
  69. /**
  70. * Methods defined in this class
  71. */
  72. public ArrayList<MethodInfo> methodList = new ArrayList<>();
  73. /**
  74. * HashMap of members declared locally in this class.
  75. */
  76. HashMap<String,MemberInfo> scope = new HashMap<>();
  77. public ClassDesc() {
  78. typeOrd = TypeDesc.classT;
  79. }
  80. /**
  81. * Find an existing ClassDescriptor object with the given
  82. * string name, or create one in the supplied package.
  83. * <p>
  84. * If the pack parameter is null, the package is found (or
  85. * created) based on the prefix of the string class name.
  86. * @param name the full name of the class
  87. * @param pack the package descriptor, or null if not known
  88. * @return the (possibly newly created) class descriptor
  89. */
  90. public static ClassDesc GetClassDesc(String name, PackageDesc pack) {
  91. if (name.indexOf(Util.JAVADOT) != -1) {
  92. name = name.replace(Util.JAVADOT,Util.FWDSLSH);
  93. }
  94. ClassDesc aClass = (ClassDesc)classMap.get(name);
  95. if (aClass == null) {
  96. aClass = ClassDesc.MakeNewClassDesc(name,pack);
  97. }
  98. return aClass;
  99. }
  100. /**
  101. * Create a new class descriptor with the given name, and added to
  102. * the given package descriptor.
  103. * <p>
  104. * If the pack parameter is null, create a new package descriptor
  105. * with a name inferred from the full class name, add the new package
  106. * to the package list, add the new class to the new package.
  107. * @param name the full name of the new class
  108. * @param pack the package to which the new class belongs, or null
  109. * @return the newly created class descriptor.
  110. */
  111. public static ClassDesc MakeNewClassDesc(String name, PackageDesc pack) {
  112. ClassDesc desc = new ClassDesc(name, pack);
  113. desc.MakeJavaName();
  114. classMap.put(desc.qualName, desc);
  115. return desc;
  116. }
  117. private ClassDesc(String thisName, PackageDesc pack) {
  118. this.typeOrd = TypeDesc.classT;
  119. this.qualName = thisName;
  120. if (pack == null) {
  121. this.parentPkg = PackageDesc.getClassPackage(this.qualName);
  122. } else {
  123. this.parentPkg = pack;
  124. }
  125. }
  126. public ClassDesc(int inNum) { this.inBaseTypeNum = inNum; }
  127. @Override
  128. public String getTypeMnemonic() {
  129. switch (javaName) {
  130. case jlString:
  131. return "S";
  132. case jlObject:
  133. return "O";
  134. default:
  135. return "o";
  136. }
  137. }
  138. /**
  139. * Read the details of the class.
  140. * <p>
  141. * Parse the class file attached to the DataInputStream,
  142. * creating new type, class and package descriptors for newly
  143. * identified type names.
  144. * @param stream The input data stream. Could be either
  145. * a FileStream or a zip stream from a jar file.
  146. * @return true if parse was successful.
  147. * @throws IOException
  148. */
  149. private boolean ReadClassFileDetails(DataInputStream stream)
  150. throws IOException {
  151. read = true;
  152. int count;
  153. ClassRef tmp;
  154. /* read and check the magic number */
  155. if (stream.readInt() != 0xCAFEBABE) {
  156. System.out.println("Bad magic number");
  157. System.exit(0);
  158. }
  159. /* read and check the minor and major version numbers */
  160. int minorVersion = stream.readUnsignedShort();
  161. // /* if (minorVersion > MINOR_VERSION) {
  162. // System.out.println("Unsupported Java minor version " +
  163. // String.valueOf(minorVersion));
  164. // System.exit(0);
  165. // }
  166. //*/
  167. int majorVersion = stream.readUnsignedShort();
  168. // /* if (majorVersion != MAJOR_VERSION) {
  169. // System.out.println("Unsupported Java major version " +
  170. // String.valueOf(majorVersion));
  171. // System.exit(0);
  172. // }
  173. //*/
  174. cp = new ConstantPool(stream);
  175. access = stream.readUnsignedShort();
  176. // Experimental code to only transform packages that
  177. // are reachable from classes that are not private.
  178. // Under consideration for next version, controlled
  179. // by a command line option.
  180. PackageDesc.tot++;
  181. if (!ConstantPool.isPublic(access) && !ConstantPool.isProtected(access)) {
  182. cp.EmptyConstantPool();
  183. PackageDesc.pub++;
  184. return true;
  185. }
  186. // End experimental code
  187. String clName = ((ClassRef) cp.Get(stream.readUnsignedShort())).GetName();
  188. if (!qualName.equals(clName)) {
  189. if (clName.startsWith(parentPkg.name)) {
  190. if (verbose) { System.out.println(clName + " IS PART OF PACKAGE " +
  191. parentPkg.name + " but name is not "
  192. + qualName); }
  193. } else {
  194. System.err.println(clName + " IS NOT PART OF PACKAGE " +
  195. parentPkg.name + " qualName = " + qualName);
  196. parentPkg = PackageDesc.getClassPackage(qualName);
  197. return false;
  198. }
  199. classMap.remove(qualName);
  200. qualName = clName;
  201. this.MakeJavaName();
  202. ClassDesc put = classMap.put(qualName,this);
  203. }
  204. isInterface = ConstantPool.isInterface(access);
  205. if (this.isInterface && (access & 1) != 1)
  206. throw new IOException("interface not public");
  207. int superIx = stream.readUnsignedShort();
  208. if (superIx > 0) {
  209. tmp = (ClassRef) cp.Get(superIx);
  210. superClass = tmp.GetClassDesc();
  211. //
  212. // If superclass is not from the current package
  213. // mark the superclass package as needed for API.
  214. //
  215. if (superClass.parentPkg != this.parentPkg) {
  216. //superClass.parentPkg.set(Util.APINEEDS);
  217. superClass.blame = this;
  218. this.AddImportToClass(superClass);
  219. }
  220. }
  221. /* get the interfaces implemented by this class */
  222. count = stream.readUnsignedShort();
  223. interfaces = new ClassDesc[count];
  224. for (int i = 0; i < count; i++) {
  225. tmp = (ClassRef) cp.Get(stream.readUnsignedShort());
  226. ClassDesc theInterface = tmp.GetClassDesc();
  227. //theInterface.parentPkg.set(Util.APINEEDS);
  228. this.AddImportToClass(theInterface);
  229. interfaces[i] = theInterface;
  230. }
  231. /* get the fields for this class */
  232. count = stream.readUnsignedShort();
  233. if (verbose)
  234. System.out.println(count != 1 ?
  235. "There are " + count + " fields" :
  236. "There is one field");
  237. for (int i = 0; i < count; i++ ) {
  238. FieldInfo fInfo = new FieldInfo(cp,stream,this);
  239. //
  240. // The package to which this class belongs
  241. // must place the package of this field's type
  242. // on the import list IFF:
  243. // * the field is public or protected AND
  244. // * the field's package is not that of thisClass
  245. //
  246. if (fInfo.isExported()) {
  247. this.fieldList.add(fInfo);
  248. if (fInfo.type.parentPkg != this.parentPkg) {
  249. fInfo.type.blame = fInfo;
  250. this.TryImport(fInfo.type);
  251. }
  252. }
  253. }
  254. /* get the methods for this class */
  255. count = stream.readUnsignedShort();
  256. if (verbose)
  257. System.out.println(count != 1 ?
  258. "There are " + count + " methods" :
  259. "There is one method");
  260. for (int i = 0; i < count; i++ ) {
  261. MethodInfo mInfo = new MethodInfo(cp,stream,this);
  262. if (mInfo.isExported())
  263. this.methodList.add(mInfo);
  264. }
  265. /* ignore the rest of the classfile (ie. the attributes) */
  266. if (verbose) { System.out.println("Finished reading class file"); }
  267. if (VERBOSE) { /*PrintClassFile();*/ Diag(); }
  268. this.AddImportToParentImports();
  269. cp.EmptyConstantPool();
  270. cp = null;
  271. return true;
  272. }
  273. public void TryImport(TypeDesc type){
  274. if (type instanceof ClassDesc) {
  275. this.AddImportToClass((ClassDesc)type);
  276. }
  277. else if (type instanceof ArrayDesc) {
  278. ((ArrayDesc)type).elemType.blame = type.blame;
  279. this.TryImport(((ArrayDesc)type).elemType); // Recursive!
  280. }
  281. else if (type instanceof PtrDesc) {
  282. ((PtrDesc)type).AddImportToPtr(this);
  283. }
  284. }
  285. public void AddImportToClass(ClassDesc aClass) {
  286. if ((aClass != this) && (aClass.parentPkg != this.parentPkg) &&
  287. (!this.imports.contains(aClass.parentPkg))) {
  288. aClass.parentPkg.set(Util.APINEEDS);
  289. this.imports.add(aClass.parentPkg);
  290. aClass.parentPkg.blame = aClass.blame;
  291. /*
  292. if (aClass.parentPkg.cpName.contains("sun"))
  293. System.err.println(aClass.parentPkg.cpName);
  294. */
  295. }
  296. }
  297. public void AddImportToParentImports() {
  298. PackageDesc myPkg = this.parentPkg;
  299. for (PackageDesc pkg : this.imports) {
  300. if (!myPkg.pkgImports.contains(pkg)) {
  301. myPkg.pkgImports.add(pkg);// pkg should have been already blamed?
  302. if (VERBOSE)
  303. System.out.printf(
  304. "Adding %s to import list of package %s, blame %s\n",
  305. pkg.name, myPkg.name,
  306. pkg.blameStr());
  307. //pkg.blame == null? "null" : pkg.blame.toString());
  308. }
  309. }
  310. }
  311. public boolean ReadPkgClassFile(File cFile) throws IOException {
  312. boolean result;
  313. try (DataInputStream in = new DataInputStream(new FileInputStream(cFile))) {
  314. if (verbose) {
  315. System.out.println("Reading Pkg Class File <"+this.javaName+">");
  316. }
  317. this.parentPkg.set(Util.CURRENT);
  318. result = this.ReadClassFileDetails(in);
  319. if (result)
  320. this.parentPkg.set(Util.FROMCLS);
  321. }
  322. return result;
  323. }
  324. public boolean ReadJarClassFile(InputStream stream) throws IOException {
  325. boolean result;
  326. try (DataInputStream in = new DataInputStream(stream)) {
  327. if (verbose) {
  328. System.out.println("Reading Jar Class File <"+qualName+">");
  329. }
  330. this.parentPkg.set(Util.CURRENT);
  331. result = this.ReadClassFileDetails(in);
  332. if (result)
  333. this.parentPkg.set(Util.FROMJAR);
  334. this.parentPkg.clear(Util.CURRENT);
  335. }
  336. return result;
  337. }
  338. public void PrintClassFile() {
  339. int i;
  340. System.out.println("ClassFile for " + qualName);
  341. cp.PrintConstantPool();
  342. System.out.print("THIS CLASS = ");
  343. System.out.print(ConstantPool.GetAccessString(access));
  344. System.out.println(qualName);
  345. if (superClass != null) {
  346. System.out.println("SUPERCLASS = " + superClass.qualName);
  347. }
  348. System.out.println("INTERFACES IMPLEMENTED");
  349. for (i = 0; i < interfaces.length; i++) {
  350. System.out.println(" " + interfaces[i].qualName);
  351. }
  352. System.out.println("FIELDS");
  353. this.fieldList.forEach((fInfo) -> {
  354. System.out.println(" " + fInfo.toString() + ";");
  355. });
  356. System.out.println("METHODS");
  357. this.methodList.forEach((mInfo) -> {
  358. System.out.println(" " + mInfo.toString());
  359. });
  360. System.out.println();
  361. }
  362. public void Diag() {
  363. System.out.println("CLASSDESC");
  364. System.out.println("name = " + name);
  365. System.out.println("javaName = " + javaName);
  366. System.out.println("qualName = " + qualName);
  367. System.out.println();
  368. }
  369. private static void AddField(FieldInfo f,HashMap<String,MemberInfo> scope) throws IOException {
  370. int fNo = 1;
  371. String origName = f.name;
  372. while (scope.containsKey(f.name)) {
  373. f.name = origName + String.valueOf(fNo);
  374. fNo++;
  375. }
  376. scope.put(f.name,f);
  377. }
  378. private static void MakeMethodName(MethodInfo meth) {
  379. if (meth.isInitProc) {
  380. meth.userName = "Init";
  381. } else {
  382. meth.userName = meth.name;
  383. }
  384. }
  385. private static void AddMethod(MethodInfo meth, HashMap<String,MemberInfo> scope)
  386. throws IOException {
  387. int methNo = 1;
  388. if (meth.userName == null) { MakeMethodName(meth); }
  389. String origName = meth.userName;
  390. while (scope.containsKey(meth.userName)) {
  391. meth.userName = origName + String.valueOf(methNo);
  392. methNo++;
  393. }
  394. scope.put(meth.userName,meth);
  395. }
  396. public void MakeJavaName() {
  397. this.javaName = qualName.replace(Util.FWDSLSH,Util.JAVADOT); // '/' --> '.'
  398. this.objName = javaName.substring(javaName.lastIndexOf(Util.JAVADOT)+1);
  399. this.name = javaName.replace(Util.JAVADOT,Util.LOWLINE); // '.' --> '_'
  400. }
  401. private void AddInterfaceImports(ClassDesc aClass) {
  402. // if (interfaces.length > 0) {
  403. if (interfaces != null && interfaces.length > 0) {
  404. for (ClassDesc intf : interfaces) {
  405. aClass.AddImportToClass(intf);
  406. intf.AddInterfaceImports(aClass);
  407. }
  408. }
  409. }
  410. public void GetSuperImports() {
  411. if (done) {
  412. return;
  413. }
  414. if (verbose) {
  415. System.out.println("GetSuperImports of " + javaName);
  416. }
  417. if (isInterface) {
  418. AddInterfaceImports(this);
  419. }
  420. if (this.superClass != null) {
  421. if (!this.superClass.done) {
  422. this.superClass.GetSuperImports();
  423. }
  424. }
  425. if (this.methodList.size() > 0) { // guard added
  426. for (MethodInfo mth : methodList) {
  427. MakeMethodName(mth);
  428. if (mth.isExported() && !mth.deprecated) {
  429. if ((!mth.isInitProc) && (!mth.isStatic())) {
  430. MethodInfo meth = GetOverridden(mth, mth.owner);
  431. if (meth != null) {
  432. mth.overridding = true;
  433. }
  434. }
  435. }
  436. }
  437. }
  438. done = true;
  439. }
  440. public void GetSuperFields(HashMap jScope) throws IOException {
  441. if (done) { return; }
  442. if (verbose) {
  443. System.out.println("GetSuperFields of " + this.javaName);
  444. }
  445. if (this.isInterface) {
  446. this.AddInterfaceImports(this);
  447. }
  448. if (this.superClass != null) {
  449. if (!this.superClass.done) {
  450. this.superClass.GetSuperFields(jScope); }
  451. Iterator<String> enum1 = superClass.scope.keySet().iterator();
  452. while (enum1.hasNext()) {
  453. String methName = (String)enum1.next();
  454. this.scope.put(methName, this.superClass.scope.get(methName));
  455. }
  456. }
  457. for (FieldInfo f : this.fieldList) {
  458. if (f.isExported()) {
  459. AddField((FieldInfo)f,scope);
  460. }
  461. }
  462. HashMap<String,MemberInfo> superScope = new HashMap<>();
  463. for (MethodInfo mth : this.methodList) {
  464. this.MakeMethodName(mth);
  465. if (mth.isExported() && !mth.deprecated) {
  466. if (mth.isInitProc) {
  467. AddMethod(mth,superScope);
  468. } else if (mth.isStatic()) {
  469. AddMethod(mth,scope);
  470. } else {
  471. if (this.scope.containsKey(mth.userName)) {
  472. MethodInfo meth = GetOverridden(mth,mth.owner);
  473. if (meth != null) {
  474. mth.overridding = true;
  475. mth.userName = meth.userName;
  476. this.scope.remove(mth.userName);
  477. this.scope.put(mth.userName,mth);
  478. } else {
  479. AddMethod(mth,this.scope);
  480. }
  481. } else {
  482. AddMethod(mth,this.scope);
  483. }
  484. }
  485. }
  486. }
  487. done = true;
  488. }
  489. private static MethodInfo GetOverridden(MethodInfo meth,ClassDesc thisClass) {
  490. ClassDesc aClass = thisClass;
  491. while (aClass.superClass != null) {
  492. aClass = aClass.superClass;
  493. if (aClass.methodList.isEmpty()) { // new guard
  494. for (MethodInfo method : aClass.methodList) {
  495. if (method.name.equals(meth.name)) {
  496. if ((method.signature != null) && (meth.signature != null)) {
  497. if (method.signature.equals(meth.signature)) {
  498. return method;
  499. }
  500. } else if (method.parTypes.length == meth.parTypes.length) {
  501. boolean ok = true;
  502. for (int j = 0; (j < method.parTypes.length) & ok; j++) {
  503. ok = method.parTypes[j] == meth.parTypes[j];
  504. }
  505. if (ok) {
  506. return method;
  507. }
  508. }
  509. }
  510. }
  511. }
  512. }
  513. return null;
  514. }
  515. public void CheckAccess() {
  516. if (ConstantPool.isAbstract(access)) {
  517. System.out.println(" is abstract ");
  518. } else if (ConstantPool.isFinal(access)) {
  519. System.out.println(" is final ");
  520. } else {
  521. System.out.println(" is default");
  522. }
  523. }
  524. public void setRecAtt(int recAtt) {
  525. if (recAtt >= 8) { recAtt -= 8; } else { hasNoArgConstructor = true; }
  526. if (recAtt == absR) {
  527. if (!ConstantPool.isAbstract(access)) {
  528. access = access + ConstantPool.ACC_ABSTRACT;
  529. }
  530. } else if (recAtt == noAtt) {
  531. if (!ConstantPool.isFinal(access)) {
  532. access = access + ConstantPool.ACC_FINAL;
  533. }
  534. }
  535. }
  536. /** Write a class definition to the typelist section of a symbol file
  537. * <p>
  538. * If the <code>writeDetails</code> flag is not true, or the
  539. * class belongs to a different package, then only the type
  540. * ordinal is written. Otherwise a full class API is emitted.
  541. *
  542. * @param out the symbol file output stream
  543. * @param thisPack the package which this symbol file describes
  544. * @throws IOException
  545. */
  546. @Override
  547. public void writeType(DataOutputStream out, PackageDesc thisPack)
  548. throws IOException {
  549. if (objName == null) {
  550. this.MakeJavaName();
  551. }
  552. if (this.parentPkg != thisPack) {
  553. out.writeByte(SymbolFile.fromS);
  554. // Diagnostic error message
  555. if (this.parentPkg.impNum < 0) {
  556. System.err.println("thisPack is " + thisPack.javaName);
  557. System.err.println("impNum is " + this.parentPkg.impNum);
  558. System.err.println("packageDesc " + this.parentPkg.javaName);
  559. System.err.println("objName " + objName);
  560. this.parentPkg.impNum = 0;
  561. }
  562. //
  563. SymbolFile.writeOrd(out, this.parentPkg.impNum);
  564. SymbolFile.writeName(out, access, objName);
  565. } else if (!ConstantPool.isPublic(access)) {
  566. out.writeByte(SymbolFile.fromS);
  567. SymbolFile.writeOrd(out, 0);
  568. SymbolFile.writeName(out, access, objName);
  569. }
  570. if (!this.writeDetails || (this.parentPkg != thisPack)) {
  571. return;
  572. }
  573. out.writeByte(SymbolFile.ptrSy);
  574. SymbolFile.writeOrd(out, outBaseTypeNum);
  575. out.writeByte(SymbolFile.tDefS);
  576. SymbolFile.writeOrd(out, outBaseTypeNum);
  577. out.writeByte(SymbolFile.recSy);
  578. int recAtt = 0;
  579. if (!hasNoArgConstructor) {
  580. recAtt = 8;
  581. }
  582. if (ConstantPool.isFinal(access)) {
  583. out.writeByte(noAtt + recAtt);
  584. } else if (isInterface) {
  585. out.writeByte(iFace + recAtt);
  586. } else if (ConstantPool.isAbstract(access)) {
  587. out.writeByte(absR + recAtt);
  588. } else {
  589. out.writeByte(extR + recAtt);
  590. }
  591. if (isInterface) {
  592. out.writeByte(SymbolFile.truSy);
  593. } else {
  594. out.writeByte(SymbolFile.falSy);
  595. }
  596. if (superClass != null) {
  597. out.writeByte(SymbolFile.basSy);
  598. SymbolFile.writeTypeOrd(out, superClass);
  599. }
  600. //if (interfaces.length > 0) {
  601. if (interfaces != null && interfaces.length > 0) {
  602. out.writeByte(SymbolFile.iFcSy);
  603. for (ClassDesc intf : interfaces) {
  604. out.writeByte(SymbolFile.basSy);
  605. SymbolFile.writeTypeOrd(out, intf);
  606. }
  607. }
  608. if (!this.fieldList.isEmpty()) {
  609. for (FieldInfo field : this.fieldList) {
  610. if (field.isExported() && !field.isStatic()) {
  611. SymbolFile.writeName(out, field.accessFlags, field.name);
  612. SymbolFile.writeTypeOrd(out, field.type);
  613. }
  614. }
  615. }
  616. if (!this.methodList.isEmpty()) {
  617. for (MethodInfo method : this.methodList) {
  618. if (method.isExported() && !method.deprecated
  619. && !method.isStatic() && !method.isInitProc
  620. && !method.isCLInitProc) {
  621. out.writeByte(SymbolFile.mthSy);
  622. // --------------------
  623. // if (methods[i].userName == null) {
  624. // System.out.println("packageDesc " + this.packageDesc.javaName);
  625. // System.out.println("objName " + objName);
  626. // for (int j=0; j < methods.length; j++) {
  627. // System.out.println("Method " + j +
  628. // (methods[i].userName == null ? " null" : methods[j].userName));
  629. // }
  630. // }
  631. // --------------------
  632. SymbolFile.writeName(out, method.accessFlags, method.userName);
  633. int attr = 0;
  634. if (!method.overridding) {
  635. attr = 1;
  636. }
  637. if (method.isAbstract()) {
  638. attr += 2;
  639. } else if (!method.isFinal()) {
  640. attr += 6;
  641. }
  642. out.writeByte(attr);
  643. out.writeByte(0);
  644. /* all java receivers are value mode */
  645. SymbolFile.writeOrd(out, outTypeNum);
  646. SymbolFile.writeString(out, method.name);
  647. SymbolFile.WriteFormalType(method, out);
  648. }
  649. }
  650. }
  651. if (!this.fieldList.isEmpty()) {
  652. for (FieldInfo field : this.fieldList) {
  653. if (field.isConstant()) {
  654. out.writeByte(SymbolFile.conSy);
  655. SymbolFile.writeName(out, field.accessFlags, field.name);
  656. SymbolFile.writeLiteral(out, field.GetConstVal());
  657. } else if (field.isExported() && field.isStatic()) {
  658. out.writeByte(SymbolFile.varSy);
  659. SymbolFile.writeName(out, field.accessFlags, field.name);
  660. SymbolFile.writeTypeOrd(out, field.type);
  661. }
  662. }
  663. }
  664. if (!this.methodList.isEmpty()) {
  665. for (MethodInfo method : this.methodList) {
  666. if (method.isExported() && !method.deprecated
  667. && method.isStatic() && !method.isCLInitProc) {
  668. out.writeByte(SymbolFile.prcSy);
  669. SymbolFile.writeName(out, method.accessFlags, method.userName);
  670. SymbolFile.writeString(out, method.name);
  671. if (method.isInitProc) {
  672. out.writeByte(SymbolFile.truSy);
  673. }
  674. SymbolFile.WriteFormalType(method, out);
  675. }
  676. }
  677. }
  678. out.writeByte(SymbolFile.endRc);
  679. }
  680. }