Mercurial > projects > dil
comparison trunk/src/dil/Parser.d @ 530:4b783fa06277
Unindented if-block in parseVariableOrFunction().
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 17 Dec 2007 02:36:37 +0100 |
parents | 135e9e6933a7 |
children | 315aeb3f7a9b |
comparison
equal
deleted
inserted
replaced
529:135e9e6933a7 | 530:4b783fa06277 |
---|---|
447 ident = token.ident; | 447 ident = token.ident; |
448 nT(); | 448 nT(); |
449 } | 449 } |
450 else | 450 else |
451 { | 451 { |
452 type = parseType(); | 452 type = parseType(); // VariableType or ReturnType |
453 if (token.type == T.LParen) | 453 if (token.type == T.LParen) |
454 { | 454 { |
455 // C-style function pointers make the grammar ambiguous. | 455 // C-style function pointers make the grammar ambiguous. |
456 // We have to treat them specially at function scope. | 456 // We have to treat them specially at function scope. |
457 // Example: | 457 // Example: |
463 // } | 463 // } |
464 // // A pointer to a function taking no parameters and returning 'something'. | 464 // // A pointer to a function taking no parameters and returning 'something'. |
465 // something(*p); | 465 // something(*p); |
466 type = parseCFunctionPointerType(type, ident, optionalParameterList); | 466 type = parseCFunctionPointerType(type, ident, optionalParameterList); |
467 } | 467 } |
468 else | 468 else if (peekNext() == T.LParen) |
469 { | 469 { // Type FunctionName ( ParameterList ) FunctionBody |
470 ident = requireIdentifier(MSG.ExpectedFunctionName); | 470 ident = requireIdentifier(MSG.ExpectedFunctionName); |
471 // Type FunctionName ( ParameterList ) FunctionBody | 471 ident || nT(); // Skip non-identifier token. |
472 if (token.type == T.LParen) | 472 assert(token.type == T.LParen); |
473 // It's a function declaration | |
474 TemplateParameters tparams; | |
475 if (tokenAfterParenIs(T.LParen)) | |
473 { | 476 { |
474 // It's a function declaration | 477 // ( TemplateParameterList ) ( ParameterList ) |
475 TemplateParameters tparams; | 478 tparams = parseTemplateParameterList(); |
476 if (tokenAfterParenIs(T.LParen)) | 479 } |
477 { | 480 |
478 // ( TemplateParameterList ) ( ParameterList ) | 481 auto params = parseParameterList(); |
479 tparams = parseTemplateParameterList(); | 482 version(D2) |
480 } | 483 { |
481 | 484 switch (token.type) |
482 auto params = parseParameterList(); | |
483 version(D2) | |
484 { | 485 { |
485 switch (token.type) | 486 case T.Const: |
486 { | 487 stc |= StorageClass.Const; |
487 case T.Const: | 488 nT(); |
488 stc |= StorageClass.Const; | 489 break; |
489 nT(); | 490 case T.Invariant: |
490 break; | 491 stc |= StorageClass.Invariant; |
491 case T.Invariant: | 492 nT(); |
492 stc |= StorageClass.Invariant; | 493 break; |
493 nT(); | 494 default: |
494 break; | |
495 default: | |
496 } | |
497 } | 495 } |
498 // ReturnType FunctionName ( ParameterList ) | 496 } |
499 auto funcBody = parseFunctionBody(); | 497 // ReturnType FunctionName ( ParameterList ) |
500 auto d = new FunctionDeclaration(type, ident, tparams, params, funcBody); | 498 auto funcBody = parseFunctionBody(); |
501 d.setStorageClass(stc); | 499 auto d = new FunctionDeclaration(type, ident, tparams, params, funcBody); |
502 d.setLinkageType(linkType); | 500 d.setStorageClass(stc); |
503 d.setProtection(protection); | 501 d.setLinkageType(linkType); |
504 return set(d, begin); | 502 d.setProtection(protection); |
505 } | 503 return set(d, begin); |
506 type = parseDeclaratorSuffix(type); | 504 } |
507 } | 505 // Type VariableName DeclaratorSuffix |
506 ident = requireIdentifier(MSG.ExpectedVariableName); | |
507 type = parseDeclaratorSuffix(type); | |
508 } | 508 } |
509 | 509 |
510 // It's a variable declaration. | 510 // It's a variable declaration. |
511 Identifier*[] idents = [ident]; | 511 Identifier*[] idents = [ident]; |
512 Expression[] values; | 512 Expression[] values; |