source: trunk/idl-compiler/c/nom-idl-compiler.c@ 261

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

More work on the IDL compiler

File size: 7.6 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#define INCL_DOSPROCESS
35#define INCL_DOS
36#define INCL_DOSPROFILE
37#define INCL_DOSERRORS
38
39#include <os2.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43
44#include <io.h>
45#include <fcntl.h>
46#include <sys\stat.h>
47
48#include <glib.h>
49#include <glib/gprintf.h>
50
51#include "nom.h"
52#include "nomtk.h"
53
54#include "parser.h"
55
56/* The pointer array holding the interfaces we found */
57GPtrArray* pInterfaceArray;
58
59/* Symbols defined for our IDL language.
60 Keep this in synch with the defined enums! */
61const SYMBOL idlSymbols[]={
62 {"interface", IDL_SYMBOL_INTERFACE, KIND_UNKNOWN}, /* 71 */
63 {"NOMCLASSVERSION", IDL_SYMBOL_CLSVERSION, KIND_UNKNOWN},
64 {"NOMINSTANCEVAR", IDL_SYMBOL_INSTANCEVAR, KIND_UNKNOWN},
65 {"NOMOVERRIDE", IDL_SYMBOL_OVERRIDE, KIND_UNKNOWN},
66 {"gulong", IDL_SYMBOL_GULONG, KIND_TYPESPEC},
67 {"gint", IDL_SYMBOL_GINT, KIND_TYPESPEC},
68 {"gpointer", IDL_SYMBOL_GPOINTER, KIND_TYPESPEC},
69 {"gboolean", IDL_SYMBOL_GBOOLEAN, KIND_TYPESPEC},
70 {"in", IDL_SYMBOL_IN, KIND_DIRECTION},
71 {"out", IDL_SYMBOL_OUT, KIND_DIRECTION},
72 {"inout", IDL_SYMBOL_INOUT, KIND_DIRECTION},
73 {"define", IDL_SYMBOL_DEFINE, KIND_UNKNOWN},
74 {"ifdef", IDL_SYMBOL_IFDEF, KIND_UNKNOWN},
75 {"endif", IDL_SYMBOL_ENDIF, KIND_UNKNOWN},
76 {NULL, 0, KIND_UNKNOWN}
77},*pSymbols=idlSymbols;
78
79GScanner *gScanner;
80GTokenType curToken=G_TOKEN_EOF;
81PINTERFACE pCurInterface=NULL;
82
83/* Holding info about current token. Referenced by gScanner. */
84SYMBOLINFO curSymbol;
85
86
87PINTERFACE findInterfaceFromName(gchar* chrName)
88{
89 int a;
90
91 for(a=0;a<pInterfaceArray->len;a++)
92 {
93 PINTERFACE pif=g_ptr_array_index(pInterfaceArray, a);
94 if(!strcmp(chrName, pif->chrName))
95 return pif;
96 }
97
98 return NULL;
99}
100
101
102gchar* getTypeSpecStringFromCurToken(void)
103{
104 GTokenValue value;
105
106 if(G_TOKEN_IDENTIFIER==curToken)
107 return g_strdup(value.v_identifier);
108 else
109 {
110 /* It's one of our symbols. */
111 PSYMBOLINFO psi;
112
113 if(curToken<=G_TOKEN_LAST)
114 g_scanner_unexp_token(gScanner,
115 G_TOKEN_SYMBOL,
116 NULL,
117 NULL,
118 NULL,
119 "Error in NOMINSTANCEVAR()",
120 TRUE); /* is_error */
121
122 psi=(PSYMBOLINFO)gScanner->user_data;
123 return psi->pSymbols[curToken-G_TOKEN_LAST-1].chrSymbolName;
124 }
125}
126
127/**
128 This is the root parse function. Here starts the fun...
129 */
130void parseIt(void)
131{
132 while(g_scanner_peek_next_token(gScanner) != G_TOKEN_EOF) {
133 GTokenType token;
134
135 curToken=g_scanner_get_next_token(gScanner);
136 token=curToken;
137 GTokenValue value=gScanner->value;
138
139 switch(curToken)
140 {
141 case IDL_SYMBOL_INTERFACE:
142 parseInterface(token);
143 break;
144
145#if 0
146 case G_TOKEN_IDENTIFIER:
147 g_message("Token: %d (G_TOKEN_IDENTIFIER)\t\t%s", token, value.v_identifier);
148 break;
149 case G_TOKEN_STRING:
150 g_message("Token: %d (G_TOKEN_STRING)\t\t\t%s", token, value.v_string);
151 break;
152 case G_TOKEN_LEFT_PAREN:
153 g_message("Token: %d (G_TOKEN_LEFT_PAREN)\t\t(", token);
154 break;
155 case G_TOKEN_RIGHT_PAREN:
156 g_message("Token: %d (G_TOKEN_RIGHT_PAREN)\t\t)", token);
157 break;
158 case ':':
159 g_message("Token: %d (colon)\t\t:", token);
160 break;
161 case ';':
162 g_message("Token: %d (semicolon)\t\t\t;", token);
163 break;
164 case '#':
165 g_message("Token: %d (hash)\t\t\t#", token);
166 break;
167 case '/':
168 g_message("Token: %d (slash)\t\t\t/ %s", token, value.v_comment);
169 break;
170 case G_TOKEN_COMMA:
171 g_message("Token: %d (G_TOKEN_COMMA)\t\t\t,", token);
172 break;
173 case G_TOKEN_INT:
174 g_message("Token: %d (G_TOKEN_INT)\t\t\t%ld", token, value.v_int);
175 break;
176 case IDL_SYMBOL_DEFINE:
177 g_message("Token: %d (IDL_SYMBOL_DEFINE)\t\t\t", token);
178 break;
179 case IDL_SYMBOL_IFDEF:
180 g_message("Token: %d (IDL_SYMBOL_IFDEF)\t\t\t", token);
181 break;
182 case IDL_SYMBOL_ENDIF:
183 g_message("Token: %d (IDL_SYMBOL_ENDIF)\t\t\t", token);
184 break;
185#endif
186 default:
187 printToken(curToken);
188 // g_message("Token: %d (---)\t\t\t%c (LINE %d)", token, token, g_scanner_cur_line(gScanner));
189 break;
190 }
191 }
192}
193
194
195/*
196
197 */
198int main(int argc, char **argv)
199{
200 int a;
201 int fd;
202
203 int idScope=0;
204
205 if(argc<2)
206 return 1;
207
208 for(a=0; a<argc; a++)
209 {
210 g_message("arg %d: %s", a, argv[a]);
211 }
212
213 fd=open(argv[1], O_RDONLY);
214
215 if(-1==fd)
216 {
217 g_message("Can't open input file %s", argv[1]);
218 exit(1);
219 }
220
221 g_printf("\n");
222
223 gScanner=g_scanner_new(NULL);
224 gScanner->user_data=(gpointer)&curSymbol;
225 curSymbol.pSymbols=idlSymbols;
226
227 pInterfaceArray=g_ptr_array_new();
228
229 g_scanner_input_file(gScanner, fd);
230 /* No single line comments */
231 gScanner->config->skip_comment_single=FALSE;
232 gScanner->config->cpair_comment_single="";
233 /* This string is used in error messages of the parser */
234 gScanner->input_name=IDL_COMPILER_STRING;
235
236 g_scanner_set_scope(gScanner, idScope);
237 /* Load our own symbols into the scanner. We use the default scope for now. */
238 while(pSymbols->chrSymbolName)
239 {
240 g_scanner_scope_add_symbol(gScanner, idScope, pSymbols->chrSymbolName, GINT_TO_POINTER(pSymbols->uiSymbolToken));
241 pSymbols++;
242 }
243 gScanner->config->symbol_2_token=TRUE;
244
245 parseIt();
246
247 if(pInterfaceArray->len)
248 printInterface();
249
250 g_scanner_destroy(gScanner);
251 close(fd);
252
253 return 0;
254}
255
256#if 0
257 /* We are a folder somwhere in the chain */
258 nomRetval=WPFileSystem_wpQueryFileName((WPFileSystem*)wpParent, bFullPath, NULLHANDLE);
259
260 nomRetval=wpParent.wpQueryFileName(bFullPath, NULLHANDLE);
261
262 nomPath=NOMPathNew();
263 nomPath= (PNOMPath) NOMPath_assignCString(nomPath, _pszFullPath, ev);
264
265 return (PNOMPath)NOMPath_appendPath(nomRetval, nomPath, NULLHANDLE);
266
267#endif
Note: See TracBrowser for help on using the repository browser.