📄 deftab.c
字号:
/*Copyright (c) 2000, Red Hat, Inc.This file is part of Source-Navigator.Source-Navigator is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public License as publishedby the Free Software Foundation; either version 2, or (at your option)any later version.Source-Navigator is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith Source-Navigator; see the file COPYING. If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330, Boston,MA 02111-1307, USA.*//* Ich, Doktor Josef Grosch, Informatiker, Dez. 1996 */#include <string.h>#include "def.h"#include "deftab.h"#include "rMemory.h"#include "Errors.h"#include "StringM.h"#include "keywords.h"#include "cobol.h"#include "sn.h"#define null (char *) NULL#define attr (unsigned long) PAF_PUBLICstatic char * section_name [] = { 0, "CONFIGURATION_SECTION", "INPUT-OUTPUT_SECTION", "FILE_SECTION", "WORKING-STORAGE_SECTION", "LOCAL-STORAGE_SECTION", "LINKAGE_SECTION", "COMMUNICATION_SECTION", "REPORT_SECTION", "SCREEN_SECTION", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "IDENTIFICATION_DIVISION", "ENVIRONMENT_DIVISION", "DATA_DIVISION", "PROCEDURE_DIVISION",};typedef struct { char level ; tpdecl * decls ;} tstack; char Section = 0; rbool NameCheck = rfalse; int acc = PAF_REF_READ;extern int error_count ;static tpdecl decls = NULL; /* declared data */static tpuse forwards = NULL; /* used data */static tpdecl sections = NULL; /* declared labels */static tplabel labels = NULL; /* used labels */static tpdecl stack_2 [52] ;static tstack stack [52] = {{01, & decls}};static int stack_ptr = 0;static int cur_level = 01;static tpdecl field [52] ;static int field_ptr = 0;static tpdecl cpl_dcl [52] ;static int cpl_dcl_ptr = 0;static tpdecl cpl_use [52] ;static int cpl_use_ptr = 0;static char * current_ident, * current_class;static char * current_subr, * ref_class;static void Predef#if defined __STDC__ | defined __cplusplus (char * name, unsigned long mask)#else (name, mask) char * name; unsigned long mask;#endif{ if (dialect & mask) { register tpdecl decl = (tpdecl) Alloc ((unsigned long) sizeof (tdecl)); decl->position = NoPosition; decl->end_pos = NoPosition; decl->e_pos = NoPosition; decl->level = 01; decl->name = MakeIdent (name, strlen (name)); decl->next = NULL; decl->fields = NULL; * stack [0].decls = decl; stack [0].decls = & decl->next; }}void BeginDeftab ARGS ((void)){ decls = NULL; /* declared data */ forwards = NULL; /* used data */ sections = NULL; /* declared labels */ labels = NULL; /* used labels */ stack [0].level = 01; stack [0].decls = & decls; stack_ptr = 0; cur_level = 01; field_ptr = 0; cpl_dcl_ptr = 0; cpl_use_ptr = 0;/* Predef ("PRINTER" , all); Predef ("PRINTER-1" , all); Predef ("CONSOLE" , all);#include "predef.c"*/}static void WriteDecls#if defined __STDC__ | defined __cplusplus (register tpdecl decls, int k)#else (decls, k) register tpdecl decls; int k;#endif{ register int i; for (; decls; decls = decls->next) { WritePosition (stdout, decls->position); for (i = 1; i <= k; i ++) (void) printf (" "); (void) printf (" %02d ", decls->level); WriteIdent (stdout, decls->name); (void) printf ("\n"); WriteDecls (decls->fields, k + 1); }}static void WriteForwards#if defined __STDC__ | defined __cplusplus (register tpuse forwards, int k)#else (forwards, k) register tpuse forwards; int k;#endif{ register int i; for (; forwards; forwards = forwards->next) { WritePosition (stdout, forwards->position); for (i = 0; i <= k; i ++) (void) printf (" "); WriteIdent (stdout, forwards->name); (void) printf ("\n"); WriteForwards (forwards->fields, k + 1); }}static void WriteSections#if defined __STDC__ | defined __cplusplus (register tpdecl sections, int k)#else (sections, k) register tpdecl sections; int k;#endif{ register int i; for (; sections; sections = sections->next) { WritePosition (stdout, sections->position); (void) printf (" "); sections->end_pos.FileName = NoIdent; WritePosition (stdout, sections->end_pos); (void) printf (" "); sections->e_pos.FileName = NoIdent; WritePosition (stdout, sections->e_pos); for (i = 0; i <= k; i ++) (void) printf (" "); WriteIdent (stdout, sections->name); (void) printf ("\n"); if (k == 0) WriteSections (sections->fields, 1); }}static void WriteLabels#if defined __STDC__ | defined __cplusplus (register tplabel labels)#else (labels) register tplabel labels;#endif{ for (; labels; labels = labels->next) { WritePosition (stdout, labels->position); (void) printf (" "); WriteIdent (stdout, labels->name); (void) printf (" "); WriteIdent (stdout, labels->name2); (void) printf ("\n"); }}void WriteDeftab ARGS ((void)){ (void) printf ("decls\n"); WriteDecls (decls, 0); (void) printf ("forwards\n"); WriteForwards (forwards, 0); (void) printf ("sections\n"); WriteSections (sections, 0); (void) printf ("labels\n"); WriteLabels (labels);}/**/tpdecl Declare#if defined __STDC__ | defined __cplusplus (register int level, tScanAttribute Attribute, int Type, tPosition e_pos)#else (level, Attribute, Type, e_pos) register int level ; tScanAttribute Attribute ; int Type ; tPosition e_pos ;#endif{ register tpdecl decl = (tpdecl) Alloc ((unsigned long) sizeof (tdecl)); decl->position = Attribute.Position; decl->end_pos = Attribute.name.EPos; decl->e_pos = e_pos; decl->level = level; decl->name = Attribute.name.Ident; decl->next = NULL; decl->fields = NULL; switch (level) { case MN: /* mnemonic name of SPECIAL-NAMES */ case CN: /* condition name of SPECIAL-NAMES */ case FD: case SD: case CD: case RD: stack_ptr = 0; break; case 01: if (Section == cFILE_SCT || Section == cCOMM_SCT) { if (stack_ptr == 0) { stack [1].level = level; stack [1].decls = & cpl_dcl [1]->fields; } stack_ptr = 1; } else { stack_ptr = 0; } cur_level = level; break; case 66: if (Section == cFILE_SCT) { if (stack_ptr == 0) { /* if fields are missing: */ stack [1].level = level; /* should not occur */ stack [1].decls = & cpl_dcl [1]->fields; stack_ptr = 1; break; } if (stack_ptr == 1) { stack [2].level = level; stack [2].decls = & cpl_dcl [2]->fields; } stack_ptr = 2; } else { if (stack_ptr == 0) { stack [1].level = level; stack [1].decls = & cpl_dcl [1]->fields; } stack_ptr = 1; } break; case 77: case 78: stack_ptr = 0; break; case IB: /* INDEXED BY of data description */ { tpdecl prev_cpl_dcl = cpl_dcl [1]; int prev_cpl_dcl_ptr = cpl_dcl_ptr; * stack [0].decls = decl; stack [0].decls = & decl->next; cpl_dcl [cpl_dcl_ptr = 1] = decl; cpl_dcl [1] = prev_cpl_dcl; cpl_dcl_ptr = prev_cpl_dcl_ptr; return decl; } case 88: default: /* levels 02 - 49 */ if (level < cur_level) { while (level < stack [-- stack_ptr].level); if (level > stack [stack_ptr].level) stack [++ stack_ptr].level = level; cur_level = level; } else if (level > cur_level) { if (cpl_dcl_ptr > 0) { stack_ptr ++; stack [stack_ptr].decls = & cpl_dcl [stack_ptr]->fields; } stack [stack_ptr].level = level; cur_level = level; } } * stack [stack_ptr].decls = decl; stack [stack_ptr].decls = & decl->next; cpl_dcl [cpl_dcl_ptr = stack_ptr + 1] = decl; return decl;}tpdecl DeclareLabel#if defined __STDC__ | defined __cplusplus (tScanAttribute Attribute, int Type, tPosition e_pos)#else (Attribute, Type, e_pos) tScanAttribute Attribute; int Type; tPosition e_pos;#endif{ register tpdecl decl = (tpdecl) Alloc ((unsigned long) sizeof (tdecl)); decl->position = Attribute.Position; decl->end_pos = Attribute.name.EPos; decl->e_pos = e_pos; decl->level = Type; decl->name = Attribute.name.Ident; if (Type == lSECTION || sections == NULL || sections->level != lSECTION) { decl->fields = NULL; decl->next = sections; sections = decl; cpl_dcl_ptr = 1; } else { decl->fields = sections; decl->next = sections->fields; sections->fields = decl; cpl_dcl_ptr = 2; } if (Type != lENTRY) current_subr = GetCStr (Attribute.name.Ident); return decl;}void DeclareEnd#if defined __STDC__ | defined __cplusplus (int Type, tPosition e_pos)#else (Type, e_pos) int Type; tPosition e_pos;#endif{ register tpdecl decl = sections; while (decl->level == lENTRY) decl = decl->next; if (Type == lSECTION) { if (decl->level == lSECTION) decl->e_pos = e_pos; } else { if (decl->level == lSECTION) { decl = decl->fields; while (decl->level == lENTRY) decl = decl->next; } decl->e_pos = e_pos; }}tpdecl search_next#if defined __STDC__ | defined __cplusplus (register tIdent name, register tpdecl decls)#else (name, decls) register tIdent name; register tpdecl decls;#endif{ while (decls) if (decls->name == name) return decls; else decls = decls->next; return NULL;}tpdecl search_all#if defined __STDC__ | defined __cplusplus (register tIdent name, register tpdecl decls, int nest)#else (name, decls, nest) register tIdent name ; register tpdecl decls ; int nest ;#endif{ while (decls) { if (decls->name == name) return cpl_use [cpl_use_ptr = nest] = decls; if (decls->fields) { register tpdecl decl = search_all (name, decls->fields, nest + 1); if (decl) { cpl_use [nest] = decls; return decl; } } decls = decls->next; } return NULL;}void CloseForwards ARGS ((void)){ tpuse forward = forwards; tpdecl decl; tpuse field; tScanAttribute Attribute; while (forward) { current_subr = section_name [forward->section]; Attribute.name.Ident = forward->name; Attribute.Position = forward->position; Attribute.name.EPos = forward->end_pos; decl = UseName (Attribute); for (field = forward->fields; field && decl; field = field->fields) { Attribute.name.Ident = field->name; Attribute.Position = field->position; Attribute.name.EPos = field->end_pos; decl = UseField (Attribute, decl->fields); } forward = forward->next; }}tpdecl UseName#if defined __STDC__ | defined __cplusplus (tScanAttribute Attribute)#else (Attribute) tScanAttribute Attribute;#endif{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -