Mercurial > projects > dil
comparison trunk/src/dil/parser/Parser.d @ 765:bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 16 Feb 2008 20:18:42 +0100 |
parents | c909a3d3fa52 |
children | 0af3b145a405 |
comparison
equal
deleted
inserted
replaced
764:4579e8505d5e | 765:bc812843603c |
---|---|
482 ident = requireIdentifier(MSG.ExpectedFunctionName); | 482 ident = requireIdentifier(MSG.ExpectedFunctionName); |
483 ident || nT(); // Skip non-identifier token. | 483 ident || nT(); // Skip non-identifier token. |
484 assert(token.kind == T.LParen); | 484 assert(token.kind == T.LParen); |
485 // It's a function declaration | 485 // It's a function declaration |
486 TemplateParameters tparams; | 486 TemplateParameters tparams; |
487 bool isTemplate; | |
487 if (tokenAfterParenIs(T.LParen)) | 488 if (tokenAfterParenIs(T.LParen)) |
488 { | 489 { // ( TemplateParameterList ) ( ParameterList ) |
489 // ( TemplateParameterList ) ( ParameterList ) | |
490 tparams = parseTemplateParameterList(); | 490 tparams = parseTemplateParameterList(); |
491 isTemplate = true; | |
491 } | 492 } |
492 | 493 |
493 auto params = parseParameterList(); | 494 auto params = parseParameterList(); |
494 version(D2) | 495 version(D2) |
495 { | 496 { |
506 default: | 507 default: |
507 } | 508 } |
508 } | 509 } |
509 // ReturnType FunctionName ( ParameterList ) | 510 // ReturnType FunctionName ( ParameterList ) |
510 auto funcBody = parseFunctionBody(); | 511 auto funcBody = parseFunctionBody(); |
511 auto d = new FunctionDeclaration(type, ident, tparams, params, funcBody); | 512 auto fd = new FunctionDeclaration(type, ident,/+ tparams,+/ params, funcBody); |
512 d.setStorageClass(stc); | 513 fd.setStorageClass(stc); |
513 d.setLinkageType(linkType); | 514 fd.setLinkageType(linkType); |
514 d.setProtection(protection); | 515 fd.setProtection(protection); |
515 return set(d, begin); | 516 if (isTemplate) |
517 { | |
518 auto d = putInsideTemplateDeclaration(begin, ident, fd, tparams); | |
519 d.setStorageClass(stc); | |
520 d.setProtection(protection); | |
521 return set(d, begin); | |
522 } | |
523 return set(fd, begin); | |
516 } | 524 } |
517 else | 525 else |
518 { | 526 { |
519 // Type VariableName DeclaratorSuffix | 527 // Type VariableName DeclaratorSuffix |
520 ident = requireIdentifier(MSG.ExpectedVariableName); | 528 ident = requireIdentifier(MSG.ExpectedVariableName); |
1018 error(token, MSG.ExpectedEnumBody, token.srcText); | 1026 error(token, MSG.ExpectedEnumBody, token.srcText); |
1019 | 1027 |
1020 return new EnumDeclaration(enumName, baseType, members, hasBody); | 1028 return new EnumDeclaration(enumName, baseType, members, hasBody); |
1021 } | 1029 } |
1022 | 1030 |
1023 /// Puts a declaration inside a template declaration. | 1031 /// Wraps a declaration inside a template declaration. |
1024 Declaration putInsideTemplateDeclaration(Token* begin, Identifier* name, | 1032 /// Params: |
1025 Declaration aggregateDecl, | 1033 /// begin = begin token of decl. |
1026 TemplateParameters tparams) | 1034 /// name = name of decl. |
1027 { | 1035 /// decl = the declaration to be wrapped. |
1028 set(aggregateDecl, begin); | 1036 /// tparams = the template parameters. |
1029 auto decls = new CompoundDeclaration; | 1037 TemplateDeclaration putInsideTemplateDeclaration(Token* begin, |
1030 decls ~= aggregateDecl; | 1038 Identifier* name, |
1031 set(decls, begin); | 1039 Declaration decl, |
1032 return new TemplateDeclaration(name, tparams, decls); | 1040 TemplateParameters tparams) |
1041 { | |
1042 set(decl, begin); | |
1043 auto cd = new CompoundDeclaration; | |
1044 cd ~= decl; | |
1045 set(cd, begin); | |
1046 return new TemplateDeclaration(name, tparams, cd); | |
1033 } | 1047 } |
1034 | 1048 |
1035 Declaration parseClassDeclaration() | 1049 Declaration parseClassDeclaration() |
1036 { | 1050 { |
1037 assert(token.kind == T.Class); | 1051 assert(token.kind == T.Class); |