comparison trunk/src/dil/Parser.d @ 409:38fccd2640eb

Added code for parsing C function pointer declarations.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Tue, 25 Sep 2007 12:15:49 +0200
parents e242f0ee2d27
children 9c69615a4876
comparison
equal deleted inserted replaced
408:3aa00474b381 409:38fccd2640eb
386 token.type == T.Identifier && 386 token.type == T.Identifier &&
387 peekNext() == T.Assign) 387 peekNext() == T.Assign)
388 { 388 {
389 ident = token; 389 ident = token;
390 nT(); 390 nT();
391 }
392 else if (token.type == T.LParen)
393 {
394 type = parseType();
395 parseCFunctionPointerType(type, ident);
391 } 396 }
392 else 397 else
393 { 398 {
394 type = parseType(); 399 type = parseType();
395 ident = requireId(); 400 ident = requireId();
3858 } 3863 }
3859 set(t, begin); 3864 set(t, begin);
3860 return t; 3865 return t;
3861 } 3866 }
3862 3867
3868 Type parseCFunctionPointerType(Type type, ref Token* ident)
3869 {
3870 assert(token.type == T.LParen);
3871 auto begin = token;
3872 nT(); // Skip (
3873 type = parseBasicType2(type);
3874 if (token.type == T.LParen)
3875 {
3876 // Can be nested.
3877 type = parseCFunctionPointerType(type, ident);
3878 }
3879 else if (token.type == T.Identifier)
3880 {
3881 // The identifier of the function pointer and the declaration.
3882 ident = token;
3883 nT();
3884 type = parseDeclaratorSuffix(type);
3885 }
3886 require(T.RParen);
3887 // Optional parameter list
3888 auto params = token.type == T.LParen ? parseParameterList() : null;
3889 type = set(new CFuncPointerType(type, params), begin);
3890 return type;
3891 }
3892
3863 Type parseDeclarator(ref Token* ident, bool identOptional = false) 3893 Type parseDeclarator(ref Token* ident, bool identOptional = false)
3864 { 3894 {
3865 auto t = parseType(); 3895 auto t = parseType();
3866 3896
3867 if (token.type == T.Identifier) 3897 if (token.type == T.LParen)
3898 {
3899 t = parseCFunctionPointerType(t, ident);
3900 }
3901 else if (token.type == T.Identifier)
3868 { 3902 {
3869 ident = token; 3903 ident = token;
3870 nT(); 3904 nT();
3871 t = parseDeclaratorSuffix(t); 3905 t = parseDeclaratorSuffix(t);
3872 } 3906 }
3873 else if (!identOptional) 3907
3908 if (ident is null && !identOptional)
3874 expected(T.Identifier); 3909 expected(T.Identifier);
3875 3910
3876 return t; 3911 return t;
3877 } 3912 }
3878 3913