/**** * * TransInterface provides functions that interface between the RSL browser and * the RSL translator, the latter written in ANSI C. TransInterface provides a * pretty clean abstraction from the browser's perspective. That is, via * TransInterface the rest of the browser need not know about the internals of * the translator. * * TransInterface provides less help from the translator's perspective. That * is, the translator is instrumented with a number of hooks that make * construction of browser information efficient. This is information that * would not be constructed at all by the translator if there were no browser * around. Hence, TransInterface provides upward by not very good downward * abstraction. We may revisit this in a later version. * * In general the following significant line is drawn between the browser and * translator: the browser does not deal at all with parse tree details. In * particular, the browser declares nodep (the parse tree node pointer) as * void*. * */ #ifndef transinterfaceIncluded #define transinterfaceIncluded //#include "browser.h" #include "std-macros++.h" #include "strlist.h" #include "new-features-stubs.h" #include "plainclist.h" #include "sym++.h" #include "esymtab.h" extern "C" int translator(int argc, char *argv[]); /* * Returns: * -1 ==> very fatal error, such as parse or type checking * 0 ==> non-fatal error, specifically undef'd names * 1 ==> no errors */ extern "C" void MoveToBrowserSymtab(); extern "C" void interpStmts(nodep); extern "C" void pp(nodep); /* extern "C" void eval(void*); */ class BrowserSymLists; class RSLBrowser; class TransInterface { public: TransInterface(int argc, char** argv); int Translate(int argc, char** argv); /* * Call the translator on the given command line args, and return what * translator() returns. Viz., return 1 if translation succeeds * entirely, 0 if there are undefined entities but translation otherwise * succeeds, -1 if there are fatal translation errors. * * In the current imple, the translator will NOT handle any checking of * .rsg files. This checking will be done as the files are opened by the * user. In a later imple, we might want the translator to perform at * least initial checking of of .rsg's by scanning the files for defs of * graphic object names that appear in picture attr decls. This is not * really a critical issue, so it can be done later. */ int ReTranslate(int argc, char** argv); /* * Call translator again, in response to Rescan command. */ bool TranslateOne(const char* filename); /* * Call the translator with just on one file; used to handle File.Open * menu command. */ void CallFun(const char* funname); /* * Call the function of the given name if it can be found. */ BrowserSymLists* GetAllSyms(); /* * Get the complete list of translated symbols, including module names, * object names, and op names. Inter-module namespace conflicts are * resolved by appending " (in Module M)" to each symbol with the same * name as one or more other symbols in other modules. */ EntityStructList* GetComponents(SymtabEntry* s); /* * Return a sorted list containing the names of the current entity's * components, given the symtab entry of the current entity. Use the * brComponents field of the symtab entry. */ EntityStructList* GetUnsortedComponents(SymtabEntry* s); /* * As GetComponents, but return unsorted list from brComponentsU. */ EntityStructList* GetInstances(SymtabEntry* s); /* * Return a sorted list of the current entity's instances. Use the * brInstances field of the symtab entry. */ EntityStructList* GetParents(SymtabEntry* s); /* * Return a sorted list of the current entity's hierarchical parents. * Use the brPartof field of the symtab entry. */ EntityStructList* GetClassParents(SymtabEntry* s); /* * Return a sorted list of the current entity's superclasses. Use the * brInstanceof field in the symtab entry. */ EntityStructList* GetOperations(SymtabEntry* s); /* * Return a sorted list of the current entity's operations. Use the * brOps field of the symtab entry. */ EntityStructList* GetInputs(SymtabEntry* s); /* * Return a sorted list of the current entity's inputs. Use the brIns * field of the symtab entry. */ EntityStructList* GetOutputs(SymtabEntry* s); /* * Return a sorted list of the current entity's outputs. Use the brOuts * field of the symtab entry. */ EntityStructList* GetLinks(SymtabEntry* s); /* * Return a sorted list of string lists of current entity's links. Use * the brLinks field of the symtab entry. */ void GetArgs(int& argc, char**& argv); /* * Supply the original command line args. */ void SetBrowser(RSLBrowser* browser); /* * Set the browser member. */ bool IsAtomic(SymtabEntry* sym); /* * Return true if the given symtab entry has an RSL atomic type. */ char* GetAtomicType(SymtabEntry* sym); /* * Return the string name of the type of the given symtab entry, assuming * it is an atomic type. Return NULL if the given symtab entry does not * have an atomic type. */ EquationsList* GetEquations(SymtabEntry* sym); /* * Return a list of equations for the given symtab entry. */ WhereClauseList* GetWhereClause(SymtabEntry* sym); /* * Return the where clause of the given symtab entry, assuming the entry * is an object. Return NULL if there is no where clause, including if * the given symtab entry is not an object. * * pre: sym->Class == C_Obj; */ StrList* GetPreCond(SymtabEntry* sym); /* * Return the precond of the given symtab entry as a list of strings, in * the form of lines of pretty printed RSL code. Assume the given symtab * entry is an op. */ StrList* GetPostCond(SymtabEntry* sym); /* * Return the postcond of the given symtab entry as a list of strings, in * the form of lines of pretty printed RSL code. Assume the given symtab * entry is an op. */ StrList* GetImports(SymtabEntry* sym); /* * Return a string list of the imports of the given symtab entry, * assuming it is a module. Each list elem is of the form: * * import-name [(from module-name)] * * where the from module-name clause is non-empty if the import clause in * which the import-name appears is qualified with a from clause. Return * NULL if the given sym has no imports or is not a module. */ StrList* GetExports(SymtabEntry* sym); /* * Return a string list of the exports of the given symtab entry, * assuming it is a module. Return NULL if the given sym has no imports * or is not a module. */ StrList* GetAttrDefs(SymtabEntry* sym); /* * Return a string list of the attribute defs of the given symtab entry, * assuming it is a module. The list is of the form of pretty printed * RSL code. Return NULL if the given sym has no imports or is not a * module. */ EntitySymtab* GetBrowserSymtab(); /* * Return the browser symtab. */ BrowserSymLists* SortSyms(); /* * Sort the symbol lists and stick them in a BrowserSymLists structure * for use by RSLBrowser::InstallNames, q.v. Note that we suffix names * with the disambiguating module name. Hence the primary sort key is * the symbol name; the secondary sort key is the module name. */ void DebugPrint(EntityStructList* l); protected: void Init(); /* * Do initializer and retranslation init. */ bool InSameModule(SymtabEntry* s1, SymtabEntry* s2); /* * Return true if the given two entries are in the same module, viz., * have the same Info.{Obj,Op}.parent field values. */ void GetModSyms(); /* * Get the module names from the separate browser symtab that the * translator builds for us. Also, build the individual per-module sym * lists that are used for building the individual per-module * dictionaries. Finally, set num_mods to the count of the total number * of modules. */ void PutSym(char* s, SymtabEntry* preve); /* * Put the given symbol name and sytab entry in the appro list based on * its class, viz. module, obj, op, or other. */ void EnterInfo(SymtabEntry* sym); /* * This, and the next 17 functions that follow, grab info from the * symtabs entries, including the attached parse tree, to construct the * lists that will be displayed in pulldonws of the menu bar. At this * point, all these functions do is convert the PlainCAuxLists created by * the translator into the EntityStructLists that the browser needs. See * the further comments about the imple in the .c file. */ void EnterObjInfo(SymtabEntry* sym); void EnterObjComponents(SymtabEntry* sym); void EnterObjInstances(SymtabEntry* sym); void EnterObjParents(SymtabEntry* sym); void EnterObjClassParents(SymtabEntry* sym); void EnterObjOperations(SymtabEntry* sym); void EnterObjLinks(SymtabEntry* sym); void EnterOpInfo(SymtabEntry* sym); void EnterOpComponents(SymtabEntry* sym); void EnterOpInstances(SymtabEntry* sym); void EnterOpParents(SymtabEntry* sym); void EnterOpClassParents(SymtabEntry* sym); void EnterOpInputs(SymtabEntry* sym); void EnterOpOutputs(SymtabEntry* sym); void EnterOpLinks(SymtabEntry* sym); void EnterGeneralValues( SymtabEntry* sym, EntityStructList** brValuesPtr, EntityStructList** brUnsortedValuesPtr); void EnterLinks(SymtabEntry* sym, EntityStructList** brLinksPtr); /* * Of note in EnterLinks is the separate handling of picture vs all other * links. Viz., picture links are used to cross the text/graphics * boundary, whereas all other links stay text-to-text. The * ramifications of this separation are the following: * * (1) The names appearing as values in the "picture" attr are in a * separate name space from other rsl entities. This means, in * particular, that the name of an entity's picture can be the * same as its own name, if desired. * * (2) Given (1), picture names need not be looked up in the browser * symtab, but they are anyway so the browser can act moderately * intelligent in browser-only mode. I.e., it treats pictures as * regular entities in browser-only mode. * * (3) Each name in a picture attr is entered into the * graphicsSymtab. This tab is a cross ref from graphic object * names to RSL entity names. It is the key to efficient imple * of link following from the graphic browser back to the text * browser. Viz., when we create the picture-of submenu for a * selected graphic object, the name of the graphic object is * looked up in the graphicSymtab, wherein the entry under that * name has a pointer back to the entity of which the graphic * object is a picture, which entity is used to update the * text browser context. * * An entry e in the graphicsSymtab has the following format: * * e->GetName() == name of graphic object * e->GetSym() == EntityStructList ptr cast to (SymtabEntry*) * * An element es of e->GetSym() has the following format: * * es->GetName()== name of rsl entity of which e->GetName() * is a picture * es->GetSym() == symtab entry for rsl entity * * Given this, (EntityStruct*) e->GetSym() can be past from the * graphic browser to browser->UpdateCurEntity(). */ void TransInterface::EnterGraphicsName(char* name, SymtabEntry* sym); /* * Enter picture names in graphics cross ref symtab. */ public: EntityStruct* LookupGraphicsName(char* name); /* * Return the entered entity struct for the given name. */ protected: /* * Data members. */ EntityStructList* mods; /* Aux str list of module names */ EntityStructList* objs; /* Aux str list of obj names */ EntityStructList* ops; /* Aux str list of op names */ EntityStructList** indiv_mods; /* Array of indiv per-module lists */ int num_mods; /* Total number of modules. */ EntityStructList* others; /* Aux str list of other symbol names (e.g., * attrs and macros) */ EntitySymtab* browserSymtab;/* Full symtab of all disambiguated names */ EntitySymtab* graphicsSymtab;/* Symtab of all picture names */ int argc; /* Saved copies of original command line */ char** argv; /* args */ RSLBrowser* browser; /* Daddy */ }; /* * BrowserSymLists is the packet of info that the browser needs to fire things * up. Its primary fields are three sorted string lists for modules, objs, and * ops. See rslbrowser.c:RSLBrowser::InstallNames for how this info is used. * * The others field contains other translator-recognized symbols, such as attr * names. These are not currently used, but may be in the future. */ class BrowserSymLists { public: BrowserSymLists(EntityStructList* mods, EntityStructList* objs, EntityStructList* ops, EntityStructList* others /*, EntityStructList* graphics */); EntityStructList* mods; EntityStructList* objs; EntityStructList* ops; EntityStructList** indiv_mods; int num_mods; EntityStructList* others; EntityStructList* graphics; }; #endif