Changeset 266 for trunk/idl-compiler
- Timestamp:
- Mar 25, 2007, 1:07:25 AM (18 years ago)
- Location:
- trunk/idl-compiler
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/idl-compiler/Makefile
r264 r266 59 59 60 60 61 $(OBJDIR)/%.o: $(CDIR)/%.c 61 $(OBJDIR)/%.o: $(CDIR)/%.c $(INCDIR)/parser.h 62 62 $(CC) -I $(INC) $(CFLAGS) -o$@ $< 63 63 64 $(OBJDIR)/%.o: $(PARSERDIR)/%.c 64 $(OBJDIR)/%.o: $(PARSERDIR)/%.c $(INCDIR)/parser.h 65 65 $(CC) -I $(INC) $(CFLAGS) -o$@ $< 66 66 -
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 -
trunk/idl-compiler/include/parser.h
r265 r266 46 46 47 47 #define IDL_COMPILER_STRING "IDL compiler" /* Used inside warnings and errors */ 48 #define ID_SCOPE 0 48 49 49 50 /* Holding an overriden method */ … … 127 128 IDL_SYMBOL_INSTANCEVAR, 128 129 IDL_SYMBOL_OVERRIDE, 130 IDL_SYMBOL_REGINTERFACE, /* Used for registered interfaces */ 131 IDL_SYMBOL_NATIVE, 129 132 /* Some GLib types */ 130 133 IDL_SYMBOL_GULONG, /* 275 */ … … 132 135 IDL_SYMBOL_GPOINTER, 133 136 IDL_SYMBOL_GBOOLEAN, 137 IDL_SYMBOL_GCHAR, 138 IDL_SYMBOL_VOID, 134 139 /* Direction of method parameters */ 135 140 IDL_SYMBOL_IN, -
trunk/idl-compiler/parser_c/interface_parser.c
r265 r266 45 45 /* The pointer array holding the interfaces we found */ 46 46 extern GPtrArray* pInterfaceArray; 47 47 extern PARSEINFO parseInfo; 48 49 static void registerInterface(void) 50 { 51 PSYMBOL pNewSymbol=g_malloc0(sizeof(SYMBOL)); 52 53 g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface); 54 55 /* Any found interface is registered as a new type so it can be 56 used in other classes. */ 57 pNewSymbol->chrSymbolName=g_strdup(pCurInterface->chrName); /* We create a copy here because 58 when cleaning up the symbol space 59 the string will be freed. */ 60 pNewSymbol->uiKind=KIND_TYPESPEC; 61 pNewSymbol->uiSymbolToken=IDL_SYMBOL_REGINTERFACE; 62 g_tree_insert(parseInfo.pSymbolTree, pNewSymbol, pNewSymbol->chrSymbolName); 63 g_scanner_scope_add_symbol(gScanner, ID_SCOPE, pNewSymbol->chrSymbolName, 64 pNewSymbol); 65 } 48 66 49 67 static PINTERFACE createInterfaceStruct() … … 178 196 interface is already defined. 179 197 180 IS:= G_TOKEN_INDENTIFIER IB2 198 IS:= G_TOKEN_SYMBOL IB2 199 200 It's G_TOKEN_SYMBOL here because every found interface is registered 201 as a new symbol with GScanner. 181 202 */ 182 203 static void parseSubclassedIFace() 183 204 { 205 PSYMBOL pCurSymbol; 184 206 185 207 /* Parent interface */ 186 if(!matchNext(G_TOKEN_ IDENTIFIER))187 { 188 g_scanner_unexp_token(gScanner, 189 G_TOKEN_ IDENTIFIER,190 NULL, 191 NULL, 192 NULL, 193 "Parent interface name is missing .",208 if(!matchNext(G_TOKEN_SYMBOL)) 209 { 210 g_scanner_unexp_token(gScanner, 211 G_TOKEN_SYMBOL, 212 NULL, 213 NULL, 214 NULL, 215 "Parent interface name is missing or unknown.", 194 216 TRUE); /* is_error */ 195 217 exit(1); 196 218 } 197 219 GTokenValue value=gScanner->value; 198 pCurInterface->chrParent=g_strdup(value.v_identifier); 220 /* Make sure it's the correct symbol */ 221 pCurSymbol=value.v_symbol; 222 223 if(IDL_SYMBOL_REGINTERFACE!=pCurSymbol->uiSymbolToken) 224 { 225 g_scanner_unexp_token(gScanner, 226 G_TOKEN_SYMBOL, 227 NULL, 228 NULL, 229 NULL, 230 "Parent interface name is unknown.", 231 TRUE); /* is_error */ 232 exit(1); 233 } 234 pCurInterface->chrParent=g_strdup(pCurSymbol->chrSymbolName); 199 235 200 236 /* Check if the parent interface is known. */ … … 209 245 TRUE); /* is_error */ 210 246 exit(1); 211 212 247 } 213 248 … … 238 273 interface:= I ';' // Forward declaration 239 274 | I '{' IB '}' 240 | I ':' G_TOKEN_INDENTIFIER '{' IB '}' 275 | I ':' G_TOKEN_SYMBOL '{' IB '}' 276 277 It's G_TOKEN_SYMBOL here because every found interface is registered 278 as a new symbol with GScanner. 241 279 */ 242 280 void parseInterface(GTokenType token) … … 246 284 /* Get the interface name */ 247 285 parseIFace(token); 286 /* It's save to register the interface right here even if the struct is almost empty. 287 If anything goes wrong later we will exit anyway. */ 288 registerInterface(); 248 289 249 290 if(matchNext(';')) 250 291 { 251 292 pCurInterface->fIsForwardDeclaration=TRUE; 252 g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);253 254 293 } 255 294 else if(matchNext(':')) 256 295 { 257 296 parseSubclassedIFace(); 258 g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);259 297 } 260 298 else if(matchNext('{')) 261 299 { 262 300 parseIFaceBody(); 263 g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface);264 301 } 265 302 else -
trunk/idl-compiler/parser_c/lineinfo_parser.c
r264 r266 40 40 41 41 extern GScanner *gScanner; 42 42 extern PARSEINFO parseInfo; 43 43 44 44 /* … … 50 50 { 51 51 GTokenValue value; 52 PSYMBOLINFO psi=(PSYMBOLINFO)gScanner->user_data;53 52 54 53 /* Line number */ 55 54 value=gScanner->value; 56 p si->uiLineCorrection=value.v_int;55 parseInfo.uiLineCorrection=g_scanner_cur_line(gScanner)-value.v_int+1; 57 56 58 57 if(!matchNext(G_TOKEN_STRING)) … … 70 69 71 70 /* Current source file */ 72 if(p si->chrCurrentSourceFile)73 g_free(p si->chrCurrentSourceFile);71 if(parseInfo.chrCurrentSourceFile) 72 g_free(parseInfo.chrCurrentSourceFile); 74 73 75 74 value=gScanner->value; 76 p si->chrCurrentSourceFile=g_strdup(value.v_string);75 parseInfo.chrCurrentSourceFile=g_strdup(value.v_string); 77 76 78 77 /* Trailing file include level info isn't used for now. Note that for the root
Note:
See TracChangeset
for help on using the changeset viewer.