1 /* 2 * Copyright (C) 2006 Bill Cox 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 17 */ 18 19 #include <stdio.h> 20 #include "dvdatabase.h" 21 22 #define DV_MAX_INDENT 1024 23 24 bool dvGenerateCode(dvModule module, char *includeFile, char *sourceFile); 25 void dvWriteHeaderFile(dvModule module, char *includeFile); 26 void dvWriteCFile(dvModule module, char *sourceFile); 27 void dvGenerateAdminTool(dvModule module, char *sourceDir); 28 bool dvReadFile(char *fileName, bool loadModules); 29 extern void dvBindProperty(dvProperty property, dvModule module); 30 void dvBindTypes(dvModule module); 31 32 /* Constructors */ 33 dvModpath dvModpathCreate(utSym sym, bool insertAtHeadOfList); 34 dvModule dvModuleCreate(utSym sym, utSym prefix); 35 dvEnum dvEnumCreate(dvModule module, utSym sym, utSym prefix); 36 dvEntry dvEntryCreate(dvEnum owningEnum, utSym sym, uint32 value); 37 dvTypedef dvTypedefCreate(dvModule module, utSym sym, char *initializer); 38 dvSchema dvSchemaCreate(dvModule module, utSym sym); 39 dvClass dvClassCreate(dvModule module, utSym sym, dvClass baseClass); 40 dvProperty dvPropertyCreate(dvClass owningClass, dvUnion owningUnion, dvPropertyType type, utSym sym); 41 dvUnion dvUnionCreate(dvClass owningClass, utSym propertySym, uint16 unionNumber); 42 dvRelationship dvRelationshipCreate(dvSchema schema, dvClass parent, dvClass child, dvRelationshipType type, 43 utSym parentLabel, utSym childLabel); 44 dvLink dvLinkCreate(dvModule importModule, dvModule exportModule); 45 dvKey dvKeyCreate(dvRelationship relationship, dvProperty property); 46 dvKey dvUnboundKeyCreate(dvRelationship relationship, utSym propertySym, uint32 lineNum); 47 dvCase dvCaseCreate(dvProperty property, dvEntry entry); 48 dvSparsegroup dvSparsegroupCreate(dvClass theClass, utSym sym); 49 50 /* Utility functions */ 51 void prUtilStart(void); 52 void prUtilStop(void); 53 dvModule dvFindModuleFromPrefix(utSym prefix); 54 uint8 dvFindPropertySize(dvProperty property); 55 void dvWrtemp(FILE *file, char *temp, ...); 56 char *dvSwrtemp(char *temp, ...); 57 char *dvPropertyGetTypeName(dvProperty property); 58 char *dvPropertyGetFieldTypeName(dvProperty property); 59 uint32 dvComputeDatabaseHash(void); 60 char *dvClassGetPrefix(dvClass theClass); 61 utSym dvUpperSym(utSym sym); 62 char *dvFindPropertyFormatString(dvProperty property); 63 char *dvClassGetReferenceTypeName(dvClass theClass); 64 bool dvModuleHasClassAttributes(dvModule module); 65 void dvAddDefaultKey(dvRelationship relationship); 66 bool dvRelationshipHashedByName(dvRelationship relationship); 67 char *dvPropertyFindInitializer(dvProperty property); 68 69 /* Some shortcut macros */ 70 #define dvModuleGetPrefix(module) utSymGetName(dvModuleGetPrefixSym(module)) 71 #define dvRelationshipGetParentLabel(theClass) utSymGetName(dvRelationshipGetParentLabelSym(theClass)) 72 #define dvRelationshipGetChildLabel(theClass) utSymGetName(dvRelationshipGetChildLabelSym(theClass)) 73 #define dvClassPersistent(theClass) dvModulePersistent(dvClassGetModule(theClass)) 74 #define dvPropertyGetID(property) utSprintf("%u", dvPropertyGetFieldNumber(property)) 75 #define dvClassRedo(theClass) (dvModulePersistent(dvClassGetModule(theClass)) || \ 76 dvModuleUndoRedo(dvClassGetModule(theClass))) 77 #define dvClassUndo(theClass) (dvModuleUndoRedo(dvClassGetModule(theClass))) 78 #define dvUnionGetTypeName(theUnion) utSprintf("%s%sUnion%d", dvPrefix, \ 79 dvClassGetName(dvUnionGetClass(theUnion)), dvUnionGetNumber(theUnion)) 80 #define dvUnionGetFieldName(theUnion) utSprintf("union%d", dvUnionGetNumber(theUnion)) 81 82 /* Globals */ 83 extern dvRoot dvTheRoot; /* Root of the database */ 84 extern dvModule dvCurrentModule; /* Module just read by dvparse */ 85 86 /* Lex, Yacc stuff */ 87 extern uint32 dvLineNum; 88 extern bool dvLoadModules; 89 extern uint16 dvNumEndsRemaining; 90 extern int dvparse(void); 91 extern int dvlex(void); /* A wrapper around dvlexlex */ 92 extern int dvlexlex(void); /* The real lexer */ 93 extern void dverror(char *message, ...); 94 extern char *dvlextext; 95 extern FILE *dvFile; 96