| 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 | GTokenType getNextTokenFromStream(void);
|
|---|
| 38 | gboolean matchCur(GTokenType token);
|
|---|
| 39 | gboolean matchNext(GTokenType token);
|
|---|
| 40 | guint queryCurTokensKind(void);
|
|---|
| 41 | void printToken(GTokenType token);
|
|---|
| 42 | void printToFile(GTokenType token);
|
|---|
| 43 | gboolean matchNextKind(guint uiKind);
|
|---|
| 44 | void moveToLine(guint toLine);
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | #define IDL_COMPILER_STRING "NOM compiler" /* Used inside warnings and errors */
|
|---|
| 48 | #define ID_SCOPE 0
|
|---|
| 49 |
|
|---|
| 50 | #if 0
|
|---|
| 51 | /* Holding an overriden method */
|
|---|
| 52 | typedef struct
|
|---|
| 53 | {
|
|---|
| 54 | gchar* chrName; /* Name of this instance variable */
|
|---|
| 55 | gchar* chrIntroducingIFace;
|
|---|
| 56 | }OVERMETHOD, *POVERMETHOD;
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | #define PARM_DIRECTION_IN 1
|
|---|
| 60 | #define PARM_DIRECTION_OUT 2
|
|---|
| 61 | #define PARM_DIRECTION_INOUT 3
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | /* Holding a method parameter */
|
|---|
| 65 | typedef struct
|
|---|
| 66 | {
|
|---|
| 67 | guint uiDirection; /* in|out|inout */
|
|---|
| 68 | gchar* chrType; /* Type e.g. gulong or GtkWidget */
|
|---|
| 69 | guint uiStar; /* incremented for each '*' */
|
|---|
| 70 | gchar* chrName;
|
|---|
| 71 | }METHODPARAM, *PMETHODPARAM;
|
|---|
| 72 |
|
|---|
| 73 | /* Holding a method */
|
|---|
| 74 | typedef struct
|
|---|
| 75 | {
|
|---|
| 76 | gchar* chrRetType; /* Type e.g. gulong or GtkWidget */
|
|---|
| 77 | gchar* chrName;
|
|---|
| 78 | METHODPARAM mpReturn; /* We don't use all fields of this struct */
|
|---|
| 79 | GPtrArray *pParamArray;
|
|---|
| 80 | }METHOD, *PMETHOD;
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 | /* Info about a symbol */
|
|---|
| 84 | typedef struct
|
|---|
| 85 | {
|
|---|
| 86 | gchar* chrSymbolName;
|
|---|
| 87 | guint uiSymbolToken;
|
|---|
| 88 | guint uiKind;
|
|---|
| 89 | }SYMBOL, *PSYMBOL;
|
|---|
| 90 |
|
|---|
| 91 | /* Struct holding all the info of a defined or declared interface */
|
|---|
| 92 | typedef struct
|
|---|
| 93 | {
|
|---|
| 94 | gchar* chrName; /* Name of this interface */
|
|---|
| 95 | gchar* chrParent; /* Name of parent interface */
|
|---|
| 96 | #if 0
|
|---|
| 97 | gulong ulMajor; /* Class version */
|
|---|
| 98 | gulong ulMinor; /* Class version */
|
|---|
| 99 | #endif
|
|---|
| 100 | gboolean fIsForwardDeclaration;
|
|---|
| 101 | PSYMBOL pSymbolIFace; /* Found interfaces are registered as a symbol with the parser.
|
|---|
| 102 | This is a pointer to the registered struct holding the necessary
|
|---|
| 103 | info and may be used to deregister a symbol later.*/
|
|---|
| 104 | PSYMBOL pSymbolIFacePtr; /* Same as before but for the pointer on an interface which is
|
|---|
| 105 | registered automatically. */
|
|---|
| 106 | gboolean fIsInRootFile;
|
|---|
| 107 | #if 0
|
|---|
| 108 | gchar* chrMetaClass; /* Pointer to metaclass name or NULL*/
|
|---|
| 109 | char* chrFileStem; /* Holding output filestem */
|
|---|
| 110 | #endif
|
|---|
| 111 | char* chrSourceFileName; /* The preprocessor includes files for us. This is the info
|
|---|
| 112 | about the file this interface is defined in. */
|
|---|
| 113 | GPtrArray *pMethodArray;
|
|---|
| 114 | #if 0
|
|---|
| 115 | GPtrArray *pOverrideArray;
|
|---|
| 116 | GPtrArray *pInstanceVarArray;
|
|---|
| 117 | #endif
|
|---|
| 118 | }INTERFACE,*PINTERFACE;
|
|---|
| 119 |
|
|---|
| 120 | typedef struct
|
|---|
| 121 | {
|
|---|
| 122 | PINTERFACE pCurInterface; /* The interface we are currently parsing. This is a working pointer. */
|
|---|
| 123 | PINTERFACE pClassDefinition; /* The definition from the IDL file of the interface we are currently
|
|---|
| 124 | parsing. This is used to check for correctness. */
|
|---|
| 125 | guint uiCurSymbolKind; /* This may be e.g. KIND_TYPESPEC */
|
|---|
| 126 | GTree* pSymbolTree; /* Our introduced symbols */
|
|---|
| 127 | GPtrArray* pInterfaceArray; /* The pointer array holding the interfaces we found */
|
|---|
| 128 | guint uiLineCorrection; /* This is the value used for correcting the line number known to the
|
|---|
| 129 | scanner. The actual line number is put by the preprocessor into
|
|---|
| 130 | the source file. It's used to calculate proper line numbers
|
|---|
| 131 | for errors. */
|
|---|
| 132 | guint uiCurFileLine; /* The line in the output file we are printing to */
|
|---|
| 133 | guint uiCurPos; /* The cursor position in the current line */
|
|---|
| 134 | guint uiTokenPos; /* Position of just gathered token on the line starting with 0 */
|
|---|
| 135 | guint uiTokenLine;
|
|---|
| 136 |
|
|---|
| 137 | gboolean fPrintToken;
|
|---|
| 138 | char* chrRootSourceFile; /* File we are intending to parse. Others may get included. */
|
|---|
| 139 | char* chrCurrentSourceFile;/* The preprocessor includes files for us. This is the info
|
|---|
| 140 | about their name. */
|
|---|
| 141 | char* chrOutfilePath; /* This is only the path, no filename */
|
|---|
| 142 | FILE* outFile; /* Output file handle */
|
|---|
| 143 | }PARSEINFO, *PPARSEINFO;
|
|---|
| 144 |
|
|---|
| 145 | /* Symbols defined for our IDL language.
|
|---|
| 146 | Keep these enums in sync with the order of the idlSymbols struct! */
|
|---|
| 147 | enum
|
|---|
| 148 | {
|
|---|
| 149 | IDL_SYMBOL_INTERFACE=G_TOKEN_LAST+1,
|
|---|
| 150 | NOMC_SYMBOL_CLASS,
|
|---|
| 151 | NOMC_SYMBOL_IMPL,
|
|---|
| 152 | IDL_SYMBOL_INSTANCEVAR,
|
|---|
| 153 | IDL_SYMBOL_OVERRIDE2,
|
|---|
| 154 | IDL_SYMBOL_REGINTERFACE, /* Used for registered interfaces */
|
|---|
| 155 | IDL_SYMBOL_CLSNAME,
|
|---|
| 156 | IDL_SYMBOL_OLDMETACLASS,
|
|---|
| 157 | IDL_SYMBOL_METACLASS,
|
|---|
| 158 | IDL_SYMBOL_FILESTEM, /* Followed by the file name for output */
|
|---|
| 159 | IDL_SYMBOL_NATIVE,
|
|---|
| 160 | /* Some GLib types */
|
|---|
| 161 | IDL_SYMBOL_GULONG, /* 275 */
|
|---|
| 162 | IDL_SYMBOL_GINT,
|
|---|
| 163 | IDL_SYMBOL_GPOINTER,
|
|---|
| 164 | IDL_SYMBOL_GBOOLEAN,
|
|---|
| 165 | IDL_SYMBOL_GCHAR,
|
|---|
| 166 | IDL_SYMBOL_VOID,
|
|---|
| 167 | /* Legacy support */
|
|---|
| 168 | IDL_SYMBOL_BOOLEAN,
|
|---|
| 169 | IDL_SYMBOL_STRING,
|
|---|
| 170 | IDL_SYMBOL_LONG,
|
|---|
| 171 | IDL_SYMBOL_UNSIGNED,
|
|---|
| 172 | /* Direction of method parameters */
|
|---|
| 173 | IDL_SYMBOL_IN,
|
|---|
| 174 | IDL_SYMBOL_OUT,
|
|---|
| 175 | IDL_SYMBOL_INOUT,
|
|---|
| 176 | /* Preprocessor stuff (not yet supported by the compiler) */
|
|---|
| 177 | IDL_SYMBOL_DEFINE,
|
|---|
| 178 | IDL_SYMBOL_IFDEF,
|
|---|
| 179 | IDL_SYMBOL_ENDIF
|
|---|
| 180 | };
|
|---|
| 181 |
|
|---|
| 182 | /* Specifies the kind of a token we read. For example we must
|
|---|
| 183 | know if a read in indentifier is a type specification when
|
|---|
| 184 | parsing method parameters. */
|
|---|
| 185 | enum
|
|---|
| 186 | {
|
|---|
| 187 | KIND_UNKNOWN =1,
|
|---|
| 188 | KIND_IDENTIFIER,
|
|---|
| 189 | KIND_TYPESPEC, /* That's something like 'gint', 'gulong'... */
|
|---|
| 190 | KIND_DIRECTION /* in, out, inout */
|
|---|
| 191 | };
|
|---|
| 192 |
|
|---|
| 193 | PINTERFACE findInterfaceFromName(gchar* chrName);
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 | #define TST_NEXT_TOKEN_NOT_OK(token, msg) \
|
|---|
| 197 | if(!matchNext(token)) \
|
|---|
| 198 | { \
|
|---|
| 199 | getNextToken(); /* Make sure error references the correct token */ \
|
|---|
| 200 | g_scanner_unexp_token(gScanner, \
|
|---|
| 201 | token, \
|
|---|
| 202 | NULL, \
|
|---|
| 203 | NULL, \
|
|---|
| 204 | NULL, \
|
|---|
| 205 | msg, \
|
|---|
| 206 | TRUE); /* is_error */ \
|
|---|
| 207 | exit(1); \
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 | void parseHash(void);
|
|---|
| 212 | void parseClass(GTokenType token);
|
|---|
| 213 | void parseTypeSpec(PMETHODPARAM pMethodParam);
|
|---|
| 214 | void parseClassMethod(void);
|
|---|
| 215 | void parseCodeBlock(void);
|
|---|
| 216 | void parseInterface(GTokenType token);
|
|---|
| 217 | void parseInterfaceMethod(void);
|
|---|
| 218 |
|
|---|
| 219 | /* In printdata.c */
|
|---|
| 220 | void printInterface(PINTERFACE pif);
|
|---|
| 221 |
|
|---|
| 222 | void emitMethodImplHeader(PINTERFACE pif, PMETHOD pm);
|
|---|
| 223 |
|
|---|
| 224 | /* in utils.c */
|
|---|
| 225 | void cleanupAndExit(int iExitCode);
|
|---|
| 226 | PINTERFACE findInterfaceForMethod(PINTERFACE pStartInterface, gchar* chrMethodName);
|
|---|
| 227 | PINTERFACE getParentInterface(PINTERFACE pif);
|
|---|
| 228 | PMETHOD findMethodInfoFromMethodName(PINTERFACE pif, gchar* chrName);
|
|---|
| 229 | PMETHOD findMethodInfoFromMethodNameWithCurrent(PINTERFACE pif, gchar* chrName);
|
|---|
| 230 | void exitIfNotMatchNext(GTokenType token, gchar* msg);
|
|---|
| 231 | void exitIfNotMatchNextKind(guint uiKind, gchar* msg);
|
|---|
| 232 |
|
|---|
| 233 | #if 0
|
|---|
| 234 | void parseInstanceVar(void);
|
|---|
| 235 |
|
|---|
| 236 | void parseClassVersion(void);
|
|---|
| 237 | void parseClassVersion(void);
|
|---|
| 238 | void parseOverrideMethod(void);
|
|---|
| 239 | void parseOverrideMethodFromIdentifier(void);
|
|---|
| 240 | void parsePreprocLineInfo(void);
|
|---|
| 241 | void parseMetaClass(void);
|
|---|
| 242 | void parseFileStem(void);
|
|---|
| 243 |
|
|---|
| 244 | /* Emitters */
|
|---|
| 245 | void emitHFile(GPtrArray* pInterfaceArray);
|
|---|
| 246 | void emitIHFile(GPtrArray* pInterfaceArray);
|
|---|
| 247 | void emitCFile(GPtrArray* pInterfaceArray);
|
|---|
| 248 |
|
|---|
| 249 | /* Emitter support function */
|
|---|
| 250 | void emitMethodParams(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray);
|
|---|
| 251 | void emitMethodParamsNoTypes(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray);
|
|---|
| 252 | void emitReturnType(PPARSEINFO pLocalPI, PINTERFACE pif, PMETHOD pm);
|
|---|
| 253 |
|
|---|
| 254 | /* In printdata.c */
|
|---|
| 255 | void printInterface(PINTERFACE pif);
|
|---|
| 256 | void printAllInterfacec(void);
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 | PINTERFACE findInterfaceFromMethodName(PINTERFACE pif, gchar* chrName);
|
|---|
| 260 | PINTERFACE findInterfaceFromName(gchar* chrName);
|
|---|
| 261 | PMETHOD findMethodInfoFromMethodName(PINTERFACE pif, gchar* chrName);
|
|---|
| 262 | gboolean queryMessageReturnsAValue(PMETHOD pm);
|
|---|
| 263 | #endif
|
|---|
| 264 |
|
|---|
| 265 | #ifdef INCL_FILE
|
|---|
| 266 | FILE* openOutfile(GScanner *gScanner, gchar* chrOutName);
|
|---|
| 267 | void closeOutfile(FILE* pFile);
|
|---|
| 268 | #endif
|
|---|