| 1 | /* ***** BEGIN LICENSE BLOCK ***** | 
|---|
| 2 | * Version: CDDL 1.0/LGPL 2.1 | 
|---|
| 3 | * | 
|---|
| 4 | * The contents of this file are subject to the COMMON DEVELOPMENT AND | 
|---|
| 5 | * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use | 
|---|
| 6 | * this file except in compliance with the License. You may obtain a copy of | 
|---|
| 7 | * the License at http://www.sun.com/cddl/ | 
|---|
| 8 | * | 
|---|
| 9 | * Software distributed under the License is distributed on an "AS IS" basis, | 
|---|
| 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 
|---|
| 11 | * for the specific language governing rights and limitations under the | 
|---|
| 12 | * License. | 
|---|
| 13 | * | 
|---|
| 14 | * The Original Code is "NOM" Netlabs Object Model | 
|---|
| 15 | * | 
|---|
| 16 | * The Initial Developer of the Original Code is | 
|---|
| 17 | * netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>. | 
|---|
| 18 | * Portions created by the Initial Developer are Copyright (C) 2007 | 
|---|
| 19 | * the Initial Developer. All Rights Reserved. | 
|---|
| 20 | * | 
|---|
| 21 | * Contributor(s): | 
|---|
| 22 | * | 
|---|
| 23 | * Alternatively, the contents of this file may be used under the terms of | 
|---|
| 24 | * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which | 
|---|
| 25 | * case the provisions of the LGPL are applicable instead of those above. If | 
|---|
| 26 | * you wish to allow use of your version of this file only under the terms of | 
|---|
| 27 | * the LGPL, and not to allow others to use your version of this file under | 
|---|
| 28 | * the terms of the CDDL, indicate your decision by deleting the provisions | 
|---|
| 29 | * above and replace them with the notice and other provisions required by the | 
|---|
| 30 | * LGPL. If you do not delete the provisions above, a recipient may use your | 
|---|
| 31 | * version of this file under the terms of any one of the CDDL or the LGPL. | 
|---|
| 32 | * | 
|---|
| 33 | * ***** END LICENSE BLOCK ***** */ | 
|---|
| 34 |  | 
|---|
| 35 | /* in token.c */ | 
|---|
| 36 | void getNextToken(void); | 
|---|
| 37 | gboolean matchCur(GTokenType token); | 
|---|
| 38 | gboolean matchNext(GTokenType token); | 
|---|
| 39 | guint queryCurTokensKind(void); | 
|---|
| 40 | void printToken(GTokenType token); | 
|---|
| 41 | gboolean matchNextKind(guint uiKind); | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 | #define IDL_COMPILER_STRING "IDL compiler" /* Used inside warnings and errors */ | 
|---|
| 45 | #define ID_SCOPE 0 | 
|---|
| 46 |  | 
|---|
| 47 | /* Holding an overriden method */ | 
|---|
| 48 | typedef struct | 
|---|
| 49 | { | 
|---|
| 50 | gchar* chrName;    /* Name of this instance variable */ | 
|---|
| 51 | gchar* chrIntroducingIFace; | 
|---|
| 52 | }OVERMETHOD, *POVERMETHOD; | 
|---|
| 53 |  | 
|---|
| 54 | #define PARM_DIRECTION_IN     1 | 
|---|
| 55 | #define PARM_DIRECTION_OUT    2 | 
|---|
| 56 | #define PARM_DIRECTION_INOUT  3 | 
|---|
| 57 | /* Holding a method parameter */ | 
|---|
| 58 | typedef struct | 
|---|
| 59 | { | 
|---|
| 60 | guint  uiDirection;   /* in|out|inout */ | 
|---|
| 61 | gchar* chrType;       /* Type e.g. gulong or GtkWidget */ | 
|---|
| 62 | guint  uiStar;        /* incremented for each '*'      */ | 
|---|
| 63 | gchar* chrName; | 
|---|
| 64 | }METHODPARAM, *PMETHODPARAM; | 
|---|
| 65 |  | 
|---|
| 66 | /* Holding a method */ | 
|---|
| 67 | typedef struct | 
|---|
| 68 | { | 
|---|
| 69 | gchar* chrRetType;    /* Type e.g. gulong or GtkWidget */ | 
|---|
| 70 | gchar* chrName; | 
|---|
| 71 | METHODPARAM mpReturn; /* We don't use all fields of this struct */ | 
|---|
| 72 | GPtrArray *pParamArray; | 
|---|
| 73 | }METHOD, *PMETHOD; | 
|---|
| 74 |  | 
|---|
| 75 | /* Info about a symbol */ | 
|---|
| 76 | typedef struct | 
|---|
| 77 | { | 
|---|
| 78 | gchar* chrSymbolName; | 
|---|
| 79 | guint  uiSymbolToken; | 
|---|
| 80 | guint  uiKind; | 
|---|
| 81 | }SYMBOL, *PSYMBOL; | 
|---|
| 82 |  | 
|---|
| 83 | /* Struct holding all the info of a defined or declared interface */ | 
|---|
| 84 | typedef struct | 
|---|
| 85 | { | 
|---|
| 86 | gchar* chrName;    /* Name of this interface   */ | 
|---|
| 87 | gchar* chrParent;  /* Name of parent interface */ | 
|---|
| 88 | gulong ulMajor;    /* Class version            */ | 
|---|
| 89 | gulong ulMinor;    /* Class version            */ | 
|---|
| 90 | gboolean fIsForwardDeclaration; | 
|---|
| 91 | PSYMBOL pSymbolIFace; /* Found interfaces are registered as a symbol with the parser. | 
|---|
| 92 | This is a pointer to the registered struct holding the necessary | 
|---|
| 93 | info and may be used to deregister a symbol later.*/ | 
|---|
| 94 | PSYMBOL pSymbolIFacePtr; /* Same as before but for the pointer on an interface which is | 
|---|
| 95 | registered automatically. */ | 
|---|
| 96 | gboolean fIsInRootFile; | 
|---|
| 97 | gchar* chrMetaClass; /* Pointer to metaclass name or NULL*/ | 
|---|
| 98 | char*  chrFileStem;  /* Holding output filestem */ | 
|---|
| 99 | char*  chrSourceFileName; /* The preprocessor includes files for us. This is the info | 
|---|
| 100 | about the file this interface is defined in. */ | 
|---|
| 101 | GPtrArray *pMethodArray; | 
|---|
| 102 | GPtrArray *pOverrideArray; | 
|---|
| 103 | GPtrArray *pInstanceVarArray; | 
|---|
| 104 | }INTERFACE,*PINTERFACE; | 
|---|
| 105 |  | 
|---|
| 106 |  | 
|---|
| 107 | typedef struct | 
|---|
| 108 | { | 
|---|
| 109 | PINTERFACE pCurInterface;      /* The interface we are currently parsing. This is a working pointer. */ | 
|---|
| 110 | guint     uiCurSymbolKind;     /* This may be e.g. KIND_TYPESPEC */ | 
|---|
| 111 | GTree*    pSymbolTree;         /* Our introduced symbols */ | 
|---|
| 112 | GPtrArray* pInterfaceArray;    /* The pointer array holding the interfaces we found */ | 
|---|
| 113 | guint     uiLineCorrection;    /* This is the line number put by the preprocessor into | 
|---|
| 114 | the source file. It's used to calculate proper line numbers | 
|---|
| 115 | for errors. */ | 
|---|
| 116 | char*     chrRootSourceFile;   /* File we are intending to parse. Others may get included. */ | 
|---|
| 117 | char*     chrCurrentSourceFile;/* The preprocessor includes files for us. This is the info | 
|---|
| 118 | about their name. */ | 
|---|
| 119 | char*  chrOutfilePath;         /* This is only the path, no filename */ | 
|---|
| 120 | FILE*     outFile;             /* Output file handle */ | 
|---|
| 121 | }PARSEINFO, *PPARSEINFO; | 
|---|
| 122 |  | 
|---|
| 123 | /* Symbols defined for our IDL language. | 
|---|
| 124 | Keep these enums in sync with the order of the idlSymbols struct! */ | 
|---|
| 125 | enum | 
|---|
| 126 | { | 
|---|
| 127 | IDL_SYMBOL_INTERFACE=G_TOKEN_LAST+1, | 
|---|
| 128 | IDL_SYMBOL_CLSVERSION, | 
|---|
| 129 | IDL_SYMBOL_INSTANCEVAR, | 
|---|
| 130 | IDL_SYMBOL_OVERRIDE, | 
|---|
| 131 | IDL_SYMBOL_OVERRIDE2, | 
|---|
| 132 | IDL_SYMBOL_REGINTERFACE,  /* Used for registered interfaces */ | 
|---|
| 133 | IDL_SYMBOL_CLSNAME, | 
|---|
| 134 | IDL_SYMBOL_OLDMETACLASS, | 
|---|
| 135 | IDL_SYMBOL_METACLASS, | 
|---|
| 136 | IDL_SYMBOL_FILESTEM,      /* Followed by the file name for output */ | 
|---|
| 137 | IDL_SYMBOL_NATIVE, | 
|---|
| 138 | /* Some GLib types */ | 
|---|
| 139 | IDL_SYMBOL_GULONG,           /* 275 */ | 
|---|
| 140 | IDL_SYMBOL_GINT, | 
|---|
| 141 | IDL_SYMBOL_GPOINTER, | 
|---|
| 142 | IDL_SYMBOL_GBOOLEAN, | 
|---|
| 143 | IDL_SYMBOL_GCHAR, | 
|---|
| 144 | IDL_SYMBOL_VOID, | 
|---|
| 145 | /* Legacy support */ | 
|---|
| 146 | IDL_SYMBOL_BOOLEAN, | 
|---|
| 147 | IDL_SYMBOL_STRING, | 
|---|
| 148 | IDL_SYMBOL_LONG, | 
|---|
| 149 | IDL_SYMBOL_UNSIGNED, | 
|---|
| 150 | /* Direction of method parameters */ | 
|---|
| 151 | IDL_SYMBOL_IN, | 
|---|
| 152 | IDL_SYMBOL_OUT, | 
|---|
| 153 | IDL_SYMBOL_INOUT, | 
|---|
| 154 | /* Preprocessor stuff (not yet supported by the compiler) */ | 
|---|
| 155 | IDL_SYMBOL_DEFINE, | 
|---|
| 156 | IDL_SYMBOL_IFDEF, | 
|---|
| 157 | IDL_SYMBOL_ENDIF | 
|---|
| 158 | }; | 
|---|
| 159 |  | 
|---|
| 160 | /* Specifies the kind of a token we read. For example we must | 
|---|
| 161 | know if a read in indentifier is a type specification when | 
|---|
| 162 | parsing method parameters. */ | 
|---|
| 163 | enum | 
|---|
| 164 | { | 
|---|
| 165 | KIND_UNKNOWN =1, | 
|---|
| 166 | KIND_IDENTIFIER, | 
|---|
| 167 | KIND_TYPESPEC,    /* That's something like 'gint', 'gulong'... */ | 
|---|
| 168 | KIND_DIRECTION    /* in, out, inout */ | 
|---|
| 169 | }; | 
|---|
| 170 |  | 
|---|
| 171 | PINTERFACE findInterfaceFromName(gchar* chrName); | 
|---|
| 172 |  | 
|---|
| 173 | void parseTypeSpec(PMETHODPARAM pMethodParam); | 
|---|
| 174 | void parseMethod(void); | 
|---|
| 175 | void parseInstanceVar(void); | 
|---|
| 176 | void parseInterface(GTokenType token); | 
|---|
| 177 | void parseClassVersion(void); | 
|---|
| 178 | void parseClassVersion(void); | 
|---|
| 179 | void parseOverrideMethod(void); | 
|---|
| 180 | void parseOverrideMethodFromIdentifier(void); | 
|---|
| 181 | void parseHash(void); | 
|---|
| 182 | void parsePreprocLineInfo(void); | 
|---|
| 183 | void parseMetaClass(void); | 
|---|
| 184 | void parseFileStem(void); | 
|---|
| 185 |  | 
|---|
| 186 | /* Emitters */ | 
|---|
| 187 | void emitHFile(GPtrArray* pInterfaceArray); | 
|---|
| 188 | void emitIHFile(GPtrArray* pInterfaceArray); | 
|---|
| 189 | void emitCFile(GPtrArray* pInterfaceArray); | 
|---|
| 190 |  | 
|---|
| 191 | /* Emitter support function */ | 
|---|
| 192 | void emitMethodParams(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray); | 
|---|
| 193 | void emitMethodParamsNoTypes(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray); | 
|---|
| 194 | void emitReturnType(PPARSEINFO pLocalPI, PINTERFACE pif, PMETHOD pm); | 
|---|
| 195 |  | 
|---|
| 196 | /* In printdata.c */ | 
|---|
| 197 | void printInterface(PINTERFACE pif); | 
|---|
| 198 | void printAllInterfacec(void); | 
|---|
| 199 |  | 
|---|
| 200 | PINTERFACE getParentInterface(PINTERFACE pif); | 
|---|
| 201 | PINTERFACE findInterfaceFromMethodName(PINTERFACE pif, gchar* chrName); | 
|---|
| 202 | PINTERFACE findInterfaceFromName(gchar* chrName); | 
|---|
| 203 | PMETHOD findMethodInfoFromMethodName(PINTERFACE pif, gchar* chrName); | 
|---|
| 204 | gboolean queryMessageReturnsAValue(PMETHOD pm); | 
|---|
| 205 |  | 
|---|
| 206 | #ifdef INCL_FILE | 
|---|
| 207 | FILE* openOutfile(GScanner *gScanner, gchar* chrOutName); | 
|---|
| 208 | void closeOutfile(FILE* pFile); | 
|---|
| 209 | #endif | 
|---|