Changeset 266 for trunk/idl-compiler/c/nom-idl-compiler.c
- Timestamp:
- Mar 25, 2007, 1:07:25 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/idl-compiler/c/nom-idl-compiler.c
r265 r266 83 83 {"NOMINSTANCEVAR", IDL_SYMBOL_INSTANCEVAR, KIND_UNKNOWN}, 84 84 {"NOMOVERRIDE", IDL_SYMBOL_OVERRIDE, KIND_UNKNOWN}, 85 {"NOMREGISTEREDIFACE", IDL_SYMBOL_REGINTERFACE, KIND_TYPESPEC}, 86 {"native", IDL_SYMBOL_NATIVE, KIND_UNKNOWN}, 85 87 {"gulong", IDL_SYMBOL_GULONG, KIND_TYPESPEC}, 86 88 {"gint", IDL_SYMBOL_GINT, KIND_TYPESPEC}, 87 89 {"gpointer", IDL_SYMBOL_GPOINTER, KIND_TYPESPEC}, 88 90 {"gboolean", IDL_SYMBOL_GBOOLEAN, KIND_TYPESPEC}, 91 {"gchar", IDL_SYMBOL_GCHAR, KIND_TYPESPEC}, 92 {"void", IDL_SYMBOL_VOID, KIND_TYPESPEC}, 89 93 {"in", IDL_SYMBOL_IN, KIND_DIRECTION}, 90 94 {"out", IDL_SYMBOL_OUT, KIND_DIRECTION}, … … 155 159 } 156 160 161 /* 162 The native keyword is used to introduce new types. That's coming 163 from the Corba spec. Maybe we will change that some time. 164 165 The current token is the 'native' keyword. 166 167 N:= G_TOKEN_SYMBOL IDENT ';' 168 */ 169 static void parseNative(void) 170 { 171 GTokenValue value; 172 PSYMBOL pCurSymbol=g_malloc0(sizeof(SYMBOL)); 173 174 if(!matchNext(G_TOKEN_IDENTIFIER)) 175 { 176 PSYMBOL pSymbol; 177 178 /* Check if it's a symbol. The following 'identifier' (word) is maybe alread 179 registered as a symbol. */ 180 if(!matchNext(G_TOKEN_SYMBOL)) 181 { 182 g_scanner_unexp_token(gScanner, 183 G_TOKEN_SYMBOL, 184 NULL, 185 NULL, 186 NULL, 187 "'native' statement is not followed by a valid identifier.", 188 TRUE); /* is_error */ 189 exit(1); 190 } 191 /* It's a symbol. Check if it's a typespec. */ 192 value=gScanner->value; 193 pSymbol=value.v_symbol; 194 if(!pSymbol || pSymbol->uiKind!=KIND_TYPESPEC) 195 { 196 g_scanner_unexp_token(gScanner, 197 G_TOKEN_SYMBOL, 198 NULL, 199 NULL, 200 NULL, 201 "'native' statement is not followed by a valid symbol.", 202 TRUE); /* is_error */ 203 exit(1); 204 } 205 } 206 207 value=gScanner->value; 208 pCurSymbol->chrSymbolName=g_strdup(value.v_identifier); 209 pCurSymbol->uiKind=KIND_TYPESPEC; 210 pCurSymbol->uiSymbolToken=G_TOKEN_NONE; 211 g_tree_insert(parseInfo.pSymbolTree, pCurSymbol, pCurSymbol->chrSymbolName); 212 g_scanner_scope_add_symbol(gScanner, ID_SCOPE, pCurSymbol->chrSymbolName, 213 pCurSymbol); 214 215 if(!matchNext(';')) 216 { 217 getNextToken(); /* Make sure error references the correct token */ 218 g_scanner_unexp_token(gScanner, 219 ';', 220 NULL, 221 NULL, 222 NULL, 223 "Error in 'native' definition , Missing semicolon", 224 TRUE); /* is_error */ 225 exit(1); 226 } 227 228 } 157 229 158 230 /** … … 180 252 case IDL_SYMBOL_INTERFACE: 181 253 parseInterface(token); 254 break; 255 case IDL_SYMBOL_NATIVE: 256 parseNative(); 182 257 break; 183 258 default: … … 226 301 default: 227 302 printToken(curToken); 228 // g_message("Token: %d (---)\t\t\t%c (LINE %d)", token, token, g_scanner_cur_line(gScanner));229 303 break; 230 304 } … … 246 320 } 247 321 322 /* 323 Compare function for the tree holding our private symbols. 324 */ 248 325 static gint funcSymbolCompare(gconstpointer a, gconstpointer b) 249 326 { … … 256 333 return 1; 257 334 }; 335 336 void funcMsgHandler(GScanner *gScanner, 337 gchar *message, 338 gboolean error) 339 { 340 341 g_printf("In file %s, line %d:\n\t%s\n", parseInfo.chrCurrentSourceFile, 342 g_scanner_cur_line(gScanner)-parseInfo.uiLineCorrection, message); 343 } 344 258 345 /* 259 346 … … 263 350 int a; 264 351 int fd; 265 int idScope=0; 352 266 353 GError *gError = NULL; 267 354 GOptionContext* gContext; … … 310 397 311 398 /* Create output file name */ 312 313 fd=open(argv[1], O_RDONLY); 399 if(!strcmp(argv[1], "-")) 400 fd=0; /* Read from stdin */ 401 else 402 fd=open(argv[1], O_RDONLY); 314 403 315 404 if(-1==fd) … … 327 416 curSymbol.pSymbols=idlSymbols; 328 417 418 gScanner->msg_handler=funcMsgHandler; 329 419 pInterfaceArray=g_ptr_array_new(); 330 420 … … 336 426 gScanner->input_name=IDL_COMPILER_STRING; 337 427 338 g_scanner_set_scope(gScanner, idScope);428 g_scanner_set_scope(gScanner, ID_SCOPE); 339 429 /* Load our own symbols into the scanner. We use the default scope for now. */ 340 430 parseInfo.pSymbolTree=g_tree_new((GCompareFunc) funcSymbolCompare); 341 431 while(pSymbols->chrSymbolName) 342 432 { 343 g_scanner_scope_add_symbol(gScanner, idScope, pSymbols->chrSymbolName, 433 #warning !!! Create a copy here so it is the same as with new symbols added later. 434 g_scanner_scope_add_symbol(gScanner, ID_SCOPE, pSymbols->chrSymbolName, 344 435 pSymbols); 345 436 g_tree_insert(parseInfo.pSymbolTree, pSymbols, pSymbols->chrSymbolName); … … 371 462 372 463 #endif 464 465 466 467 468 469 470 471 472
Note:
See TracChangeset
for help on using the changeset viewer.