diff 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
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;