Changeset 261
- Timestamp:
- Mar 24, 2007, 12:51:37 AM (18 years ago)
- Location:
- trunk/idl-compiler
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/idl-compiler/c/nom-idl-compiler.c
r260 r261 85 85 86 86 87 PINTERFACE 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 87 101 88 102 gchar* getTypeSpecStringFromCurToken(void) … … 111 125 } 112 126 113 void 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. 127 /** 128 This is the root parse function. Here starts the fun... 122 129 */ 123 int 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 130 void parseIt(void) 131 { 169 132 while(g_scanner_peek_next_token(gScanner) != G_TOKEN_EOF) { 170 /* get the next token */171 133 GTokenType token; 134 172 135 curToken=g_scanner_get_next_token(gScanner); 173 136 token=curToken; … … 179 142 parseInterface(token); 180 143 break; 144 145 #if 0 181 146 case G_TOKEN_IDENTIFIER: 182 147 g_message("Token: %d (G_TOKEN_IDENTIFIER)\t\t%s", token, value.v_identifier); … … 218 183 g_message("Token: %d (IDL_SYMBOL_ENDIF)\t\t\t", token); 219 184 break; 185 #endif 220 186 default: 221 g_message("Token: %d (---)\t\t\t%c (LINE %d)", token, token, g_scanner_cur_line(gScanner)); 187 printToken(curToken); 188 // g_message("Token: %d (---)\t\t\t%c (LINE %d)", token, token, g_scanner_cur_line(gScanner)); 222 189 break; 223 190 } 224 191 } 225 if(pCurInterface) 192 } 193 194 195 /* 196 197 */ 198 int 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) 226 248 printInterface(); 227 249 -
trunk/idl-compiler/c/printdata.c
r259 r261 140 140 g_printf("Found Interface:\n"); 141 141 g_printf("\tName:\t\t%s\n", pif->chrName); 142 g_printf("\tParent:\t\t%s\n", (pif->chrParent ? pif->chrParent : "No parent")); 142 143 g_printf("\tMajor:\t\t%ld\n", pif->ulMajor); 143 144 g_printf("\tMinor:\t\t%ld\n", pif->ulMinor); -
trunk/idl-compiler/include/parser.h
r260 r261 136 136 }; 137 137 138 PINTERFACE findInterfaceFromName(gchar* chrName); 138 139 139 140 void parseTypeSpec(PMETHODPARAM pMethodParam); -
trunk/idl-compiler/parser_c/interface_parser.c
r259 r261 34 34 #include <os2.h> 35 35 #include <stdlib.h> 36 #include <string.h> 36 37 37 38 #include <glib.h> … … 65 66 | OV // Overriden method 66 67 */ 67 void parseI FaceBody(void)68 void parseIBody(void) 68 69 { 69 70 /* Current token is '{' */ … … 97 98 98 99 /* 100 Parse the interface name. 101 Note that the current token is the 'interface' keyword. 102 99 103 I:= IDL_SYMBOL_INTERFACE G_TOKEN_INDENTIFIER 100 104 */ … … 114 118 /* Save interface info */ 115 119 GTokenValue value=gScanner->value; 116 pCurInterface=createInterfaceStruct();117 120 pCurInterface->chrName=g_strdup(value.v_identifier); 118 121 } 119 122 120 123 /* 124 Current token is '{'. 125 126 IB2:= '{' IB '}' 127 | '{' IB '}' ';' 128 129 */ 130 static void parseIFaceBody(void) 131 { 132 parseIBody(); 133 if(!matchNext('}')) 134 { 135 g_scanner_unexp_token(gScanner, 136 '}', 137 NULL, 138 NULL, 139 NULL, 140 "No closing of 'interface' section.", 141 TRUE); /* is_error */ 142 exit(1); 143 } 144 /* Remove a terminating ';' from the input if present. */ 145 matchNext(';'); 146 } 147 148 /* 149 Parse an interface which is subclassed. This includes checking if the parent 150 interface is already defined. 151 152 IS:= G_TOKEN_INDENTIFIER IB2 153 */ 154 static void parseSubclassedIFace() 155 { 156 157 /* Parent interface */ 158 if(!matchNext(G_TOKEN_IDENTIFIER)) 159 { 160 g_scanner_unexp_token(gScanner, 161 G_TOKEN_IDENTIFIER, 162 NULL, 163 NULL, 164 NULL, 165 "Parent interface name is missing.", 166 TRUE); /* is_error */ 167 exit(1); 168 } 169 GTokenValue value=gScanner->value; 170 pCurInterface->chrParent=g_strdup(value.v_identifier); 171 172 /* Check if the parent interface is known. */ 173 if(!findInterfaceFromName(pCurInterface->chrParent)) 174 { 175 g_scanner_unexp_token(gScanner, 176 G_TOKEN_IDENTIFIER, 177 NULL, 178 NULL, 179 NULL, 180 "Parent interface in definition is unknown.", 181 TRUE); /* is_error */ 182 exit(1); 183 184 } 185 186 if(!matchNext('{')) 187 { 188 g_scanner_unexp_token(gScanner, 189 '{', 190 NULL, 191 NULL, 192 NULL, 193 "No opening brace in interface definition.", 194 TRUE); /* is_error */ 195 exit(1); 196 197 } 198 parseIFaceBody(); 199 } 200 201 /* 121 202 Parse an interface declaration. The current token is the 'interface' keyword. 203 204 interface:= I ';' // Forward declaration 205 | I IB2 206 | I ':' IS // Subclassed interface 207 208 This translates into: 122 209 123 210 interface:= I ';' // Forward declaration 124 211 | I '{' IB '}' 125 | I ':' G_TOKEN_INDENTIFIER '{' ID '}' 126 127 212 | I ':' G_TOKEN_INDENTIFIER '{' IB '}' 128 213 */ 129 214 void parseInterface(GTokenType token) 130 215 { 216 pCurInterface=createInterfaceStruct(); 217 218 /* Get the interface name */ 131 219 parseIFace(token); 132 getNextToken(); 133 switch(curToken) 134 { 135 case ';': 136 if(pCurInterface) 137 { 138 pCurInterface->fIsForwardDeclaration=TRUE; 139 g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface); 140 pCurInterface=NULL; 141 } 142 break; 143 case ':': 144 g_message("Line %d: Defining subclasses interfaces not supported yet", g_scanner_cur_line(gScanner)); 145 exit(0); 146 case '{': 220 221 if(matchNext(';')) 222 { 223 pCurInterface->fIsForwardDeclaration=TRUE; 224 g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface); 225 226 } 227 else if(matchNext(':')) 228 { 229 parseSubclassedIFace(); 230 g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface); 231 } 232 else if(matchNext('{')) 233 { 147 234 parseIFaceBody(); 148 235 g_ptr_array_add(pInterfaceArray, (gpointer) pCurInterface); 149 break; 150 default: 236 } 237 else 238 { 151 239 g_message("Line %d: Error in interface declaration", g_scanner_cur_line(gScanner)); 152 240 exit(0); 153 break;154 155 } 241 } 242 } 243
Note:
See TracChangeset
for help on using the changeset viewer.