help-global
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch: parsing initialization lists in C++ constructors (more correct)


From: vova gorsunov
Subject: patch: parsing initialization lists in C++ constructors (more correct)
Date: Fri, 12 Feb 2010 17:29:54 +0300

Oops, nevermind the last message :) I meant

Index: libparser/Cpp.c
===================================================================
RCS file: /sources/global/global/libparser/Cpp.c,v
retrieving revision 1.2
diff -u -r1.2 Cpp.c
--- libparser/Cpp.c     5 Feb 2010 00:50:09 -0000       1.2
+++ libparser/Cpp.c     12 Feb 2010 14:27:31 -0000
@@ -568,6 +568,39 @@
                        break;
        }
 }
+
+static void process_expressions(const struct parser_param *param,
+       const char ends_with) {
+       char meaningful_chars[] = " (";
+       int c;
+
+       meaningful_chars[0] = ends_with;
+       while((c = nexttoken(meaningful_chars, cpp_reserved_word)) != EOF) {
+               if(SYMBOL == c) {
+                       PUT(PARSER_REF_SYM, token, lineno, sp);
+               } else if('(' == c) {
+                       process_expressions(param, ')');
+               } else if(ends_with == c)
+                       return;
+       }
+}
+
+static void process_initialization_list(const struct parser_param *param) {
+       int c;
+       while ((c = nexttoken("({,", cpp_reserved_word)) != EOF) {
+               if('{' == c) {
+                       pushbacktoken();
+                       return;
+               } else if('(' == c) {
+                       /* can be pretty much anything */
+                       process_expressions(param, ')');
+               } else if(SYMBOL == c) {
+                       PUT(PARSER_REF_SYM, token, lineno, sp);
+               }
+       }
+}
+
+
 /*
  * function_definition: return if function definition or not.
  *
@@ -610,7 +643,7 @@
                return 0;
        }
        brace_level = 0;
-       while ((c = nexttoken(",;[](){}=", cpp_reserved_word)) != EOF) {
+       while ((c = nexttoken(",;[](){}=:", cpp_reserved_word)) != EOF) {
                switch (c) {
                case SHARP_IFDEF:
                case SHARP_IFNDEF:
@@ -639,6 +672,10 @@
                        break;
                else if (c == '=')
                        break;
+               else if(':' == c) {
+                       process_initialization_list(param);
+                       return 1;
+               }
                /* pick up symbol */
                if (c == SYMBOL)
                        PUT(PARSER_REF_SYM, token, lineno, sp);
@@ -646,6 +683,7 @@
        return 0;
 }

+
 /*
  * condition_macro:
  *
Index: libutil/token.c
===================================================================
RCS file: /sources/global/global/libutil/token.c,v
retrieving revision 1.24
diff -u -r1.24 token.c
--- libutil/token.c     25 Dec 2008 05:39:05 -0000      1.24
+++ libutil/token.c     12 Feb 2010 14:27:32 -0000
@@ -185,6 +185,9 @@
                                *p   = 0;
                                if (reserved && (c = (*reserved)(token, tlen)) 
== 0)
                                        break;
+                       } else {
+                               if (interested == NULL || strchr(interested, c))
+                                       break;
                        }
                } else if (c == '%' && ymode) {
                        /* recognize '%%' as a token if it is reserved word. */

-- 
/vg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]