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

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

Started work on an IDL compiler

File size: 7.3 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
87
88gchar* getTypeSpecStringFromCurToken(void)
89{
90 GTokenValue value;
91
92 if(G_TOKEN_IDENTIFIER==curToken)
93 return g_strdup(value.v_identifier);
94 else
95 {
96 /* It's one of our symbols. */
97 PSYMBOLINFO psi;
98
99 if(curToken<=G_TOKEN_LAST)
100 g_scanner_unexp_token(gScanner,
101 G_TOKEN_SYMBOL,
102 NULL,
103 NULL,
104 NULL,
105 "Error in NOMINSTANCEVAR()",
106 TRUE); /* is_error */
107
108 psi=(PSYMBOLINFO)gScanner->user_data;
109 return psi->pSymbols[curToken-G_TOKEN_LAST-1].chrSymbolName;
110 }
111}
112
113void parseIt()
114{
115
116}
117
118
119/*
120 Main entry point. This function is called from the EMX wrapper. Be aware that gtk_init()
121 is already called in the wrapper.
122 */
123int main(int argc, char **argv)
124{
125 int a;
126 int fd;
127
128 int idScope=0;
129
130 if(argc<2)
131 return 1;
132
133 for(a=0; a<argc; a++)
134 {
135 g_message("arg %d: %s", a, argv[a]);
136 }
137
138 fd=open(argv[1], O_RDONLY);
139
140 if(-1==fd)
141 {
142 g_message("Can't open input file %s", argv[1]);
143 exit(1);
144 }
145
146 g_printf("\n");
147
148 gScanner=g_scanner_new(NULL);
149 gScanner->user_data=(gpointer)&curSymbol;
150 curSymbol.pSymbols=idlSymbols;
151
152 pInterfaceArray=g_ptr_array_new();
153
154 g_scanner_input_file(gScanner, fd);
155 /* No single line comments */
156 gScanner->config->skip_comment_single=FALSE;
157 gScanner->config->cpair_comment_single="";
158 gScanner->input_name=IDL_COMPILER_STRING;
159
160 g_scanner_set_scope(gScanner, idScope);
161 /* Load our own symbols into the scanner. We use the defualt scope for now. */
162 while(pSymbols->chrSymbolName)
163 {
164 g_scanner_scope_add_symbol(gScanner, idScope, pSymbols->chrSymbolName, GINT_TO_POINTER(pSymbols->uiSymbolToken));
165 pSymbols++;
166 }
167 gScanner->config->symbol_2_token=TRUE;
168
169 while(g_scanner_peek_next_token(gScanner) != G_TOKEN_EOF) {
170 /* get the next token */
171 GTokenType token;
172 curToken=g_scanner_get_next_token(gScanner);
173 token=curToken;
174 GTokenValue value=gScanner->value;
175
176 switch(curToken)
177 {
178 case IDL_SYMBOL_INTERFACE:
179 parseInterface(token);
180 break;
181 case G_TOKEN_IDENTIFIER:
182 g_message("Token: %d (G_TOKEN_IDENTIFIER)\t\t%s", token, value.v_identifier);
183 break;
184 case G_TOKEN_STRING:
185 g_message("Token: %d (G_TOKEN_STRING)\t\t\t%s", token, value.v_string);
186 break;
187 case G_TOKEN_LEFT_PAREN:
188 g_message("Token: %d (G_TOKEN_LEFT_PAREN)\t\t(", token);
189 break;
190 case G_TOKEN_RIGHT_PAREN:
191 g_message("Token: %d (G_TOKEN_RIGHT_PAREN)\t\t)", token);
192 break;
193 case ':':
194 g_message("Token: %d (colon)\t\t:", token);
195 break;
196 case ';':
197 g_message("Token: %d (semicolon)\t\t\t;", token);
198 break;
199 case '#':
200 g_message("Token: %d (hash)\t\t\t#", token);
201 break;
202 case '/':
203 g_message("Token: %d (slash)\t\t\t/ %s", token, value.v_comment);
204 break;
205 case G_TOKEN_COMMA:
206 g_message("Token: %d (G_TOKEN_COMMA)\t\t\t,", token);
207 break;
208 case G_TOKEN_INT:
209 g_message("Token: %d (G_TOKEN_INT)\t\t\t%ld", token, value.v_int);
210 break;
211 case IDL_SYMBOL_DEFINE:
212 g_message("Token: %d (IDL_SYMBOL_DEFINE)\t\t\t", token);
213 break;
214 case IDL_SYMBOL_IFDEF:
215 g_message("Token: %d (IDL_SYMBOL_IFDEF)\t\t\t", token);
216 break;
217 case IDL_SYMBOL_ENDIF:
218 g_message("Token: %d (IDL_SYMBOL_ENDIF)\t\t\t", token);
219 break;
220 default:
221 g_message("Token: %d (---)\t\t\t%c (LINE %d)", token, token, g_scanner_cur_line(gScanner));
222 break;
223 }
224 }
225 if(pCurInterface)
226 printInterface();
227
228 g_scanner_destroy(gScanner);
229 close(fd);
230
231 return 0;
232}
233
234#if 0
235 /* We are a folder somwhere in the chain */
236 nomRetval=WPFileSystem_wpQueryFileName((WPFileSystem*)wpParent, bFullPath, NULLHANDLE);
237
238 nomRetval=wpParent.wpQueryFileName(bFullPath, NULLHANDLE);
239
240 nomPath=NOMPathNew();
241 nomPath= (PNOMPath) NOMPath_assignCString(nomPath, _pszFullPath, ev);
242
243 return (PNOMPath)NOMPath_appendPath(nomRetval, nomPath, NULLHANDLE);
244
245#endif
Note: See TracBrowser for help on using the repository browser.