# HG changeset patch # User Aziz K?ksal # Date 1190715349 -7200 # Node ID 38fccd2640eb8a52d2dcfcec199633e7642cbbca # Parent 3aa00474b381fb4c9f18a1f401bd8e403555779e Added code for parsing C function pointer declarations. diff -r 3aa00474b381 -r 38fccd2640eb trunk/src/dil/Parser.d --- 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; diff -r 3aa00474b381 -r 38fccd2640eb trunk/src/dil/SyntaxTree.d --- 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 diff -r 3aa00474b381 -r 38fccd2640eb trunk/src/dil/Types.d --- 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