Changeset 383 for trunk/nomc/parser_c
- Timestamp:
- Jul 2, 2008, 11:39:12 PM (17 years ago)
- Location:
- trunk/nomc/parser_c
- Files:
-
- 5 edited
-
class_parser.c (modified) (2 diffs)
-
classmethod_parser.c (modified) (1 diff)
-
interface_parser.c (modified) (1 diff)
-
interfacemethod_parser.c (modified) (1 diff)
-
typespec_parser.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/nomc/parser_c/class_parser.c
r382 r383 124 124 125 125 126 /*127 Function to parse the body of a class.128 Current token is '{'.129 130 CBODY:= '}' //This is an empty class body131 | CLASSMETHODS '}'132 */133 /*134 135 CLASSMETHODS:= CLASSMETHOD136 | CLASSMETHOD CLASSMETHODS137 */138 126 139 127 /* … … 142 130 143 131 CBODY:= '}' //This is an empty class body 144 | IMPLCLASSMETHODS '}'132 | CLASSMETHODS '}' 145 133 146 134 */ -
trunk/nomc/parser_c/classmethod_parser.c
r380 r383 138 138 139 139 140 141 142 static void doSingleMethodParam(void) 143 { 144 GTokenValue value; 145 PSYMBOL pCurSymbol; 146 147 PMETHODPARAM pParam; 148 pParam=g_malloc0(sizeof(METHODPARAM)); 149 150 /* Do direction */ 151 /* Direction */ 152 if(!matchNextKind(KIND_DIRECTION)) /* Be aware that we don't compare types here */ 153 { 154 pParam->uiDirection=PARM_DIRECTION_IN; 155 } 156 else 157 { 158 value=gScanner->value; 159 pCurSymbol=value.v_symbol; 160 switch(pCurSymbol->uiSymbolToken) 161 { 162 case IDL_SYMBOL_IN: 163 pParam->uiDirection=PARM_DIRECTION_IN; 164 break; 165 case IDL_SYMBOL_OUT: 166 pParam->uiDirection=PARM_DIRECTION_OUT; 167 break; 168 case IDL_SYMBOL_INOUT: 169 pParam->uiDirection=PARM_DIRECTION_INOUT; 170 break; 171 default: 172 break; 173 } 174 } 175 176 177 /* Do typespec */ 178 179 /* Do identifier */ 180 exitIfNotMatchNext(G_TOKEN_IDENTIFIER, "Error in method implementation."); 181 182 /* The current token is the identifier */ 183 value=gScanner->value; 184 pParam->chrName=g_strdup(value.v_identifier); 185 186 187 } 188 189 /* 190 191 MPARAMS := Ë)Ë 192 | MPARAM 193 | MPARAM ',' MPARAMS 194 */ 195 static void doMethodParams(PMETHOD pMethod) 196 { 197 198 while(g_scanner_peek_next_token(gScanner)!= G_TOKEN_EOF && g_scanner_peek_next_token(gScanner)!=')') 199 { 200 doSingleMethodParam(); 201 202 if(!matchNext(',')) 203 break; 204 } 205 exitIfNotMatchNext(')', "No closing of method parameter list."); 206 } 207 208 /* 209 210 MPARAM := TYPESPEC IDENT 211 212 */ 213 214 215 /* 216 Current token is the one just before the typespec. 217 218 METHOD := TYPESPEC IDENT '(' MPARAMS 219 220 */ 221 static void parseMethod(PMETHOD pMethod) 222 { 223 GTokenValue value; 224 PINTERFACE pif; 225 PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data; 226 227 /********* Parse typespec *******************************************/ 228 229 230 /********* Method identifier ****************************************/ 231 232 exitIfNotMatchNext(G_TOKEN_IDENTIFIER, "Error in method implementation."); 233 234 /* The current token is the identifier */ 235 value=gScanner->value; 236 pMethod->chrName=g_strdup(value.v_identifier); 237 238 /* Now check if the method was introduced by some parent. The interface struct contains 239 the parent name if any and the function will follow the chain of parents. */ 240 if((pif=findInterfaceForMethod(pParseInfo->pCurInterface, pMethod->chrName))!=NULL) 241 { 242 gchar* chrMessage; 243 chrMessage=g_strdup_printf("A method '%s' is already present in interface '%s'.", 244 pMethod->chrName, pif->chrName); 245 246 g_scanner_unexp_token(gScanner, 247 G_TOKEN_IDENTIFIER, 248 NULL, NULL, NULL, 249 chrMessage, 250 TRUE); /* is_error */ 251 cleanupAndExit(1); 252 } 253 254 /* Check if the method is defined at all */ 255 if(NULL==findMethodInfoFromMethodNameWithCurrent(pParseInfo->pClassDefinition, pMethod->chrName)) 256 { 257 gchar* chrMessage; 258 chrMessage=g_strdup_printf("Method '%s' is not defined for the current class or one of the parents.", 259 pMethod->chrName); 260 261 g_scanner_unexp_token(gScanner, 262 G_TOKEN_IDENTIFIER, 263 NULL, NULL, NULL, 264 chrMessage, 265 TRUE); /* is_error */ 266 cleanupAndExit(1); 267 268 } 269 270 /****** Method parameters ***************************************************/ 271 exitIfNotMatchNext('(', "Error in method implementation."); 272 273 /* Do parameters */ 274 275 } 276 277 /* 278 279 CLASSMETHODS:= CLASSMETHOD 280 | CLASSMETHOD CLASSMETHODS 281 282 CLASSMETHOD := IMPL METHOD 283 284 */ 285 static void parseSingleClassMethod(void) 286 { 287 GTokenValue value; 288 PSYMBOL pCurSymbol; 289 PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data; 290 PMETHOD pMethod=createMethodStruct(); 291 292 g_ptr_array_add( pParseInfo->pCurInterface->pMethodArray, (gpointer) pMethod); 293 294 /* Method implementations must start with "impl" which is registered as a symbol. Here we check if 295 the token is a symbol. */ 296 exitIfNotMatchNext(G_TOKEN_SYMBOL, "Method implementation must start with 'impl'."); 297 298 value=gScanner->value; 299 pCurSymbol=value.v_symbol; 300 301 /* Check if symbol is "impl". */ 302 if(!pCurSymbol || pCurSymbol->uiSymbolToken!=NOMC_SYMBOL_IMPL) 303 { 304 g_scanner_unexp_token(gScanner, 305 G_TOKEN_SYMBOL, 306 NULL, NULL, NULL, 307 "'impl'.", 308 TRUE); /* is_error */ 309 cleanupAndExit(1); 310 } 311 312 /* Parse method */ 313 parseMethod(pMethod); 314 315 } 316 317 /* 318 319 CLASSMETHODS:= IMPL METHOD 320 ^ | IMPL METHOD CLASSMETHODS 321 */ 322 void parseClassMethods(void) 323 { 324 do 325 { 326 PSYMBOL pCurSymbol; 327 GTokenValue value; 328 329 /* There must be at least one class method */ 330 parseSingleClassMethod(); 331 332 /* Any additional methods start with ËimplË */ 333 if(g_scanner_peek_next_token(gScanner)!=G_TOKEN_SYMBOL) 334 break; 335 336 value=gScanner->next_value; 337 pCurSymbol=value.v_symbol; 338 339 if(!pCurSymbol || pCurSymbol->uiSymbolToken!=NOMC_SYMBOL_IMPL) 340 break; 341 }while(g_scanner_peek_next_token(gScanner)!= G_TOKEN_EOF); 342 } 343 140 344 /* 141 345 Current token is the typespec. -
trunk/nomc/parser_c/interface_parser.c
r380 r383 143 143 //printToken(gScanner->token); 144 144 145 parse Method();145 parseInterfaceMethod(); 146 146 } 147 147 else if(matchNext('#')) -
trunk/nomc/parser_c/interfacemethod_parser.c
r380 r383 157 157 | TS G_TOKEN_IDENTIFIER '(' MPARMS ')' ';' // method 158 158 */ 159 void parse Method(void)159 void parseInterfaceMethod(void) 160 160 { 161 161 GTokenValue value; -
trunk/nomc/parser_c/typespec_parser.c
r380 r383 45 45 46 46 /* 47 Parse a typespec e.g. 'gulong' or 'gulong*'. 48 49 Current token is the one directly before the typespec. 50 Note: only single word typespecs are allowed. 51 52 TS:= TYPESPEC 53 | TYPESPEC '*' 54 55 */ 56 void parseTypeSpec2(PMETHODPARAM pMethodParam) 57 { 58 char *chrTemp; 59 60 exitIfNotMatchNextKind(KIND_TYPESPEC, "Expected return type specifier."); 61 62 /* Return type name */ 63 pMethodParam->chrType=getTypeSpecStringFromCurToken(); 64 65 /* Do we return a pointer (check for '*') */ 66 while(matchNext('*')) 67 pMethodParam->uiStar++; 68 } 69 70 71 /* 47 72 Parse a typespec e.g. 'gulong' or 'gulong*'. 48 73
Note:
See TracChangeset
for help on using the changeset viewer.
