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