xref: /original-bsd/old/dbx/languages.c (revision 1808f06c)
1 /*
2  * Copyright (c) 1983 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)languages.c	5.3 (Berkeley) 06/01/90";
10 #endif /* not lint */
11 
12 /*
13  * Language management.
14  */
15 
16 #include "defs.h"
17 #include "languages.h"
18 #include "c.h"
19 #include "pascal.h"
20 #include "modula-2.h"
21 #include "asm.h"
22 
23 #ifndef public
24 
25 typedef struct Language *Language;
26 
27 typedef enum {
28     L_PRINTDECL, L_PRINTVAL, L_TYPEMATCH, L_BUILDAREF, L_EVALAREF,
29     L_MODINIT, L_HASMODULES, L_PASSADDR,
30     L_ENDOP
31 } LanguageOp;
32 
33 typedef LanguageOperation();
34 
35 Language primlang;
36 
37 #endif
38 
39 struct Language {
40     String name;
41     String suffix;
42     LanguageOperation *op[20];
43     Language next;
44 };
45 
46 private Language head;
47 
48 /*
49  * Initialize language information.
50  *
51  * The last language initialized will be the default one
52  * for otherwise indistinguised symbols.
53  */
54 
language_init()55 public language_init()
56 {
57     primlang = language_define("$builtin symbols", ".?");
58     c_init();
59     fortran_init();
60     pascal_init();
61     modula2_init();
62     asm_init();
63 }
64 
findlanguage(suffix)65 public Language findlanguage(suffix)
66 String suffix;
67 {
68     Language lang;
69 
70     lang = head;
71     if (suffix != nil) {
72 	while (lang != nil and not streq(lang->suffix, suffix)) {
73 	    lang = lang->next;
74 	}
75 	if (lang == nil) {
76 	    lang = head;
77 	}
78     }
79     return lang;
80 }
81 
language_name(lang)82 public String language_name(lang)
83 Language lang;
84 {
85     return (lang == nil) ? "(nil)" : lang->name;
86 }
87 
language_define(name,suffix)88 public Language language_define(name, suffix)
89 String name;
90 String suffix;
91 {
92     Language p;
93 
94     p = new(Language);
95     p->name = name;
96     p->suffix = suffix;
97     p->next = head;
98     head = p;
99     return p;
100 }
101 
language_setop(lang,op,operation)102 public language_setop(lang, op, operation)
103 Language lang;
104 LanguageOp op;
105 LanguageOperation *operation;
106 {
107     checkref(lang);
108     assert(ord(op) < ord(L_ENDOP));
109     lang->op[ord(op)] = operation;
110 }
111 
language_op(lang,op)112 public LanguageOperation *language_op(lang, op)
113 Language lang;
114 LanguageOp op;
115 {
116     LanguageOperation *o;
117 
118     checkref(lang);
119     o = lang->op[ord(op)];
120     checkref(o);
121     return o;
122 }
123