PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/SN-NG3/snavigator/parsers/cobol/deftab.c

https://gitlab.com/OpenSourceMirror/sourcenav
C | 870 lines | 739 code | 79 blank | 52 comment | 154 complexity | a3093c5fb34af5264001eae97138677a MD5 | raw file
  1. /*
  2. Copyright (c) 2000, Red Hat, Inc.
  3. This file is part of Source-Navigator.
  4. Source-Navigator is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. Source-Navigator 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 GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with Source-Navigator; see the file COPYING. If not, write to
  14. the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
  15. MA 02111-1307, USA.
  16. */
  17. /* Ich, Doktor Josef Grosch, Informatiker, Dez. 1996 */
  18. #include <string.h>
  19. #include "def.h"
  20. #include "deftab.h"
  21. #include "rMemory.h"
  22. #include "Errors.h"
  23. #include "StringM.h"
  24. #include "keywords.h"
  25. #include "cobol.h"
  26. #include "sn.h"
  27. #define null (char *) NULL
  28. #define attr (unsigned long) PAF_PUBLIC
  29. static char * section_name [] = { 0,
  30. "CONFIGURATION_SECTION",
  31. "INPUT-OUTPUT_SECTION",
  32. "FILE_SECTION",
  33. "WORKING-STORAGE_SECTION",
  34. "LOCAL-STORAGE_SECTION",
  35. "LINKAGE_SECTION",
  36. "COMMUNICATION_SECTION",
  37. "REPORT_SECTION",
  38. "SCREEN_SECTION",
  39. 0,
  40. 0,
  41. 0,
  42. 0,
  43. 0,
  44. 0,
  45. 0,
  46. 0,
  47. 0,
  48. 0,
  49. 0,
  50. "IDENTIFICATION_DIVISION",
  51. "ENVIRONMENT_DIVISION",
  52. "DATA_DIVISION",
  53. "PROCEDURE_DIVISION",
  54. };
  55. typedef struct {
  56. char level ;
  57. tpdecl * decls ;
  58. } tstack;
  59. char Section = 0;
  60. rbool NameCheck = rfalse;
  61. int acc = PAF_REF_READ;
  62. extern int error_count ;
  63. static tpdecl decls = NULL; /* declared data */
  64. static tpuse forwards = NULL; /* used data */
  65. static tpdecl sections = NULL; /* declared labels */
  66. static tplabel labels = NULL; /* used labels */
  67. static tpdecl stack_2 [52] ;
  68. static tstack stack [52] = {{01, & decls}};
  69. static int stack_ptr = 0;
  70. static int cur_level = 01;
  71. static tpdecl field [52] ;
  72. static int field_ptr = 0;
  73. static tpdecl cpl_dcl [52] ;
  74. static int cpl_dcl_ptr = 0;
  75. static tpdecl cpl_use [52] ;
  76. static int cpl_use_ptr = 0;
  77. static char * current_ident, * current_class;
  78. static char * current_subr, * ref_class;
  79. static void Predef
  80. #if defined __STDC__ | defined __cplusplus
  81. (char * name, unsigned long mask)
  82. #else
  83. (name, mask) char * name; unsigned long mask;
  84. #endif
  85. {
  86. if (dialect & mask) {
  87. register tpdecl decl = (tpdecl) Alloc ((unsigned long) sizeof (tdecl));
  88. decl->position = NoPosition;
  89. decl->end_pos = NoPosition;
  90. decl->e_pos = NoPosition;
  91. decl->level = 01;
  92. decl->name = MakeIdent (name, strlen (name));
  93. decl->next = NULL;
  94. decl->fields = NULL;
  95. * stack [0].decls = decl;
  96. stack [0].decls = & decl->next;
  97. }
  98. }
  99. void BeginDeftab ARGS ((void))
  100. {
  101. decls = NULL; /* declared data */
  102. forwards = NULL; /* used data */
  103. sections = NULL; /* declared labels */
  104. labels = NULL; /* used labels */
  105. stack [0].level = 01;
  106. stack [0].decls = & decls;
  107. stack_ptr = 0;
  108. cur_level = 01;
  109. field_ptr = 0;
  110. cpl_dcl_ptr = 0;
  111. cpl_use_ptr = 0;
  112. /*
  113. Predef ("PRINTER" , all);
  114. Predef ("PRINTER-1" , all);
  115. Predef ("CONSOLE" , all);
  116. #include "predef.c"
  117. */
  118. }
  119. static void WriteDecls
  120. #if defined __STDC__ | defined __cplusplus
  121. (register tpdecl decls, int k)
  122. #else
  123. (decls, k) register tpdecl decls; int k;
  124. #endif
  125. {
  126. register int i;
  127. for (; decls; decls = decls->next) {
  128. WritePosition (stdout, decls->position);
  129. for (i = 1; i <= k; i ++) (void) printf (" ");
  130. (void) printf (" %02d ", decls->level);
  131. WriteIdent (stdout, decls->name);
  132. (void) printf ("\n");
  133. WriteDecls (decls->fields, k + 1);
  134. }
  135. }
  136. static void WriteForwards
  137. #if defined __STDC__ | defined __cplusplus
  138. (register tpuse forwards, int k)
  139. #else
  140. (forwards, k) register tpuse forwards; int k;
  141. #endif
  142. {
  143. register int i;
  144. for (; forwards; forwards = forwards->next) {
  145. WritePosition (stdout, forwards->position);
  146. for (i = 0; i <= k; i ++) (void) printf (" ");
  147. WriteIdent (stdout, forwards->name);
  148. (void) printf ("\n");
  149. WriteForwards (forwards->fields, k + 1);
  150. }
  151. }
  152. static void WriteSections
  153. #if defined __STDC__ | defined __cplusplus
  154. (register tpdecl sections, int k)
  155. #else
  156. (sections, k) register tpdecl sections; int k;
  157. #endif
  158. {
  159. register int i;
  160. for (; sections; sections = sections->next) {
  161. WritePosition (stdout, sections->position);
  162. (void) printf (" ");
  163. sections->end_pos.FileName = NoIdent;
  164. WritePosition (stdout, sections->end_pos);
  165. (void) printf (" ");
  166. sections->e_pos.FileName = NoIdent;
  167. WritePosition (stdout, sections->e_pos);
  168. for (i = 0; i <= k; i ++) (void) printf (" ");
  169. WriteIdent (stdout, sections->name);
  170. (void) printf ("\n");
  171. if (k == 0) WriteSections (sections->fields, 1);
  172. }
  173. }
  174. static void WriteLabels
  175. #if defined __STDC__ | defined __cplusplus
  176. (register tplabel labels)
  177. #else
  178. (labels) register tplabel labels;
  179. #endif
  180. {
  181. for (; labels; labels = labels->next) {
  182. WritePosition (stdout, labels->position);
  183. (void) printf (" ");
  184. WriteIdent (stdout, labels->name);
  185. (void) printf (" ");
  186. WriteIdent (stdout, labels->name2);
  187. (void) printf ("\n");
  188. }
  189. }
  190. void WriteDeftab ARGS ((void))
  191. {
  192. (void) printf ("decls\n"); WriteDecls (decls, 0);
  193. (void) printf ("forwards\n"); WriteForwards (forwards, 0);
  194. (void) printf ("sections\n"); WriteSections (sections, 0);
  195. (void) printf ("labels\n"); WriteLabels (labels);
  196. }
  197. /*
  198. */
  199. tpdecl Declare
  200. #if defined __STDC__ | defined __cplusplus
  201. (register int level, tScanAttribute Attribute, int Type, tPosition e_pos)
  202. #else
  203. (level, Attribute, Type, e_pos)
  204. register int level ;
  205. tScanAttribute Attribute ;
  206. int Type ;
  207. tPosition e_pos ;
  208. #endif
  209. {
  210. register tpdecl decl = (tpdecl) Alloc ((unsigned long) sizeof (tdecl));
  211. decl->position = Attribute.Position;
  212. decl->end_pos = Attribute.name.EPos;
  213. decl->e_pos = e_pos;
  214. decl->level = level;
  215. decl->name = Attribute.name.Ident;
  216. decl->next = NULL;
  217. decl->fields = NULL;
  218. switch (level) {
  219. case MN: /* mnemonic name of SPECIAL-NAMES */
  220. case CN: /* condition name of SPECIAL-NAMES */
  221. case FD:
  222. case SD:
  223. case CD:
  224. case RD: stack_ptr = 0; break;
  225. case 01: if (Section == cFILE_SCT || Section == cCOMM_SCT) {
  226. if (stack_ptr == 0) {
  227. stack [1].level = level;
  228. stack [1].decls = & cpl_dcl [1]->fields;
  229. }
  230. stack_ptr = 1;
  231. } else {
  232. stack_ptr = 0;
  233. }
  234. cur_level = level; break;
  235. case 66: if (Section == cFILE_SCT) {
  236. if (stack_ptr == 0) { /* if fields are missing: */
  237. stack [1].level = level; /* should not occur */
  238. stack [1].decls = & cpl_dcl [1]->fields;
  239. stack_ptr = 1;
  240. break;
  241. }
  242. if (stack_ptr == 1) {
  243. stack [2].level = level;
  244. stack [2].decls = & cpl_dcl [2]->fields;
  245. }
  246. stack_ptr = 2;
  247. } else {
  248. if (stack_ptr == 0) {
  249. stack [1].level = level;
  250. stack [1].decls = & cpl_dcl [1]->fields;
  251. }
  252. stack_ptr = 1;
  253. } break;
  254. case 77:
  255. case 78: stack_ptr = 0; break;
  256. case IB: /* INDEXED BY of data description */
  257. {
  258. tpdecl prev_cpl_dcl = cpl_dcl [1];
  259. int prev_cpl_dcl_ptr = cpl_dcl_ptr;
  260. * stack [0].decls = decl;
  261. stack [0].decls = & decl->next;
  262. cpl_dcl [cpl_dcl_ptr = 1] = decl;
  263. cpl_dcl [1] = prev_cpl_dcl;
  264. cpl_dcl_ptr = prev_cpl_dcl_ptr;
  265. return decl;
  266. }
  267. case 88:
  268. default: /* levels 02 - 49 */
  269. if (level < cur_level) {
  270. while (level < stack [-- stack_ptr].level);
  271. if (level > stack [stack_ptr].level)
  272. stack [++ stack_ptr].level = level;
  273. cur_level = level;
  274. } else if (level > cur_level) {
  275. if (cpl_dcl_ptr > 0) {
  276. stack_ptr ++;
  277. stack [stack_ptr].decls = & cpl_dcl [stack_ptr]->fields;
  278. }
  279. stack [stack_ptr].level = level;
  280. cur_level = level;
  281. }
  282. }
  283. * stack [stack_ptr].decls = decl;
  284. stack [stack_ptr].decls = & decl->next;
  285. cpl_dcl [cpl_dcl_ptr = stack_ptr + 1] = decl;
  286. return decl;
  287. }
  288. tpdecl DeclareLabel
  289. #if defined __STDC__ | defined __cplusplus
  290. (tScanAttribute Attribute, int Type, tPosition e_pos)
  291. #else
  292. (Attribute, Type, e_pos) tScanAttribute Attribute; int Type; tPosition e_pos;
  293. #endif
  294. {
  295. register tpdecl decl = (tpdecl) Alloc ((unsigned long) sizeof (tdecl));
  296. decl->position = Attribute.Position;
  297. decl->end_pos = Attribute.name.EPos;
  298. decl->e_pos = e_pos;
  299. decl->level = Type;
  300. decl->name = Attribute.name.Ident;
  301. if (Type == lSECTION || sections == NULL || sections->level != lSECTION) {
  302. decl->fields = NULL;
  303. decl->next = sections;
  304. sections = decl;
  305. cpl_dcl_ptr = 1;
  306. } else {
  307. decl->fields = sections;
  308. decl->next = sections->fields;
  309. sections->fields = decl;
  310. cpl_dcl_ptr = 2;
  311. }
  312. if (Type != lENTRY) current_subr = GetCStr (Attribute.name.Ident);
  313. return decl;
  314. }
  315. void DeclareEnd
  316. #if defined __STDC__ | defined __cplusplus
  317. (int Type, tPosition e_pos)
  318. #else
  319. (Type, e_pos) int Type; tPosition e_pos;
  320. #endif
  321. {
  322. register tpdecl decl = sections;
  323. while (decl->level == lENTRY) decl = decl->next;
  324. if (Type == lSECTION) {
  325. if (decl->level == lSECTION) decl->e_pos = e_pos;
  326. } else {
  327. if (decl->level == lSECTION) {
  328. decl = decl->fields;
  329. while (decl->level == lENTRY) decl = decl->next;
  330. }
  331. decl->e_pos = e_pos;
  332. }
  333. }
  334. tpdecl search_next
  335. #if defined __STDC__ | defined __cplusplus
  336. (register tIdent name, register tpdecl decls)
  337. #else
  338. (name, decls) register tIdent name; register tpdecl decls;
  339. #endif
  340. {
  341. while (decls) if (decls->name == name) return decls; else decls = decls->next;
  342. return NULL;
  343. }
  344. tpdecl search_all
  345. #if defined __STDC__ | defined __cplusplus
  346. (register tIdent name, register tpdecl decls, int nest)
  347. #else
  348. (name, decls, nest)
  349. register tIdent name ;
  350. register tpdecl decls ;
  351. int nest ;
  352. #endif
  353. {
  354. while (decls) {
  355. if (decls->name == name) return cpl_use [cpl_use_ptr = nest] = decls;
  356. if (decls->fields) {
  357. register tpdecl decl = search_all (name, decls->fields, nest + 1);
  358. if (decl) { cpl_use [nest] = decls; return decl; }
  359. }
  360. decls = decls->next;
  361. }
  362. return NULL;
  363. }
  364. void CloseForwards ARGS ((void))
  365. {
  366. tpuse forward = forwards;
  367. tpdecl decl;
  368. tpuse field;
  369. tScanAttribute Attribute;
  370. while (forward) {
  371. current_subr = section_name [forward->section];
  372. Attribute.name.Ident = forward->name;
  373. Attribute.Position = forward->position;
  374. Attribute.name.EPos = forward->end_pos;
  375. decl = UseName (Attribute);
  376. for (field = forward->fields; field && decl; field = field->fields) {
  377. Attribute.name.Ident = field->name;
  378. Attribute.Position = field->position;
  379. Attribute.name.EPos = field->end_pos;
  380. decl = UseField (Attribute, decl->fields);
  381. }
  382. forward = forward->next;
  383. }
  384. }
  385. tpdecl UseName
  386. #if defined __STDC__ | defined __cplusplus
  387. (tScanAttribute Attribute)
  388. #else
  389. (Attribute) tScanAttribute Attribute;
  390. #endif
  391. {
  392. tpdecl decl = search_next (Attribute.name.Ident, decls);
  393. if (decl) {
  394. field [field_ptr = 1] = cpl_use [cpl_use_ptr = 1] = decl;
  395. } else {
  396. decl = search_all (Attribute.name.Ident, decls, 1);
  397. if (decl) {
  398. field [field_ptr = 1] = decl;
  399. } else {
  400. int PrevSection = Section;
  401. Section = cWS_SCT;
  402. field [field_ptr = 1] =
  403. cpl_use [cpl_use_ptr = 1] = Declare (1, Attribute, oDATA, Attribute.name.EPos);
  404. Section = PrevSection;
  405. if (NameCheck) {
  406. MessageI ("name not declared", xxError, Attribute.Position, xxIdent, (char *) & Attribute.name.Ident);
  407. error_count ++;
  408. }
  409. }
  410. }
  411. if (cross_ref_fp) {
  412. if (cpl_use_ptr == 1) {
  413. put_cross_ref (PAF_REF_TO_GLOB_VAR, PAF_FUNC_DEF, PAF_REF_SCOPE_GLOBAL,
  414. null, current_subr, null, null, GetCStr (Attribute.name.Ident),
  415. null, current_file, (int) Attribute.Position.Line, acc);
  416. } else {
  417. ref_class = GetCStr (cpl_use [cpl_use_ptr - 1]->name);
  418. if (ref_class [0] == '\0') ref_class = "FILLER";
  419. put_cross_ref (PAF_REF_TO_MBR_VAR, PAF_FUNC_DEF, PAF_REF_SCOPE_GLOBAL,
  420. null, current_subr, null, ref_class, GetCStr (Attribute.name.Ident),
  421. null, current_file, (int) Attribute.Position.Line, acc);
  422. }
  423. }
  424. return decl;
  425. }
  426. tpdecl UseField
  427. #if defined __STDC__ | defined __cplusplus
  428. (tScanAttribute Attribute, tpdecl decls)
  429. #else
  430. (Attribute, decls) tScanAttribute Attribute; tpdecl decls;
  431. #endif
  432. {
  433. tpdecl decl = search_next (Attribute.name.Ident, decls);
  434. if (decl) {
  435. field [++ field_ptr] = cpl_use [++ cpl_use_ptr] = decl;
  436. } else {
  437. decl = search_all (Attribute.name.Ident, decls, cpl_use_ptr + 1);
  438. if (decl) {
  439. field [++ field_ptr] = decl;
  440. } else {
  441. if (NameCheck) {
  442. MessageI ("field not declared", xxError, Attribute.Position, xxIdent, (char *) & Attribute.name.Ident);
  443. error_count ++;
  444. }
  445. }
  446. }
  447. if (cross_ref_fp) {
  448. if (cpl_use_ptr == 1) {
  449. put_cross_ref (PAF_REF_TO_MBR_VAR, PAF_FUNC_DEF, PAF_REF_SCOPE_GLOBAL,
  450. null, current_subr, null, null, GetCStr (Attribute.name.Ident),
  451. null, current_file, (int) Attribute.Position.Line, acc);
  452. } else {
  453. ref_class = GetCStr (cpl_use [cpl_use_ptr - 1]->name);
  454. if (ref_class [0] == '\0') ref_class = "FILLER";
  455. put_cross_ref (PAF_REF_TO_MBR_VAR, PAF_FUNC_DEF, PAF_REF_SCOPE_GLOBAL,
  456. null, current_subr, null, ref_class, GetCStr (Attribute.name.Ident),
  457. null, current_file, (int) Attribute.Position.Line, acc);
  458. }
  459. }
  460. return decl;
  461. }
  462. void UseForward
  463. #if defined __STDC__ | defined __cplusplus
  464. (tScanAttribute Attribute)
  465. #else
  466. (Attribute) tScanAttribute Attribute;
  467. #endif
  468. {
  469. register tpuse use = (tpuse) Alloc ((unsigned long) sizeof (tuse));
  470. use->name = Attribute.name.Ident;
  471. use->position = Attribute.Position;
  472. use->end_pos = Attribute.name.EPos;
  473. use->next = forwards;
  474. use->fields = NULL;
  475. use->section = Section;
  476. forwards = use;
  477. }
  478. void UseFieldForward
  479. #if defined __STDC__ | defined __cplusplus
  480. (tScanAttribute Attribute)
  481. #else
  482. (Attribute) tScanAttribute Attribute;
  483. #endif
  484. {
  485. register tpuse p, use = (tpuse) Alloc ((unsigned long) sizeof (tuse));
  486. use->name = Attribute.name.Ident;
  487. use->position = Attribute.Position;
  488. use->end_pos = Attribute.name.EPos;
  489. use->next = NULL;
  490. use->fields = NULL;
  491. use->section = Section;
  492. forwards->position = Attribute.Position;
  493. for (p = forwards; p->fields != NULL; p = p->fields);
  494. p->fields = use;
  495. }
  496. void UseLabel
  497. #if defined __STDC__ | defined __cplusplus
  498. (tScanAttribute Attribute)
  499. #else
  500. (Attribute) tScanAttribute Attribute;
  501. #endif
  502. {
  503. register tplabel label = (tplabel) Alloc ((unsigned long) sizeof (tlabel));
  504. label->name = Attribute.name.Ident;
  505. label->name2 = NoIdent;
  506. label->scope = sections;
  507. label->position = Attribute.Position;
  508. label->end_pos = Attribute.name.EPos;
  509. label->next = labels;
  510. labels = label;
  511. if (cross_ref_fp) {
  512. put_cross_ref (PAF_REF_TO_FUNCTION, PAF_FUNC_DEF, PAF_REF_SCOPE_GLOBAL,
  513. null, current_subr, null, null, GetCStr (Attribute.name.Ident),
  514. null, current_file, (int) Attribute.Position.Line, acc);
  515. }
  516. }
  517. void UseLabel2
  518. #if defined __STDC__ | defined __cplusplus
  519. (tScanAttribute Attribute, tScanAttribute Attribute2)
  520. #else
  521. (Attribute, Attribute2) tScanAttribute Attribute; tScanAttribute Attribute2;
  522. #endif
  523. {
  524. UseLabel (Attribute);
  525. labels->name2 = Attribute2.name.Ident;
  526. if (cross_ref_fp) {
  527. put_cross_ref (PAF_REF_TO_FUNCTION, PAF_FUNC_DEF, PAF_REF_SCOPE_GLOBAL,
  528. null, current_subr, null, null, GetCStr (Attribute2.name.Ident),
  529. null, current_file, (int) Attribute2.Position.Line, acc);
  530. }
  531. }
  532. void UseLabelExtern
  533. #if defined __STDC__ | defined __cplusplus
  534. (tScanAttribute Attribute)
  535. #else
  536. (Attribute) tScanAttribute Attribute;
  537. #endif
  538. {
  539. if (cross_ref_fp) {
  540. put_cross_ref (PAF_REF_TO_FUNCTION, PAF_FUNC_DEF, PAF_REF_SCOPE_GLOBAL,
  541. null, current_subr, null, null, GetCStr (Attribute.name.Ident),
  542. null, current_file, (int) Attribute.Position.Line, acc);
  543. }
  544. }
  545. tpdecl search_next_label
  546. #if defined __STDC__ | defined __cplusplus
  547. (register tIdent name, register tpdecl decls)
  548. #else
  549. (name, decls) register tIdent name; register tpdecl decls;
  550. #endif
  551. {
  552. while (decls) if (decls->name == name) return decls; else decls = decls->next;
  553. return NULL;
  554. }
  555. tpdecl search_all_label
  556. #if defined __STDC__ | defined __cplusplus
  557. (register tIdent name, register tpdecl decls)
  558. #else
  559. (name, decls) register tIdent name; register tpdecl decls;
  560. #endif
  561. {
  562. register tpdecl decl;
  563. while (decls) {
  564. if (decls->name == name) return decls;
  565. decl = search_next_label (name, decls->fields);
  566. if (decl) return decl;
  567. decls = decls->next;
  568. }
  569. return NULL;
  570. }
  571. void CloseLabels ARGS ((void))
  572. {
  573. tplabel label = labels;
  574. register tpdecl decl, decl2;
  575. if (! NameCheck) return;
  576. while (label) {
  577. if (label->name2 == NoIdent) {
  578. decl = search_next_label (label->name, label->scope);
  579. if (! decl) decl = search_all_label (label->name, sections);
  580. if (decl) {
  581. field_ptr = 1;
  582. field [1] = decl;
  583. if (decl->level == lPARAGRPH && decl->fields != NULL) {
  584. cpl_use_ptr = 2;
  585. cpl_use [1] = decl->fields;
  586. cpl_use [2] = decl;
  587. } else {
  588. cpl_use_ptr = 1;
  589. cpl_use [1] = decl;
  590. }
  591. } else {
  592. MessageI ("label not declared", xxError, label->position, xxIdent, (char *) & label->name);
  593. error_count ++;
  594. }
  595. } else {
  596. decl = search_next_label (label->name2, sections);
  597. if (decl && decl->level == lSECTION) {
  598. decl2 = search_next_label (label->name, decl->fields);
  599. if (decl2) {
  600. field_ptr = cpl_use_ptr = 2;
  601. field [1] = cpl_use [1] = decl;
  602. field [2] = cpl_use [2] = decl2;
  603. } else {
  604. MessageI ("paragraph not declared", xxError, label->position, xxIdent, (char *) & label->name);
  605. error_count ++;
  606. }
  607. } else {
  608. MessageI ("section not declared", xxError, label->position, xxIdent, (char *) & label->name2);
  609. error_count ++;
  610. }
  611. }
  612. label = label->next;
  613. }
  614. }
  615. void CloseDeftab ARGS ((void))
  616. {
  617. CloseForwards ();
  618. CloseLabels ();
  619. /* WriteDeftab (); */
  620. }
  621. static void ReleaseDecls
  622. #if defined __STDC__ | defined __cplusplus
  623. (register tpdecl decls)
  624. #else
  625. (decls) register tpdecl decls;
  626. #endif
  627. {
  628. while (decls) {
  629. tpdecl next = decls->next;
  630. ReleaseDecls (decls->fields);
  631. Free ((unsigned long) sizeof (tdecl), (char *) decls);
  632. decls = next;
  633. }
  634. }
  635. static void ReleaseForwards
  636. #if defined __STDC__ | defined __cplusplus
  637. (register tpuse forwards)
  638. #else
  639. (forwards) register tpuse forwards;
  640. #endif
  641. {
  642. while (forwards) {
  643. tpuse next = forwards->next;
  644. ReleaseForwards (forwards->fields);
  645. Free ((unsigned long) sizeof (tuse), (char *) forwards);
  646. forwards = next;
  647. }
  648. }
  649. static void ReleaseSections
  650. #if defined __STDC__ | defined __cplusplus
  651. (register tpdecl sections, int k)
  652. #else
  653. (sections, k) register tpdecl sections; int k;
  654. #endif
  655. {
  656. while (sections) {
  657. tpdecl next = sections->next;
  658. if (k == 0) ReleaseSections (sections->fields, 1);
  659. Free ((unsigned long) sizeof (tdecl), (char *) sections);
  660. sections = next;
  661. }
  662. }
  663. static void ReleaseLabels
  664. #if defined __STDC__ | defined __cplusplus
  665. (register tplabel labels)
  666. #else
  667. (labels) register tplabel labels;
  668. #endif
  669. {
  670. while (labels) {
  671. tplabel next = labels->next;
  672. Free ((unsigned long) sizeof (tlabel), (char *) labels);
  673. labels = next;
  674. }
  675. }
  676. void ReleaseDeftab ARGS ((void))
  677. {
  678. ReleaseForwards (forwards);
  679. ReleaseSections (sections, 0);
  680. ReleaseLabels (labels);
  681. ReleaseDecls (decls);
  682. }
  683. static void GetEPos
  684. #if defined __STDC__ | defined __cplusplus
  685. (register tpdecl decls, tPosition * e_pos)
  686. #else
  687. (decls, e_pos) register tpdecl decls; tPosition * e_pos;
  688. #endif
  689. {
  690. if (decls->next ) GetEPos (decls->next , e_pos);
  691. else if (decls->fields) GetEPos (decls->fields, e_pos);
  692. else * e_pos = decls->e_pos;
  693. }
  694. static void PutDecls
  695. #if defined __STDC__ | defined __cplusplus
  696. (register tpdecl decls, int k)
  697. #else
  698. (decls, k) register tpdecl decls; int k;
  699. #endif
  700. {
  701. for (; decls; decls = decls->next) {
  702. if (decls->name != NoIdent) {
  703. current_ident = GetCStr (decls->name);
  704. if (decls->level == 78 || decls->level == 88) {
  705. /* constant */
  706. put_symbol (PAF_CONS_DEF, null, current_ident, current_file,
  707. (int) decls->position.Line, (int) decls->position.Column - 1,
  708. (int) decls->end_pos.Line, (int) decls->end_pos.Column,
  709. attr, null, null, null, null, 0, 0, 0, 0);
  710. } else {
  711. if (k == 0) {
  712. /* variable declared on outer level */
  713. put_symbol (PAF_GLOB_VAR_DEF, null, current_ident, current_file,
  714. (int) decls->position.Line, (int) decls->position.Column - 1,
  715. (int) decls->end_pos.Line, (int) decls->end_pos.Column,
  716. attr, null, null, null, null, 0, 0, 0, 0);
  717. } else {
  718. /* variable declared on inner level */
  719. current_class = GetCStr (stack_2 [k - 1]->name);
  720. if (current_class [0] == '\0') current_class = "FILLER";
  721. put_symbol (PAF_MBR_VAR_DEF, current_class, current_ident, current_file,
  722. (int) decls->position.Line, (int) decls->position.Column - 1,
  723. (int) decls->end_pos.Line, (int) decls->end_pos.Column,
  724. attr, null, null, null, null, 0, 0, 0, 0);
  725. }
  726. if (decls->fields) {
  727. /* variable has members */
  728. tPosition e_pos; GetEPos (decls->fields, & e_pos);
  729. /* was PAF_STRUCT_DEF, does not work any more because of new paf.h */
  730. put_symbol (PAF_CLASS_DEF, null, current_ident, current_file,
  731. (int) decls->position.Line, (int) decls->position.Column - 1,
  732. (int) e_pos.Line, (int) e_pos.Column,
  733. attr | PAF_STRUCT_DEF, null, null, null, null, 0, 0, 0, 0);
  734. stack_2 [k] = decls;
  735. PutDecls (decls->fields, k + 1);
  736. } else {
  737. /* variable has no members */
  738. }
  739. }
  740. } else { /* FILLER */
  741. if (decls->level == 78 || decls->level == 88) {
  742. /* constant */
  743. } else {
  744. if (decls->fields) {
  745. /* FILLER has members */
  746. stack_2 [k] = decls;
  747. PutDecls (decls->fields, k + 1);
  748. }
  749. }
  750. }
  751. }
  752. }
  753. static void PutSections
  754. #if defined __STDC__ | defined __cplusplus
  755. (register tpdecl sections, int k)
  756. #else
  757. (sections, k) register tpdecl sections; int k;
  758. #endif
  759. {
  760. for (; sections; sections = sections->next) {
  761. current_ident = GetCStr (sections->name);
  762. put_symbol (PAF_FUNC_DEF, null, current_ident, current_file,
  763. (int) sections->position.Line, (int) sections->position.Column - 1,
  764. (int) sections->e_pos.Line, (int) sections->e_pos.Column,
  765. attr, null, null, null, null, 0, 0, 0, 0);
  766. /* put_symbol (PAF_FUNC_DCL, null, current_ident, current_file,
  767. (int) sections->position.Line, (int) sections->position.Column - 1,
  768. (int) sections->e_pos.Line, (int) sections->e_pos.Column,
  769. attr, null, null, null, null, 0, 0, 0, 0);
  770. */
  771. /* put_symbol (PAF_SUBR_DEF, null, current_ident, current_file,
  772. (int) sections->position.Line, (int) sections->position.Column - 1,
  773. (int) sections->e_pos.Line, (int) sections->e_pos.Column,
  774. attr, null, null, null, null, 0, 0, 0, 0);
  775. */
  776. if (k == 0) PutSections (sections->fields, 1);
  777. }
  778. }
  779. void PutDeftab ARGS ((void))
  780. {
  781. PutSections (sections, 0);
  782. PutDecls (decls, 0);
  783. }