]> code.delx.au - gnu-emacs/blobdiff - admin/grammars/c.by
Update copyright year to 2015
[gnu-emacs] / admin / grammars / c.by
index 1797827679b35293f72554da07eee3c26aa14af7..8a3a194b00eb002c4d6f302df79a006071e599c5 100644 (file)
@@ -1,6 +1,5 @@
 ;;; c.by -- LL grammar for C/C++ language specification
-
-;; Copyright (C) 1999-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
 ;;
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 ;;         David Ponce <david@dponce.com>
 ;; >  * Can't parse signature element: "RmcBucStatus* rftBucStatus"
 
 %package semantic-c-by
+%provide semantic/bovine/c-by
+
+%{
+(declare-function semantic-c-reconstitute-token "semantic/bovine/c"
+                 (tokenpart declmods typedecl))
+(declare-function semantic-c-reconstitute-template "semantic/bovine/c"
+                 (tag specifier))
+(declare-function semantic-expand-c-tag "semantic/bovine/c" (tag))
+(declare-function semantic-parse-region "semantic"
+                 (start end &optional nonterminal depth returnonerror))
+}
 
 %languagemode  c-mode c++-mode
 %start         declaration
@@ -54,6 +64,7 @@
 %token <punctuation>   PLUS       "\\`[+]\\'"
 %token <punctuation>   MINUS      "\\`[-]\\'"
 %token <punctuation>   BANG       "\\`[!]\\'"
+%token <punctuation>   QUESTION   "\\`[?]\\'"
 %token <punctuation>   EQUAL      "\\`[=]\\'"
 %token <punctuation>   LESS       "\\`[<]\\'"
 %token <punctuation>   GREATER    "\\`[>]\\'"
 %put VIRTUAL summary "Method Modifier: virtual <type> <name>(...) ..."
 %token MUTABLE "mutable"
 %put MUTABLE summary "Member Declaration Modifier: mutable <type> <name> ..."
+%token EXPLICIT "explicit"
+%put EXPLICIT summary "Forbids implicit type conversion: explicit <constructor>"
 
 %token STRUCT "struct"
 %put STRUCT summary "Structure Type Declaration: struct [name] { ... };"
 %put DELETE summary "delete <object>;"
 
 ;; Despite this, this parser can find templates by ignoring the TEMPLATE
-;; keyword, and finding the class/method being templateized.
+;; keyword, and finding the class/method being templatized.
 %token TEMPLATE "template"
 %put TEMPLATE summary "template <class TYPE ...> TYPE_OR_FUNCTION"
 
@@ -261,7 +274,7 @@ define
   ;
 
 ;; In C++, structures can have the same things as classes.
-;; So delete this somday in the figure.
+;; So delete this somday in the figure.
 ;;
 ;;structparts : semantic-list
 ;;            (EXPANDFULL $1 structsubparts)
@@ -370,6 +383,9 @@ namespacesubparts
  ;; PUBLIC or PRIVATE bits.  Ignore them for now.
   | template
   | using
