1 /* 2 * Copyright (c) 1983 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)languages.c 5.2 (Berkeley) 05/23/89"; 20 #endif /* not lint */ 21 22 /* 23 * Language management. 24 */ 25 26 #include "defs.h" 27 #include "languages.h" 28 #include "c.h" 29 #include "pascal.h" 30 #include "modula-2.h" 31 #include "asm.h" 32 33 #ifndef public 34 35 typedef struct Language *Language; 36 37 typedef enum { 38 L_PRINTDECL, L_PRINTVAL, L_TYPEMATCH, L_BUILDAREF, L_EVALAREF, 39 L_MODINIT, L_HASMODULES, L_PASSADDR, 40 L_ENDOP 41 } LanguageOp; 42 43 typedef LanguageOperation(); 44 45 Language primlang; 46 47 #endif 48 49 struct Language { 50 String name; 51 String suffix; 52 LanguageOperation *op[20]; 53 Language next; 54 }; 55 56 private Language head; 57 58 /* 59 * Initialize language information. 60 * 61 * The last language initialized will be the default one 62 * for otherwise indistinguised symbols. 63 */ 64 65 public language_init() 66 { 67 primlang = language_define("$builtin symbols", ".?"); 68 c_init(); 69 fortran_init(); 70 pascal_init(); 71 modula2_init(); 72 asm_init(); 73 } 74 75 public Language findlanguage(suffix) 76 String suffix; 77 { 78 Language lang; 79 80 lang = head; 81 if (suffix != nil) { 82 while (lang != nil and not streq(lang->suffix, suffix)) { 83 lang = lang->next; 84 } 85 if (lang == nil) { 86 lang = head; 87 } 88 } 89 return lang; 90 } 91 92 public String language_name(lang) 93 Language lang; 94 { 95 return (lang == nil) ? "(nil)" : lang->name; 96 } 97 98 public Language language_define(name, suffix) 99 String name; 100 String suffix; 101 { 102 Language p; 103 104 p = new(Language); 105 p->name = name; 106 p->suffix = suffix; 107 p->next = head; 108 head = p; 109 return p; 110 } 111 112 public language_setop(lang, op, operation) 113 Language lang; 114 LanguageOp op; 115 LanguageOperation *operation; 116 { 117 checkref(lang); 118 assert(ord(op) < ord(L_ENDOP)); 119 lang->op[ord(op)] = operation; 120 } 121 122 public LanguageOperation *language_op(lang, op) 123 Language lang; 124 LanguageOp op; 125 { 126 LanguageOperation *o; 127 128 checkref(lang); 129 o = lang->op[ord(op)]; 130 checkref(o); 131 return o; 132 } 133