source: trunk/idl-compiler/include/parser.h@ 287

Last change on this file since 287 was 287, checked in by cinc, 18 years ago

Implemented interface forward declaration.

File size: 7.4 KB
Line 
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 */
36void getNextToken(void);
37gboolean matchCur(GTokenType token);
38gboolean matchNext(GTokenType token);
39guint queryCurTokensKind(void);
40void printToken(GTokenType token);
41gboolean 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 */
48typedef 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 */
58typedef 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 */
67typedef 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 */
76typedef 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 */
84typedef 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
107typedef 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! */
125enum
126{
127 IDL_SYMBOL_INTERFACE=G_TOKEN_LAST+1,
128 IDL_SYMBOL_CLSVERSION,
129 IDL_SYMBOL_INSTANCEVAR,
130 IDL_SYMBOL_OVERRIDE,
131 IDL_SYMBOL_REGINTERFACE, /* Used for registered interfaces */
132 IDL_SYMBOL_CLSNAME,
133 IDL_SYMBOL_OLDMETACLASS,
134 IDL_SYMBOL_METACLASS,
135 IDL_SYMBOL_FILESTEM, /* Followed by the file name for output */
136 IDL_SYMBOL_NATIVE,
137 /* Some GLib types */
138 IDL_SYMBOL_GULONG, /* 275 */
139 IDL_SYMBOL_GINT,
140 IDL_SYMBOL_GPOINTER,
141 IDL_SYMBOL_GBOOLEAN,
142 IDL_SYMBOL_GCHAR,
143 IDL_SYMBOL_VOID,
144 /* Legacy support */
145 IDL_SYMBOL_BOOLEAN,
146 IDL_SYMBOL_STRING,
147 IDL_SYMBOL_LONG,
148 IDL_SYMBOL_UNSIGNED,
149 /* Direction of method parameters */
150 IDL_SYMBOL_IN,
151 IDL_SYMBOL_OUT,
152 IDL_SYMBOL_INOUT,
153 /* Preprocessor stuff (not yet supported by the compiler) */
154 IDL_SYMBOL_DEFINE,
155 IDL_SYMBOL_IFDEF,
156 IDL_SYMBOL_ENDIF
157};
158
159/* Specifies the kind of a token we read. For example we must
160 know if a read in indentifier is a type specification when
161 parsing method parameters. */
162enum
163{
164 KIND_UNKNOWN =1,
165 KIND_IDENTIFIER,
166 KIND_TYPESPEC, /* That's something like 'gint', 'gulong'... */
167 KIND_DIRECTION /* in, out, inout */
168};
169
170PINTERFACE findInterfaceFromName(gchar* chrName);
171
172void parseTypeSpec(PMETHODPARAM pMethodParam);
173void parseMethod(void);
174void parseInstanceVar(void);
175void parseInterface(GTokenType token);
176void parseClassVersion(void);
177void parseClassVersion(void);
178void parseOverrideMethod(void);
179void parseHash(void);
180void parsePreprocLineInfo(void);
181void parseMetaClass(void);
182void parseFileStem(void);
183
184/* Emitters */
185void emitHFile(GPtrArray* pInterfaceArray);
186void emitIHFile(GPtrArray* pInterfaceArray);
187
188/* Emitter support function */
189void emitMethodParams(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray);
190void emitMethodParamsNoTypes(PPARSEINFO pLocalPI, PINTERFACE pif, GPtrArray *pArray);
191void emitReturnType(PPARSEINFO pLocalPI, PINTERFACE pif, PMETHOD pm);
192
193/* In printdata.c */
194void printInterface(PINTERFACE pif);
195void printAllInterfacec(void);
196
197PINTERFACE getParentInterface(PINTERFACE pif);
198PINTERFACE findInterfaceFromMethodName(PINTERFACE pif, gchar* chrName);
199PINTERFACE findInterfaceFromName(gchar* chrName);
200PMETHOD findMethodInfoFromMethodName(PINTERFACE pif, gchar* chrName);
201
202#ifdef INCL_FILE
203FILE* openOutfile(GScanner *gScanner, gchar* chrOutName);
204void closeOutfile(FILE* pFile);
205#endif
Note: See TracBrowser for help on using the repository browser.