Mercurial > projects > dil
changeset 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 | 3aa00474b381 |
children | 4d9ee8e60712 |
files | trunk/src/dil/Parser.d trunk/src/dil/SyntaxTree.d trunk/src/dil/Types.d |
diffstat | 3 files changed, 51 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/dil/Parser.d Mon Sep 24 17:22:59 2007 +0200 +++ b/trunk/src/dil/Parser.d Tue Sep 25 12:15:49 2007 +0200 @@ -389,6 +389,11 @@ ident = token; nT(); } + else if (token.type == T.LParen) + { + type = parseType(); + parseCFunctionPointerType(type, ident); + } else { type = parseType(); @@ -3860,17 +3865,47 @@ return t; } + Type parseCFunctionPointerType(Type type, ref Token* ident) + { + assert(token.type == T.LParen); + auto begin = token; + nT(); // Skip ( + type = parseBasicType2(type); + if (token.type == T.LParen) + { + // Can be nested. + type = parseCFunctionPointerType(type, ident); + } + else if (token.type == T.Identifier) + { + // The identifier of the function pointer and the declaration. + ident = token; + nT(); + type = parseDeclaratorSuffix(type); + } + require(T.RParen); + // Optional parameter list + auto params = token.type == T.LParen ? parseParameterList() : null; + type = set(new CFuncPointerType(type, params), begin); + return type; + } + Type parseDeclarator(ref Token* ident, bool identOptional = false) { auto t = parseType(); - if (token.type == T.Identifier) + if (token.type == T.LParen) + { + t = parseCFunctionPointerType(t, ident); + } + else if (token.type == T.Identifier) { ident = token; nT(); t = parseDeclaratorSuffix(t); } - else if (!identOptional) + + if (ident is null && !identOptional) expected(T.Identifier); return t;
--- a/trunk/src/dil/SyntaxTree.d Mon Sep 24 17:22:59 2007 +0200 +++ b/trunk/src/dil/SyntaxTree.d Tue Sep 25 12:15:49 2007 +0200 @@ -196,6 +196,7 @@ ArrayType, FunctionType, DelegateType, + CFuncPointerType, ConstType, // D2.0 InvariantType, // D2.0
--- a/trunk/src/dil/Types.d Mon Sep 24 17:22:59 2007 +0200 +++ b/trunk/src/dil/Types.d Tue Sep 25 12:15:49 2007 +0200 @@ -307,6 +307,7 @@ Function, Delegate, Pointer, + CFuncPointer, Array, DotList, Identifier, @@ -467,6 +468,18 @@ } } +class CFuncPointerType : Type +{ + Parameters params; + this(Type type, Parameters params) + { + super(TID.CFuncPointer, type); + mixin(set_kind); + if (params) + this.children ~= params; + } +} + version(D2) { class ConstType : Type