+ ;; Includes inside namespaces
+  | spp-include
+    (TAG $1 'include :inside-ns t)
   | ;;EMPTY
   ;
 
@@ -566,7 +582,7 @@ template-type
     (TYPE-TAG $2 "class" nil nil )
   | STRUCT symbol
     (TYPE-TAG $2 "struct" nil nil )
- ;; TODO: Klaus Berndl: For the moment is is ok, that we parse the C++
+ ;; TODO: Klaus Berndl: For the moment it is ok, that we parse the C++
  ;; keyword typename as a class....
   | TYPENAME symbol
     (TYPE-TAG $2 "class" nil nil)
@@ -575,10 +591,12 @@ template-type
   | declmods typeformbase cv-declmods opt-stars
     opt-ref variablearg-opt-name
     (TYPE-TAG (car $2) nil nil nil
+             :template-specifier (plist-get (nth 2 $2) :template-specifier)
               :constant-flag (if (member "const" (append $1 $3)) t nil)
               :typemodifiers (delete "const" (append $1 $3))
               :reference (car ,$5)
               :pointer (car $4)
+             :typevar (car $6)
               )
   ;
 
@@ -734,7 +752,7 @@ builtintype
 
 ;; Klaus Berndl: This parses also nonsense like "const volatile int
 ;; const volatile const const volatile a ..." but IMHO nobody writes
-;; such code. Normaly we shoud define a rule like typeformbase-mode
+;; such code. Normally we should define a rule like typeformbase-mode
 ;; which exactly defines the different allowed cases and combinations
 ;; of declmods (minus the CVDECLMOD) typeformbase and cv-declmods so
 ;; we could recognize more invalid code but IMHO this is not worth the
@@ -817,7 +835,7 @@ opt-initializers
 
 opt-post-fcn-modifiers
   : post-fcn-modifiers opt-post-fcn-modifiers
-    ( ,(cons ,$1 $2) )
+    ( ,(cons ,(car $1) $2) )
   | ;;EMPTY
     ( nil )
   ;
@@ -886,8 +904,8 @@ varname
 ;; I should store more in this def, but leave it simple for now.
 ;; Klaus Berndl: const and volatile can be written after the type!
 variablearg
-  : declmods typeformbase cv-declmods opt-ref variablearg-opt-name
-    ( VARIABLE-TAG (list $5) $2 nil
+  : declmods typeformbase cv-declmods opt-ref variablearg-opt-name opt-assign
+    ( VARIABLE-TAG (list (append $5 ,$6)) $2 nil
                    :constant-flag (if (member "const" (append $1 $3)) t nil)
                    :typemodifiers (delete "const" (append $1 $3))
                    :reference (car ,$4)
@@ -897,6 +915,8 @@ variablearg
 variablearg-opt-name
   : varname
     ( ,$1 )
+  | semantic-list arg-list
+    ( (car ( EXPAND $1 function-pointer )) $2)
  ;; Klaus Berndl: This allows variableargs without a arg-name being
  ;; parsed correct even if there several pointers (*)
   | opt-stars
@@ -911,9 +931,9 @@ varname-opt-initializer
 
 varnamelist
   : opt-ref varname varname-opt-initializer COMA varnamelist
-    ( ,(cons $2 $5) )
+    ( ,(cons (append $2 $3) $5) )
   | opt-ref varname varname-opt-initializer
-    ( $2 )
+    ( (append $2 $3) )
   ;
 
 ;; Klaus Berndl: Is necessary to parse stuff like
@@ -1096,8 +1116,10 @@ functionname
   ;
 
 function-pointer
-  : LPAREN STAR symbol RPAREN
-    ( (concat "*" $3) )
+  : LPAREN STAR opt-symbol RPAREN
+    ( (concat "*" ,(car $3)) )
+  | LPAREN symbol RPAREN
+    ( $2 )
   ;
 
 fun-or-proto-end
@@ -1105,7 +1127,7 @@ fun-or-proto-end
     ( t )
   | semantic-list
     ( nil )
- ;; Here is an anoying feature of C++ pure virtual methods
+ ;; Here is an annoying feature of C++ pure virtual methods
   | EQUAL ZERO SEMICOLON
     ( :pure-virtual-flag )
   | fun-try-end
@@ -1135,16 +1157,26 @@ type-cast-list
   : open-paren typeformbase close-paren
   ;
 
-opt-stuff-after-symbol
+opt-brackets-after-symbol
+  : brackets-after-symbol
+  | ;; EMPTY
+  ;
+
+brackets-after-symbol
   : PAREN_BLCK
   | BRACK_BLCK
-  | ;; EMPTY
   ;
 
 multi-stage-dereference
-  : namespace-symbol opt-stuff-after-symbol PERIOD multi-stage-dereference ;; method call
-  | namespace-symbol opt-stuff-after-symbol MINUS GREATER multi-stage-dereference ;;method call
-  | namespace-symbol opt-stuff-after-symbol
+  : namespace-symbol opt-brackets-after-symbol
+    PERIOD multi-stage-dereference ;; method call
+  | namespace-symbol opt-brackets-after-symbol
+    MINUS GREATER multi-stage-dereference ;;method call
+  | namespace-symbol opt-brackets-after-symbol
+    PERIOD namespace-symbol opt-brackets-after-symbol
+  | namespace-symbol opt-brackets-after-symbol
+    MINUS GREATER namespace-symbol opt-brackets-after-symbol
+  | namespace-symbol brackets-after-symbol
   ;
 
 string-seq
@@ -1170,13 +1202,16 @@ expr-binop
   | AMPERSAND
   | OR OR
   | OR
+  | MOD
  ;; There are more.
   ;
 
 ;; Use expression for parsing only.  Don't actually return anything
 ;; for now.  Hopefully we can fix this later.
 expression
-  : unaryexpression expr-binop unaryexpression
+  : unaryexpression QUESTION unaryexpression COLON unaryexpression
+    ( (identity start) (identity end) )
+  | unaryexpression expr-binop unaryexpression
     ( (identity start) (identity end) )
   | unaryexpression
     ( (identity start) (identity end) )
@@ -1187,8 +1222,7 @@ unaryexpression
   | multi-stage-dereference
   | NEW multi-stage-dereference
   | NEW builtintype-types semantic-list
- ;; Klaus Berndl: symbol -> namespace-symbol!
-  | namespace-symbol
+  | symbol
  ;; Klaus Berndl: C/C++ allows sequences of strings which are
  ;; concatenated by the precompiler to one string
   | string-seq